AS AgentScopeAPI 手册 / API Reference

ReasoningContext

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

参数Parameters
名称Name类型Type说明Description
agentNameString智能体名称(类型 `String`)。The agent name.
源码Source 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.

参数Parameters
名称Name类型Type说明Description
chunkChatResponse分块(类型 `ChatResponse`)。Response chunk from the model
返回Returns List<Msg>
返回列出。List of messages that can be sent immediately
源码Source io/agentscope/core/agent/accumulator/ReasoningContext.java:86–142

buildFinalMessage

public Msg buildFinalMessage()

构建最终消息。

Build the final reasoning message with all content blocks.

返回Returns Msg
返回消息。The complete reasoning message with all blocks, or null if no content
源码Source io/agentscope/core/agent/accumulator/ReasoningContext.java:162–208

getAccumulatedText

public String getAccumulatedText()

获取 getAccumulatedText。

Get the accumulated text content.

返回Returns String
返回字符串结果。accumulated text as string
源码Source io/agentscope/core/agent/accumulator/ReasoningContext.java:256–258

replaceAccumulatedText

public void replaceAccumulatedText(String text)

设置该参数。

Replace accumulated text after onModelCall middleware transforms text delta events.

参数Parameters
名称Name类型Type说明Description
textString文本(类型 `String`)。text reconstructed from the transformed event stream
源码Source io/agentscope/core/agent/accumulator/ReasoningContext.java:266–268

getAccumulatedThinking

public String getAccumulatedThinking()

获取 getAccumulatedThinking。

Get the accumulated thinking content.

返回Returns String
返回字符串结果。accumulated thinking as string
源码Source io/agentscope/core/agent/accumulator/ReasoningContext.java:276–278

getAccumulatedToolCall

public ToolUseBlock getAccumulatedToolCall(String id)

获取 getAccumulatedToolCall。

Get accumulated tool call by ID.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。The tool call ID to look up
返回Returns ToolUseBlock
返回ToolUseBlock。The accumulated ToolUseBlock, or null if not found
源码Source io/agentscope/core/agent/accumulator/ReasoningContext.java:289–291

getAllAccumulatedToolCalls

public List<ToolUseBlock> getAllAccumulatedToolCalls()

获取 getAllAccumulatedToolCalls。

Get all accumulated tool calls.

返回Returns List<ToolUseBlock>
返回列出。List of all accumulated ToolUseBlocks
源码Source io/agentscope/core/agent/accumulator/ReasoningContext.java:298–300

getChatUsage

public ChatUsage getChatUsage()

获取聊天用量。

Get the accumulated ChatUsage.

返回Returns ChatUsage
返回ChatUsage。ChatUsage with accumulated tokens, or null if no usage data
源码Source io/agentscope/core/agent/accumulator/ReasoningContext.java:307–320
基于官方固定版本源码静态生成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.