ToolUseBlock
public final class ToolUseBlock extends ContentBlock
io/agentscope/core/message/ToolUseBlock.java:34–286工具使用块,在智能体、模型与前端之间传递结构化消息和事件。位于 io.agentscope.core.message 包,继承自 ContentBlock。核心成员包括 getId、getName、getInput、getContent、getMetadata、getState。
Represents a tool use request within a message.
This content block is used when an agent requests to execute a tool. It contains the tool's unique identifier, name, input parameters, and optionally the raw content for streaming tool calls.
The tool input is stored as a generic map of string keys to object values, allowing for flexible parameter passing to different tool implementations.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | 构建器,用于构建并配置目标实例。 Builder for constructing ToolUseBlock instances. |
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
METADATA_THOUGHT_SIGNATUREstaticfinal | String | 元数据 THOUGHT SIGNATURE字段。 Metadata key for Gemini thought signature (byte[] value). |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ToolUseBlock(String id, String name, Map<String, Object> input, Map<String, Object> metadata) | 初始化 `ToolUseBlock` 实例。 Creates a new tool use block for JSON deserialization. |
public ToolUseBlock(String id, String name, Map<String, Object> input) | 初始化 `ToolUseBlock` 实例。 Creates a new tool use block without metadata (convenience constructor). |
public ToolUseBlock(String id, String name, Map<String, Object> input, String content, Map<String, Object> metadata) | 创建新的工具使用块使用原始内容用于流式。 Creates a new tool use block with raw content for streaming. |
public ToolUseBlock(String id, String name, Map<String, Object> input, String content, Map<String, Object> metadata, ToolCallState state) | 初始化 `ToolUseBlock` 实例。 Creates a new tool use block with all fields. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public String getId() | 获取标识。 Gets the unique identifier of this tool call. |
public String getName() | 获取名称的工具到执行。 Gets the name of the tool to execute. |
public Map<String, Object> getInput() | 获取输入参数用于工具。 Gets the input parameters for the tool. |
public String getContent() | 获取原始内容用于流式工具调用。 Gets the raw content for streaming tool calls. |
public Map<String, Object> getMetadata() | 获取元数据。 Gets the provider-specific metadata. |
public ToolCallState getState() | 获取工具调用状态。 Gets the tool call state. |
public ToolUseBlock withState(ToolCallState state) | 执行使用状态相关操作。 Returns a copy of this block with the given state. |
public static Builder builder()static | 返回构建器实例。 Creates a new builder for constructing a ToolUseBlock. |
字段详情Field Detail
METADATA_THOUGHT_SIGNATURE
public static final String METADATA_THOUGHT_SIGNATURE
元数据 THOUGHT SIGNATURE字段。声明为 public static final String METADATA_THOUGHT_SIGNATURE。
Metadata key for Gemini thought signature (byte[] value).
io/agentscope/core/message/ToolUseBlock.java:37构造器详情Constructor Detail
ToolUseBlock
public ToolUseBlock(String id, String name, Map<String, Object> input, Map<String, Object> metadata)
初始化 ToolUseBlock 实例。
Creates a new tool use block for JSON deserialization.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Unique identifier for this tool call |
name | String | 工具到执行的名称。Name of the tool to execute |
input | Map<String, Object> | 输入消息(类型 `Map`)。Input parameters for the tool (will be defensively copied) |
metadata | Map<String, Object> | 元数据(类型 `Map`)。Provider-specific metadata (will be defensively copied) |
io/agentscope/core/message/ToolUseBlock.java:54–57ToolUseBlock
public ToolUseBlock(String id, String name, Map<String, Object> input)
初始化 ToolUseBlock 实例。
Creates a new tool use block without metadata (convenience constructor).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Unique identifier for this tool call |
name | String | 工具到执行的名称。Name of the tool to execute |
input | Map<String, Object> | 输入消息(类型 `Map`)。Input parameters for the tool (will be defensively copied) |
io/agentscope/core/message/ToolUseBlock.java:66–68ToolUseBlock
public ToolUseBlock(String id, String name, Map<String, Object> input, String content, Map<String, Object> metadata)
创建新的工具使用块使用原始内容用于流式。
Creates a new tool use block with raw content for streaming.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Unique identifier for this tool call |
name | String | 工具到执行的名称。Name of the tool to execute |
input | Map<String, Object> | 输入消息(类型 `Map`)。Input parameters for the tool (will be defensively copied) |
content | String | 用于流式工具调用的原始内容。Raw content for streaming tool calls |
metadata | Map<String, Object> | 元数据(类型 `Map`)。Provider-specific metadata (will be defensively copied) |
io/agentscope/core/message/ToolUseBlock.java:79–86ToolUseBlock
public ToolUseBlock(String id, String name, Map<String, Object> input, String content, Map<String, Object> metadata, ToolCallState state)
初始化 ToolUseBlock 实例。
Creates a new tool use block with all fields.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Unique identifier for this tool call |
name | String | 工具到执行的名称。Name of the tool to execute |
input | Map<String, Object> | 输入消息(类型 `Map`)。Input parameters for the tool (will be defensively copied) |
content | String | 用于流式工具调用的原始内容。Raw content for streaming tool calls |
metadata | Map<String, Object> | 元数据(类型 `Map`)。Provider-specific metadata (will be defensively copied) |
state | ToolCallState | 状态对象(类型 `ToolCallState`)。The tool call state, defaults to PENDING if null |
io/agentscope/core/message/ToolUseBlock.java:98–119方法详情Method Detail
getId
public String getId()
获取标识。
Gets the unique identifier of this tool call.
Stringio/agentscope/core/message/ToolUseBlock.java:126–128getName
public String getName()
获取名称的工具到执行。
Gets the name of the tool to execute.
Stringio/agentscope/core/message/ToolUseBlock.java:135–137getInput
public Map<String, Object> getInput()
获取输入参数用于工具。
Gets the input parameters for the tool.
Map<String, Object>io/agentscope/core/message/ToolUseBlock.java:144–146getContent
public String getContent()
获取原始内容用于流式工具调用。
Gets the raw content for streaming tool calls.
Stringio/agentscope/core/message/ToolUseBlock.java:153–155getMetadata
public Map<String, Object> getMetadata()
获取元数据。
Gets the provider-specific metadata.
Map<String, Object>io/agentscope/core/message/ToolUseBlock.java:165–167getState
public ToolCallState getState()
获取工具调用状态。
Gets the tool call state.
ToolCallStateio/agentscope/core/message/ToolUseBlock.java:174–176withState
public ToolUseBlock withState(ToolCallState state)
执行使用状态相关操作。
Returns a copy of this block with the given state.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
state | ToolCallState | 新的状态。The new state |
ToolUseBlockio/agentscope/core/message/ToolUseBlock.java:184–186builder
public static Builder builder()
返回构建器实例。
Creates a new builder for constructing a ToolUseBlock.
Builderio/agentscope/core/message/ToolUseBlock.java:193–195嵌套类详情Nested Class Detail
Builder
public static class Builder构建器,用于构建并配置目标实例。位于 io.agentscope.core.message 包。核心成员包括 id、name、input、content、metadata、state。
Builder for constructing ToolUseBlock instances.