AS AgentScopeAPI 手册 / API Reference

ChatCompletionsStreamingAdapter

public class ChatCompletionsStreamingAdapter
源码Source 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 Flux of ChatCompletionsChunk (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.

源码Source 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.

参数Parameters
名称Name类型Type说明Description
agentReActAgent智能体到流来自。The agent to stream from
messagesList<Msg>消息到发送到智能体。The messages to send to the agent
requestIdString请求标识(类型 `String`)。The request ID for tracking (used as chunk ID)
modelString模型实例(类型 `String`)。The model name to include in chunks
返回Returns Flux<ChatCompletionsChunk>
返回Flux。A `Flux` of `ChatCompletionsChunk` objects
源码Source io/agentscope/core/chat/completions/streaming/ChatCompletionsStreamingAdapter.java:92–125

convertEventToChunks

public Flux<ChatCompletionsChunk> convertEventToChunks(Event event, String requestId, String model)

转换 convertEventToChunks。

Convert an agent event to one or more streaming chunks.

参数Parameters
名称Name类型Type说明Description
eventEvent智能体事件。The agent event
requestIdString请求标识(类型 `String`)。The request ID for tracking
modelString模型名称。The model name
返回Returns Flux<ChatCompletionsChunk>
返回Flux。Flux of ChatCompletionsChunk objects
源码Source io/agentscope/core/chat/completions/streaming/ChatCompletionsStreamingAdapter.java:137–140

createErrorChunk

public ChatCompletionsChunk createErrorChunk(Throwable error, String requestId, String model)

创建错误分块。

Create an error chunk.

参数Parameters
名称Name类型Type说明Description
errorThrowable错误(类型 `Throwable`)。The error that occurred
requestIdString请求标识(类型 `String`)。The request ID for tracking
modelString模型名称。The model name
返回Returns ChatCompletionsChunk
返回ChatCompletionsChunk。A ChatCompletionsChunk representing the error
源码Source io/agentscope/core/chat/completions/streaming/ChatCompletionsStreamingAdapter.java:287–290
基于官方固定版本源码静态生成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.