AS AgentScopeAPI 手册 / API Reference

ChatCompletionsController

@RestController @RequestMapping public class ChatCompletionsController
源码Source io/agentscope/spring/boot/chat/web/ChatCompletionsController.java:77–293

聊天补全控制器,承载智能体的部署、调度与服务化运行。位于 io.agentscope.spring.boot.chat.web 包。核心成员包括 createCompletion、createCompletionStream、ChatCompletionsController。

HTTP controller exposing a Chat Completions API compatible with OpenAI's standard.

This controller implements a 100% stateless API, fully compatible with OpenAI's Chat Completions API. Each request is independent, and the client is responsible for managing conversation history.

How It Works:

  • Client sends complete conversation history in messages

  • Server creates a fresh agent instance, loads the messages

  • Agent processes and returns a response

  • Client appends the assistant message to their history for next request

Tool Calls:

When the assistant uses tools, the response includes tool_calls in the assistant message. The client should:

  • Append the assistant message (with tool_calls) to history

  • Execute the tools and create tool result messages

  • Send the updated history in the next request

Features:

  • Non-streaming JSON response (default)

  • SSE streaming when Accept: text/event-stream

  • Full OpenAI compatibility

构造器摘要Constructor Summary

构造器Constructor说明Description
public ChatCompletionsController(ObjectProvider<ReActAgent> agentProvider, ChatMessageConverter messageConverter, ChatCompletionsResponseBuilder responseBuilder, ChatCompletionsStreamingService streamingService, OpenAIToolConverter toolConverter)
初始化 `ChatCompletionsController` 实例。
Constructs a new ChatCompletionsController.

方法摘要Method Summary

方法Method说明Description
public Object createCompletion(ChatCompletionsRequest request)
创建补全。
Non-streaming chat completion endpoint.
public Flux<ServerSentEvent<String>> createCompletionStream(ChatCompletionsRequest request)
创建补全流。
Streaming chat completion endpoint.

构造器详情Constructor Detail

ChatCompletionsController

public ChatCompletionsController(ObjectProvider<ReActAgent> agentProvider, ChatMessageConverter messageConverter, ChatCompletionsResponseBuilder responseBuilder, ChatCompletionsStreamingService streamingService, OpenAIToolConverter toolConverter)

初始化 ChatCompletionsController 实例。

Constructs a new ChatCompletionsController.

参数Parameters
名称Name类型Type说明Description
agentProviderObjectProvider<ReActAgent>智能体提供者(类型 `ObjectProvider`)。Provider for creating prototype-scoped agent instances
messageConverterChatMessageConverter消息转换器(类型 `ChatMessageConverter`)。Converter for HTTP DTOs to framework messages
responseBuilderChatCompletionsResponseBuilder响应构建器(类型 `ChatCompletionsResponseBuilder`)。Builder for response objects
streamingServiceChatCompletionsStreamingService流式服务(类型 `ChatCompletionsStreamingService`)。Service for streaming responses
toolConverterOpenAIToolConverter用于OpenAI 工具到 ToolSchema的转换器。Converter for OpenAI tools to ToolSchema
源码Source io/agentscope/spring/boot/chat/web/ChatCompletionsController.java:98–109

方法详情Method Detail

createCompletion

public Object createCompletion(ChatCompletionsRequest request)

创建补全。

Non-streaming chat completion endpoint.

参数Parameters
名称Name类型Type说明Description
requestChatCompletionsRequest请求(类型 `ChatCompletionsRequest`)。The chat completion request containing the full message history
返回Returns Object
返回对象。A `Mono` containing the `ChatCompletionsResponse` with the agent's reply, or a `Flux` of `ServerSentEvent` if streaming is requested
源码Source io/agentscope/spring/boot/chat/web/ChatCompletionsController.java:123–202

createCompletionStream

public Flux<ServerSentEvent<String>> createCompletionStream(ChatCompletionsRequest request)

创建补全流。

Streaming chat completion endpoint.

参数Parameters
名称Name类型Type说明Description
requestChatCompletionsRequest请求(类型 `ChatCompletionsRequest`)。The chat completion request containing the full message history
返回Returns Flux<ServerSentEvent<String>>
返回Flux>。A `Flux` of `ServerSentEvent` containing text deltas and completion events
源码Source io/agentscope/spring/boot/chat/web/ChatCompletionsController.java:213–292
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.