类 ToolResultBlock

java.lang.Object
io.agentscope.core.message.ContentBlock
io.agentscope.core.message.ToolResultBlock
所有已实现的接口:
State

public final class ToolResultBlock extends ContentBlock
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.
  • 字段详细资料

    • METADATA_SUSPENDED

      public static final String METADATA_SUSPENDED
      Metadata key indicating this result is suspended for external execution.
      另请参阅:
  • 构造器详细资料

    • ToolResultBlock

      public ToolResultBlock(String id, String name, List<ContentBlock> output, Map<String,Object> metadata)
    • ToolResultBlock

      public ToolResultBlock(String id, String name, ContentBlock output)
      Creates a tool result block with a single content block output.
      参数:
      id - Tool call ID
      name - Tool name
      output - Single content block as output
    • ToolResultBlock

      public ToolResultBlock(String id, String name, List<ContentBlock> output)
      Creates a tool result block with a list of content blocks as output.
      参数:
      id - Tool call ID
      name - Tool name
      output - List of content blocks as output
  • 方法详细资料

    • getId

      public String getId()
      Gets the tool call ID.
      返回:
      The tool call ID, or null if not set
    • getName

      public String getName()
      Gets the tool name.
      返回:
      The tool name, or null if not set
    • getOutput

      public List<ContentBlock> getOutput()
      Gets the output content blocks.
      返回:
      Immutable list of content blocks representing the tool output
    • getMetadata

      public Map<String,Object> 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

      public static ToolResultBlock suspended(ToolUseBlock toolUse, ToolSuspendException exception)
      Creates a suspended tool result from a ToolSuspendException.

      This method is used by the framework to convert a ToolSuspendException into a suspended result that will be returned to the user for external execution.

      参数:
      toolUse - The tool use block that triggered the exception
      exception - The exception thrown by the tool
      返回:
      A suspended ToolResultBlock
    • suspended

      public static ToolResultBlock suspended(ToolUseBlock toolUse)
      Creates a suspended tool result with default message.
      参数:
      toolUse - The tool use block that requires external execution
      返回:
      A suspended ToolResultBlock
    • text

      public static ToolResultBlock text(String text)
      Create a simple text result (for tool method return values).
      参数:
      text - Text content
      返回:
      ToolResultBlock with text output
    • error

      public static ToolResultBlock error(String errorMessage)
      Create an error result (for tool method return values).
      参数:
      errorMessage - Error message
      返回:
      ToolResultBlock with error output
    • of

      public static ToolResultBlock of(ContentBlock output)
      Create a result with output only (for tool method return values).
      参数:
      output - Content block output
      返回:
      ToolResultBlock with the given output
    • of

      public static ToolResultBlock of(List<ContentBlock> output)
      Create a result with output list only (for tool method return values).
      参数:
      output - List of content blocks
      返回:
      ToolResultBlock with the given output
    • of

      public static ToolResultBlock of(ContentBlock output, Map<String,Object> metadata)
      Create a result with output and metadata (for tool method return values).
      参数:
      output - Content block output
      metadata - Metadata map
      返回:
      ToolResultBlock with output and metadata
    • of

      public static ToolResultBlock of(List<ContentBlock> output, Map<String,Object> metadata)
      Create a result with output list and metadata (for tool method return values).
      参数:
      output - List of content blocks
      metadata - Metadata map
      返回:
      ToolResultBlock with output and metadata
    • of

      public static ToolResultBlock of(String id, String name, ContentBlock output)
      Create a result with id, name, and output (for message ContentBlock).
      参数:
      id - Tool call ID
      name - Tool name
      output - Content block output
      返回:
      ToolResultBlock for use in messages
    • of

      public static ToolResultBlock of(String id, String name, List<ContentBlock> output)
      Create a result with id, name, and output list (for message ContentBlock).
      参数:
      id - Tool call ID
      name - Tool name
      output - 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 ID
      name - Tool name
      output - Content block output
      metadata - 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 ID
      name - Tool name
      output - List of content blocks
      metadata - Metadata map
      返回:
      ToolResultBlock with all fields
    • withIdAndName

      public ToolResultBlock withIdAndName(String id, String name)
      Create a ToolResultBlock for use in messages by setting id and name.
      参数:
      id - Tool call ID
      name - Tool name
      返回:
      New ToolResultBlock with id and name set
    • builder

      public static ToolResultBlock.Builder builder()
      Creates a new builder for constructing ToolResultBlock instances.
      返回:
      A new builder instance