AS AgentScopeAPI 手册 / API Reference

ToolUseBlock

public final class ToolUseBlock extends ContentBlock
源码Source 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_SIGNATURE
staticfinal
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
staticfinal

元数据 THOUGHT SIGNATURE字段。声明为 public static final String METADATA_THOUGHT_SIGNATURE。

Metadata key for Gemini thought signature (byte[] value).

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

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。Unique identifier for this tool call
nameString工具到执行的名称。Name of the tool to execute
inputMap<String, Object>输入消息(类型 `Map`)。Input parameters for the tool (will be defensively copied)
metadataMap<String, Object>元数据(类型 `Map`)。Provider-specific metadata (will be defensively copied)
源码Source io/agentscope/core/message/ToolUseBlock.java:54–57

ToolUseBlock

public ToolUseBlock(String id, String name, Map<String, Object> input)

初始化 ToolUseBlock 实例。

Creates a new tool use block without metadata (convenience constructor).

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。Unique identifier for this tool call
nameString工具到执行的名称。Name of the tool to execute
inputMap<String, Object>输入消息(类型 `Map`)。Input parameters for the tool (will be defensively copied)
源码Source io/agentscope/core/message/ToolUseBlock.java:66–68

ToolUseBlock

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.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。Unique identifier for this tool call
nameString工具到执行的名称。Name of the tool to execute
inputMap<String, Object>输入消息(类型 `Map`)。Input parameters for the tool (will be defensively copied)
contentString用于流式工具调用的原始内容。Raw content for streaming tool calls
metadataMap<String, Object>元数据(类型 `Map`)。Provider-specific metadata (will be defensively copied)
源码Source io/agentscope/core/message/ToolUseBlock.java:79–86

ToolUseBlock

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.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。Unique identifier for this tool call
nameString工具到执行的名称。Name of the tool to execute
inputMap<String, Object>输入消息(类型 `Map`)。Input parameters for the tool (will be defensively copied)
contentString用于流式工具调用的原始内容。Raw content for streaming tool calls
metadataMap<String, Object>元数据(类型 `Map`)。Provider-specific metadata (will be defensively copied)
stateToolCallState状态对象(类型 `ToolCallState`)。The tool call state, defaults to PENDING if null
源码Source io/agentscope/core/message/ToolUseBlock.java:98–119

方法详情Method Detail

getId

public String getId()

获取标识。

Gets the unique identifier of this tool call.

返回Returns String
工具调用标识。The tool call ID
源码Source io/agentscope/core/message/ToolUseBlock.java:126–128

getName

public String getName()

获取名称的工具到执行。

Gets the name of the tool to execute.

返回Returns String
工具名称。The tool name
源码Source io/agentscope/core/message/ToolUseBlock.java:135–137

getInput

public Map<String, Object> getInput()

获取输入参数用于工具。

Gets the input parameters for the tool.

返回Returns Map<String, Object>
工具输入参数映射。The tool input parameters map
源码Source io/agentscope/core/message/ToolUseBlock.java:144–146

getContent

public String getContent()

获取原始内容用于流式工具调用。

Gets the raw content for streaming tool calls.

返回Returns String
返回字符串结果。The raw content, or null if not set
源码Source io/agentscope/core/message/ToolUseBlock.java:153–155

getMetadata

public Map<String, Object> getMetadata()

获取元数据。

Gets the provider-specific metadata.

返回Returns Map<String, Object>
返回映射。The metadata map, or an empty map if not set
源码Source io/agentscope/core/message/ToolUseBlock.java:165–167

getState

public ToolCallState getState()

获取工具调用状态。

Gets the tool call state.

返回Returns ToolCallState
工具调用状态。The tool call state
源码Source io/agentscope/core/message/ToolUseBlock.java:174–176

withState

public ToolUseBlock withState(ToolCallState state)

执行使用状态相关操作。

Returns a copy of this block with the given state.

参数Parameters
名称Name类型Type说明Description
stateToolCallState新的状态。The new state
返回Returns ToolUseBlock
一种新的ToolUseBlock 使用已更新状态。A new ToolUseBlock with the updated state
源码Source io/agentscope/core/message/ToolUseBlock.java:184–186

builder

public static Builder builder()
static

返回构建器实例。

Creates a new builder for constructing a ToolUseBlock.

返回Returns Builder
一种新的构建器实例。A new builder instance
源码Source io/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.

基于官方固定版本源码静态生成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.