ToolResultBlock
public final class ToolResultBlock extends ContentBlock
io/agentscope/core/message/ToolResultBlock.java:35–433表示结果的工具执行。位于 io.agentscope.core.message 包,继承自 ContentBlock。核心成员包括 getId、getName、getOutput、getMetadata、getState、withState。
Represents the result of a tool execution.
This class serves two purposes: 1. As a return value from tool methods (id and name are null) 2. As a ContentBlock in messages (id and name are required)
Supports metadata for passing additional execution information.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | 构建器,用于构建并配置目标实例。 Builder for constructing ToolResultBlock instances. |
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
METADATA_SUSPENDEDstaticfinal | String | 元数据 SUSPENDED字段。 Metadata key indicating this result is suspended for external execution. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ToolResultBlock(String id, String name, List<ContentBlock> output, Map<String, Object> metadata, ToolResultState state) | 初始化 `ToolResultBlock` 实例。 Creates a new instance. |
public ToolResultBlock(String id, String name, List<ContentBlock> output, Map<String, Object> metadata) | 初始化 `ToolResultBlock` 实例。 Creates a new instance. |
public ToolResultBlock(String id, String name, ContentBlock output) | 初始化 `ToolResultBlock` 实例。 Creates a tool result block with a single content block output. |
public ToolResultBlock(String id, String name, List<ContentBlock> output) | 初始化 `ToolResultBlock` 实例。 Creates a tool result block with a list of content blocks as output. |
方法摘要Method Summary
字段详情Field Detail
METADATA_SUSPENDED
public static final String METADATA_SUSPENDED
元数据 SUSPENDED字段。声明为 public static final String METADATA_SUSPENDED。
Metadata key indicating this result is suspended for external execution.
io/agentscope/core/message/ToolResultBlock.java:38构造器详情Constructor Detail
ToolResultBlock
public ToolResultBlock(String id, String name, List<ContentBlock> output, Map<String, Object> metadata, ToolResultState state)
初始化 ToolResultBlock 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。The id. |
name | String | 名称(类型 `String`)。The name. |
output | List<ContentBlock> | 输出(类型 `List`)。The output. |
metadata | Map<String, Object> | 元数据(类型 `Map`)。The metadata. |
state | ToolResultState | 状态对象(类型 `ToolResultState`)。The state. |
io/agentscope/core/message/ToolResultBlock.java:46–58ToolResultBlock
public ToolResultBlock(String id, String name, List<ContentBlock> output, Map<String, Object> metadata)
初始化 ToolResultBlock 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。The id. |
name | String | 名称(类型 `String`)。The name. |
output | List<ContentBlock> | 输出(类型 `List`)。The output. |
metadata | Map<String, Object> | 元数据(类型 `Map`)。The metadata. |
io/agentscope/core/message/ToolResultBlock.java:60–63ToolResultBlock
public ToolResultBlock(String id, String name, ContentBlock output)
初始化 ToolResultBlock 实例。
Creates a tool result block with a single content block output.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Tool call ID |
name | String | 名称(类型 `String`)。Tool name |
output | ContentBlock | 输出(类型 `ContentBlock`)。Single content block as output |
io/agentscope/core/message/ToolResultBlock.java:72–74ToolResultBlock
public ToolResultBlock(String id, String name, List<ContentBlock> output)
初始化 ToolResultBlock 实例。
Creates a tool result block with a list of content blocks as output.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Tool call ID |
name | String | 名称(类型 `String`)。Tool name |
output | List<ContentBlock> | 输出(类型 `List`)。List of content blocks as output |
io/agentscope/core/message/ToolResultBlock.java:83–85方法详情Method Detail
getId
public String getId()
获取工具调用标识。
Gets the tool call ID.
Stringio/agentscope/core/message/ToolResultBlock.java:92–94getName
public String getName()
获取工具名称。
Gets the tool name.
Stringio/agentscope/core/message/ToolResultBlock.java:101–103getOutput
public List<ContentBlock> getOutput()
获取输出。
Gets the output content blocks.
List<ContentBlock>io/agentscope/core/message/ToolResultBlock.java:110–112getMetadata
public Map<String, Object> getMetadata()
获取元数据。
Gets the metadata associated with the tool result.
Map<String, Object>io/agentscope/core/message/ToolResultBlock.java:119–121getState
public ToolResultState getState()
获取工具结果状态。
Gets the tool result state.
ToolResultStateio/agentscope/core/message/ToolResultBlock.java:128–130withState
public ToolResultBlock withState(ToolResultState state)
执行使用状态相关操作。
Returns a copy of this block with the given state.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
state | ToolResultState | 新的状态。The new state |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:138–140isSuspended
public boolean isSuspended()
判断是否 isSuspended。
Checks if this result is suspended for external execution.
booleanio/agentscope/core/message/ToolResultBlock.java:150–154suspended
public static ToolResultBlock suspended(ToolUseBlock toolUse, ToolSuspendException exception)
执行 suspended 方法。
Creates a suspended tool result from a ToolSuspendException.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolUse | ToolUseBlock | 工具使用(类型 `ToolUseBlock`)。The tool use block that triggered the exception |
exception | ToolSuspendException | 异常(类型 `ToolSuspendException`)。The exception thrown by the tool |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:166–176suspended
public static ToolResultBlock suspended(ToolUseBlock toolUse)
设置该参数。
Creates a suspended tool result with default message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolUse | ToolUseBlock | 工具使用(类型 `ToolUseBlock`)。The tool use block that requires external execution |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:184–186text
public static ToolResultBlock text(String text)
设置文本。
Create a simple text result (for tool method return values).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
text | String | 文本(类型 `String`)。Text content |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:194–197error
public static ToolResultBlock error(String errorMessage)
设置错误。
Create an error result (for tool method return values).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
errorMessage | String | 错误消息(类型 `String`)。Error message |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:205–212error
public static ToolResultBlock error(String toolId, String errorMessage)
创建错误结果用于工具调用。
Create an error result for a tool call.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
toolId | String | 工具标识(类型 `String`)。Tool call ID |
errorMessage | String | 错误消息(类型 `String`)。Error message |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:224–231of
public static ToolResultBlock of(ContentBlock output)
创建并返回实例。
Create a result with output only (for tool method return values).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
output | ContentBlock | 输出(类型 `ContentBlock`)。Content block output |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:239–241of
public static ToolResultBlock of(List<ContentBlock> output)
创建并返回实例。
Create a result with output list only (for tool method return values).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
output | List<ContentBlock> | 输出(类型 `List`)。List of content blocks |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:249–251of
public static ToolResultBlock of(ContentBlock output, Map<String, Object> metadata)
创建并返回实例。
Create a result with output and metadata (for tool method return values).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
output | ContentBlock | 输出(类型 `ContentBlock`)。Content block output |
metadata | Map<String, Object> | 元数据(类型 `Map`)。Metadata map |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:260–262of
public static ToolResultBlock of(List<ContentBlock> output, Map<String, Object> metadata)
创建并返回实例。
Create a result with output list and metadata (for tool method return values).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
output | List<ContentBlock> | 输出(类型 `List`)。List of content blocks |
metadata | Map<String, Object> | 元数据(类型 `Map`)。Metadata map |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:271–273of
public static ToolResultBlock of(String id, String name, ContentBlock output)
创建结果使用标识,名称,和输出(用于消息 ContentBlock)。
Create a result with id, name, and output (for message ContentBlock).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Tool call ID |
name | String | 名称(类型 `String`)。Tool name |
output | ContentBlock | 输出(类型 `ContentBlock`)。Content block output |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:283–285of
public static ToolResultBlock of(String id, String name, List<ContentBlock> output)
创建结果使用标识,名称,和输出列出(用于消息 ContentBlock)。
Create a result with id, name, and output list (for message ContentBlock).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Tool call ID |
name | String | 名称(类型 `String`)。Tool name |
output | List<ContentBlock> | 输出(类型 `List`)。List of content blocks |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:295–297of
public static ToolResultBlock of(String id, String name, ContentBlock output, Map<String, Object> metadata)
创建并返回实例。
Create a result with all fields (for message ContentBlock with metadata).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Tool call ID |
name | String | 名称(类型 `String`)。Tool name |
output | ContentBlock | 输出(类型 `ContentBlock`)。Content block output |
metadata | Map<String, Object> | 元数据(类型 `Map`)。Metadata map |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:308–311of
public static ToolResultBlock of(String id, String name, List<ContentBlock> output, Map<String, Object> metadata)
创建并返回实例。
Create a result with all fields including output list (for message ContentBlock with metadata).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Tool call ID |
name | String | 名称(类型 `String`)。Tool name |
output | List<ContentBlock> | 输出(类型 `List`)。List of content blocks |
metadata | Map<String, Object> | 元数据(类型 `Map`)。Metadata map |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:323–326withIdAndName
public ToolResultBlock withIdAndName(String id, String name)
创建ToolResultBlock 用于使用 in 消息通过设置标识和名称。
Create a ToolResultBlock for use in messages by setting id and name.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Tool call ID |
name | String | 名称(类型 `String`)。Tool name |
ToolResultBlockio/agentscope/core/message/ToolResultBlock.java:335–337builder
public static Builder builder()
返回构建器实例。
Creates a new builder for constructing ToolResultBlock instances.
Builderio/agentscope/core/message/ToolResultBlock.java:344–346嵌套类详情Nested Class Detail
Builder
public static class Builder构建器,用于构建并配置目标实例。位于 io.agentscope.core.message 包。核心成员包括 id、name、output、metadata、state、build。
Builder for constructing ToolResultBlock instances.