ChatCompletionsStreamingAdapter
public class ChatCompletionsStreamingAdapter
io/agentscope/core/chat/completions/streaming/ChatCompletionsStreamingAdapter.java:68–333聊天补全流式适配器,为框架提供通用类型与基础能力。位于 io.agentscope.core.chat.completions.streaming 包。核心成员包括 stream、convertEventToChunks、createErrorChunk、ChatCompletionsStreamingAdapter。
Framework-agnostic adapter for handling streaming chat completion responses.
This adapter converts agent events to OpenAI-compatible ChatCompletionsChunk objects.
It is designed to be used by framework-specific adapters (e.g., Spring SSE, Quarkus Multi) that
handle the final serialization and transport.
Design Philosophy:
-
Core streaming logic is framework-agnostic
-
Returns
FluxofChatCompletionsChunk(not framework-specific types) -
Framework adapters (in starter modules) handle SSE/transport specifics
Supported Event Types:
-
EventType#REASONING- Text content and tool call decisions -
EventType#TOOL_RESULT- Tool execution results
Output Chunk Types:
-
Text chunks - Incremental text content
-
Tool call chunks - When agent decides to call tools
-
Finish chunks - Stream completion with finish_reason
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ChatCompletionsStreamingAdapter() | 初始化 `ChatCompletionsStreamingAdapter` 实例。 Constructs a new `ChatCompletionsStreamingAdapter`. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Flux<ChatCompletionsChunk> stream(ReActAgent agent, List<Msg> messages, String requestId, String model) | 执行流相关操作。 Stream agent events as OpenAI-compatible chunks. |
public Flux<ChatCompletionsChunk> convertEventToChunks(Event event, String requestId, String model) | 转换 `convertEventToChunks`。 Convert an agent event to one or more streaming chunks. |
public ChatCompletionsChunk createErrorChunk(Throwable error, String requestId, String model) | 创建错误分块。 Create an error chunk. |
构造器详情Constructor Detail
ChatCompletionsStreamingAdapter
public ChatCompletionsStreamingAdapter()
初始化 ChatCompletionsStreamingAdapter 实例。
Constructs a new ChatCompletionsStreamingAdapter.
io/agentscope/core/chat/completions/streaming/ChatCompletionsStreamingAdapter.java:73方法详情Method Detail
stream
public Flux<ChatCompletionsChunk> stream(ReActAgent agent, List<Msg> messages, String requestId, String model)
执行流相关操作。
Stream agent events as OpenAI-compatible chunks.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agent | ReActAgent | 智能体到流来自。The agent to stream from |
messages | List<Msg> | 消息到发送到智能体。The messages to send to the agent |
requestId | String | 请求标识(类型 `String`)。The request ID for tracking (used as chunk ID) |
model | String | 模型实例(类型 `String`)。The model name to include in chunks |
Flux<ChatCompletionsChunk>io/agentscope/core/chat/completions/streaming/ChatCompletionsStreamingAdapter.java:92–125convertEventToChunks
public Flux<ChatCompletionsChunk> convertEventToChunks(Event event, String requestId, String model)
转换 convertEventToChunks。
Convert an agent event to one or more streaming chunks.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
event | Event | 智能体事件。The agent event |
requestId | String | 请求标识(类型 `String`)。The request ID for tracking |
model | String | 模型名称。The model name |
Flux<ChatCompletionsChunk>io/agentscope/core/chat/completions/streaming/ChatCompletionsStreamingAdapter.java:137–140createErrorChunk
public ChatCompletionsChunk createErrorChunk(Throwable error, String requestId, String model)
创建错误分块。
Create an error chunk.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
error | Throwable | 错误(类型 `Throwable`)。The error that occurred |
requestId | String | 请求标识(类型 `String`)。The request ID for tracking |
model | String | 模型名称。The model name |
ChatCompletionsChunkio/agentscope/core/chat/completions/streaming/ChatCompletionsStreamingAdapter.java:287–290