类 ToolResultBlock
java.lang.Object
io.agentscope.core.message.ContentBlock
io.agentscope.core.message.ToolResultBlock
- 所有已实现的接口:
State
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.
-
嵌套类概要
嵌套类修饰符和类型类说明static classBuilder for constructing ToolResultBlock instances. -
字段概要
字段修饰符和类型字段说明static final StringMetadata key indicating this result is suspended for external execution. -
构造器概要
构造器构造器说明ToolResultBlock(String id, String name, ContentBlock output) Creates a tool result block with a single content block output.ToolResultBlock(String id, String name, List<ContentBlock> output) Creates a tool result block with a list of content blocks as output.ToolResultBlock(String id, String name, List<ContentBlock> output, Map<String, Object> metadata) -
方法概要
修饰符和类型方法说明static ToolResultBlock.Builderbuilder()Creates a new builder for constructing ToolResultBlock instances.static ToolResultBlockCreate an error result (for tool method return values).getId()Gets the tool call ID.Gets the metadata associated with the tool result.getName()Gets the tool name.Gets the output content blocks.booleanChecks if this result is suspended for external execution.static ToolResultBlockof(ContentBlock output) Create a result with output only (for tool method return values).static ToolResultBlockof(ContentBlock output, Map<String, Object> metadata) Create a result with output and metadata (for tool method return values).static ToolResultBlockof(String id, String name, ContentBlock output) Create a result with id, name, and output (for message ContentBlock).static ToolResultBlockCreate a result with all fields (for message ContentBlock with metadata).static ToolResultBlockof(String id, String name, List<ContentBlock> output) Create a result with id, name, and output list (for message ContentBlock).static ToolResultBlockCreate a result with all fields including output list (for message ContentBlock with metadata).static ToolResultBlockof(List<ContentBlock> output) Create a result with output list only (for tool method return values).static ToolResultBlockCreate a result with output list and metadata (for tool method return values).static ToolResultBlocksuspended(ToolUseBlock toolUse) Creates a suspended tool result with default message.static ToolResultBlocksuspended(ToolUseBlock toolUse, ToolSuspendException exception) Creates a suspended tool result from a ToolSuspendException.static ToolResultBlockCreate a simple text result (for tool method return values).withIdAndName(String id, String name) Create a ToolResultBlock for use in messages by setting id and name.
-
字段详细资料
-
METADATA_SUSPENDED
Metadata key indicating this result is suspended for external execution.- 另请参阅:
-
-
构造器详细资料
-
ToolResultBlock
-
ToolResultBlock
Creates a tool result block with a single content block output.- 参数:
id- Tool call IDname- Tool nameoutput- Single content block as output
-
ToolResultBlock
Creates a tool result block with a list of content blocks as output.- 参数:
id- Tool call IDname- Tool nameoutput- List of content blocks as output
-
-
方法详细资料
-
getId
Gets the tool call ID.- 返回:
- The tool call ID, or null if not set
-
getName
Gets the tool name.- 返回:
- The tool name, or null if not set
-
getOutput
Gets the output content blocks.- 返回:
- Immutable list of content blocks representing the tool output
-
getMetadata
Gets the metadata associated with the tool result.- 返回:
- Immutable metadata map, or empty map if not set
-
isSuspended
public boolean isSuspended()Checks if this result is suspended for external execution.A suspended result is created when a tool throws
ToolSuspendException, indicating that the tool execution needs to be handled externally by the user.- 返回:
- true if this result is suspended, false otherwise
-
suspended
Creates a suspended tool result from a ToolSuspendException.This method is used by the framework to convert a
ToolSuspendExceptioninto a suspended result that will be returned to the user for external execution.- 参数:
toolUse- The tool use block that triggered the exceptionexception- The exception thrown by the tool- 返回:
- A suspended ToolResultBlock
-
suspended
Creates a suspended tool result with default message.- 参数:
toolUse- The tool use block that requires external execution- 返回:
- A suspended ToolResultBlock
-
text
Create a simple text result (for tool method return values).- 参数:
text- Text content- 返回:
- ToolResultBlock with text output
-
error
Create an error result (for tool method return values).- 参数:
errorMessage- Error message- 返回:
- ToolResultBlock with error output
-
of
Create a result with output only (for tool method return values).- 参数:
output- Content block output- 返回:
- ToolResultBlock with the given output
-
of
Create a result with output list only (for tool method return values).- 参数:
output- List of content blocks- 返回:
- ToolResultBlock with the given output
-
of
Create a result with output and metadata (for tool method return values).- 参数:
output- Content block outputmetadata- Metadata map- 返回:
- ToolResultBlock with output and metadata
-
of
Create a result with output list and metadata (for tool method return values).- 参数:
output- List of content blocksmetadata- Metadata map- 返回:
- ToolResultBlock with output and metadata
-
of
Create a result with id, name, and output (for message ContentBlock).- 参数:
id- Tool call IDname- Tool nameoutput- Content block output- 返回:
- ToolResultBlock for use in messages
-
of
Create a result with id, name, and output list (for message ContentBlock).- 参数:
id- Tool call IDname- Tool nameoutput- List of content blocks- 返回:
- ToolResultBlock for use in messages
-
of
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).- 参数:
id- Tool call IDname- Tool nameoutput- Content block outputmetadata- Metadata map- 返回:
- ToolResultBlock with all fields
-
of
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).- 参数:
id- Tool call IDname- Tool nameoutput- List of content blocksmetadata- Metadata map- 返回:
- ToolResultBlock with all fields
-
withIdAndName
Create a ToolResultBlock for use in messages by setting id and name.- 参数:
id- Tool call IDname- Tool name- 返回:
- New ToolResultBlock with id and name set
-
builder
Creates a new builder for constructing ToolResultBlock instances.- 返回:
- A new builder instance
-