ReasoningContext
public class ReasoningContext
io/agentscope/core/agent/accumulator/ReasoningContext.java:44–321推理上下文,驱动智能体的推理、工具调用与会话执行。位于 io.agentscope.core.agent.accumulator 包。核心成员包括 processChunk、buildFinalMessage、getAccumulatedText、replaceAccumulatedText、getAccumulatedThinking、getAccumulatedToolCall。
Reasoning context that manages all state and content accumulation for a single reasoning round.
Responsibilities:
-
Accumulate various content types (text, thinking, tool calls) from streaming responses
-
Generate real-time streaming messages (for Hook notifications)
-
Build final aggregated message (for saving to memory)
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ReasoningContext(String agentName) | 初始化 `ReasoningContext` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public List<Msg> processChunk(ChatResponse chunk) | 处理分块。 Process a response chunk and return messages that can be sent immediately. |
public Msg buildFinalMessage() | 构建最终消息。 Build the final reasoning message with all content blocks. |
public String getAccumulatedText() | 获取 `getAccumulatedText`。 Get the accumulated text content. |
public void replaceAccumulatedText(String text) | 设置该参数。 Replace accumulated text after `onModelCall` middleware transforms text delta events. |
public String getAccumulatedThinking() | 获取 `getAccumulatedThinking`。 Get the accumulated thinking content. |
public ToolUseBlock getAccumulatedToolCall(String id) | 获取 `getAccumulatedToolCall`。 Get accumulated tool call by ID. |
public List<ToolUseBlock> getAllAccumulatedToolCalls() | 获取 `getAllAccumulatedToolCalls`。 Get all accumulated tool calls. |
public ChatUsage getChatUsage() | 获取聊天用量。 Get the accumulated ChatUsage. |
构造器详情Constructor Detail
ReasoningContext
public ReasoningContext(String agentName)
初始化 ReasoningContext 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentName | String | 智能体名称(类型 `String`)。The agent name. |
io/agentscope/core/agent/accumulator/ReasoningContext.java:68–70方法详情Method Detail
processChunk
public List<Msg> processChunk(ChatResponse chunk)
处理分块。
Process a response chunk and return messages that can be sent immediately.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
chunk | ChatResponse | 分块(类型 `ChatResponse`)。Response chunk from the model |
List<Msg>io/agentscope/core/agent/accumulator/ReasoningContext.java:86–142buildFinalMessage
public Msg buildFinalMessage()
构建最终消息。
Build the final reasoning message with all content blocks.
Msgio/agentscope/core/agent/accumulator/ReasoningContext.java:162–208getAccumulatedText
public String getAccumulatedText()
获取 getAccumulatedText。
Get the accumulated text content.
Stringio/agentscope/core/agent/accumulator/ReasoningContext.java:256–258replaceAccumulatedText
public void replaceAccumulatedText(String text)
设置该参数。
Replace accumulated text after onModelCall middleware transforms text delta events.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
text | String | 文本(类型 `String`)。text reconstructed from the transformed event stream |
io/agentscope/core/agent/accumulator/ReasoningContext.java:266–268getAccumulatedThinking
public String getAccumulatedThinking()
获取 getAccumulatedThinking。
Get the accumulated thinking content.
Stringio/agentscope/core/agent/accumulator/ReasoningContext.java:276–278getAccumulatedToolCall
public ToolUseBlock getAccumulatedToolCall(String id)
获取 getAccumulatedToolCall。
Get accumulated tool call by ID.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。The tool call ID to look up |
ToolUseBlockio/agentscope/core/agent/accumulator/ReasoningContext.java:289–291getAllAccumulatedToolCalls
public List<ToolUseBlock> getAllAccumulatedToolCalls()
获取 getAllAccumulatedToolCalls。
Get all accumulated tool calls.
List<ToolUseBlock>io/agentscope/core/agent/accumulator/ReasoningContext.java:298–300getChatUsage
public ChatUsage getChatUsage()
获取聊天用量。
Get the accumulated ChatUsage.
ChatUsageio/agentscope/core/agent/accumulator/ReasoningContext.java:307–320