AS AgentScopeAPI 手册 / API Reference
类class agentscope.tool

ToolResponse

class ToolResponse(BaseModel)
源码Source agentscope/tool/_response.py:51–178

ToolResponse 封装一次工具调用的内容块、状态与元数据,是 ToolChunk 流的最终结果。位于 agentscope.tool 包。核心成员包括 append_chunk。

The tool response from a tool execution, which contains the completed tool result (compared to ToolChunk). Declared in agentscope.tool.

属性摘要Attribute Summary

属性Attribute类型Type说明Description值Value
contentList[TextBlock | DataBlock]
工具返回的内容块列表。
Field(default_factory=list)
stateLiteral[ToolResultState.ERROR, ToolResultState.DENIED, ToolResultState.INTERRUPTED, ToolResultState.SUCCESS]
工具执行状态,例如成功、失败或中断。
ToolResultState.SUCCESS
metadatadict
工具附加的元数据。
Field(default_factory=dict)
idstr
标识字段。
Field(default_factory=_generate_id)

方法摘要Method Summary

方法Method说明Description
def append_chunk(chunk: ToolChunk) -> Self
追加分块。
Append a tool chunk to the current tool response, accumulate the data blocks and update the state and metadata.

属性详情Attribute Detail

content

List[TextBlock | DataBlock] = Field(default_factory=list)

内容字段。声明为 List[TextBlock | DataBlock]。

The content field.

源码Source agentscope/tool/_response.py:55

state

Literal[ToolResultState.ERROR, ToolResultState.DENIED, ToolResultState.INTERRUPTED, ToolResultState.SUCCESS] = ToolResultState.SUCCESS

状态字段。声明为 Literal[ToolResultState.ERROR, ToolResultState.DENIED, ToolResultState.INTERRUPTED, ToolResultState.SUCCESS]。

The state field.

源码Source agentscope/tool/_response.py:59

metadata

dict = Field(default_factory=dict)

元数据字段。声明为 dict。

The metadata field.

源码Source agentscope/tool/_response.py:67

id

str = Field(default_factory=_generate_id)

标识字段。声明为 str。

The id field.

源码Source agentscope/tool/_response.py:71

方法详情Method Detail

append_chunk

def append_chunk(chunk: ToolChunk) -> Self

追加分块。

Append a tool chunk to the current tool response, accumulate the data blocks and update the state and metadata.

参数Parameters
名称Name类型Type说明Description
chunkToolChunk分块(类型 `ToolChunk`)。The chunk.
返回Returns Self
返回自身。Returns self.
源码Source agentscope/tool/_response.py:74–178
基于官方固定版本源码静态生成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.