类 Toolkit.ToolRegistration

java.lang.Object
io.agentscope.core.tool.Toolkit.ToolRegistration
封闭类:
Toolkit

public static class Toolkit.ToolRegistration extends Object
Fluent builder for registering tools with optional configuration.

This builder provides a clear, type-safe way to register tools with various options without method proliferation.

  • 方法详细资料

    • tool

      public Toolkit.ToolRegistration tool(Object toolObject)
      Set the tool object to register (scans for @Tool methods).
      参数:
      toolObject - Object containing @Tool annotated methods
      返回:
      This builder for chaining
    • agentTool

      public Toolkit.ToolRegistration agentTool(AgentTool agentTool)
      Set the AgentTool instance to register.
      参数:
      agentTool - The AgentTool instance
      返回:
      This builder for chaining
    • mcpClient

      public Toolkit.ToolRegistration mcpClient(McpClientWrapper mcpClientWrapper)
      Set the MCP client to register.
      参数:
      mcpClientWrapper - The MCP client wrapper
      返回:
      This builder for chaining
    • subAgent

      public Toolkit.ToolRegistration subAgent(SubAgentProvider<?> provider)
      Register a sub-agent as a tool with default configuration.

      The tool name and description are derived from the agent's properties. Uses a single "task" string parameter by default.

      Example:

      
       toolkit.registration()
           .subAgent(() -> ReActAgent.builder()
               .name("ResearchAgent")
               .model(model)
               .build())
           .apply();
       
      参数:
      provider - Factory for creating agent instances (called for each invocation)
      返回:
      This builder for chaining
    • subAgent

      public Toolkit.ToolRegistration subAgent(SubAgentProvider<?> provider, SubAgentConfig config)
      Register a sub-agent as a tool with custom configuration.

      Sub-agents support multi-turn conversation with session-based state management. The tool exposes two parameters: message (required) and session_id (optional, for continuing existing conversations).

      Example with custom tool name and description:

      
       toolkit.registration()
           .subAgent(
               () -> ReActAgent.builder().name("Expert").model(model).build(),
               SubAgentConfig.builder()
                   .toolName("ask_expert")
                   .description("Ask the domain expert a question")
                   .build())
           .apply();
       

      Example with persistent session for cross-process conversations:

      
       toolkit.registration()
           .subAgent(
               () -> ReActAgent.builder().name("Assistant").model(model).build(),
               SubAgentConfig.builder()
                   .session(new JsonSession(Path.of("sessions")))
                   .forwardEvents(true)
                   .build())
           .apply();
       
      参数:
      provider - Factory for creating agent instances (called for each session)
      config - Configuration for the sub-agent tool, or null to use defaults (tool name derived from agent name, InMemorySession for state, events forwarded)
      返回:
      This builder for chaining
      另请参阅:
    • enableTools

      public Toolkit.ToolRegistration enableTools(List<String> enableTools)
      Set the list of tools to enable from the MCP client.

      Only applicable when using mcpClient(). If not specified, all tools are enabled.

      参数:
      enableTools - List of tool names to enable
      返回:
      This builder for chaining
    • disableTools

      public Toolkit.ToolRegistration disableTools(List<String> disableTools)
      Set the list of tools to disable from the MCP client.

      Only applicable when using mcpClient().

      参数:
      disableTools - List of tool names to disable
      返回:
      This builder for chaining
    • group

      public Toolkit.ToolRegistration group(String groupName)
      Set the tool group name.
      参数:
      groupName - The group name (null for ungrouped)
      返回:
      This builder for chaining
    • presetParameters

      public Toolkit.ToolRegistration presetParameters(Map<String,Map<String,Object>> presetParameters)
      Set preset parameters that will be automatically injected during tool execution.

      These parameters are not exposed in the JSON schema.

      The map should have tool names as keys and parameter maps as values:

      
       Map.of(
           "toolName1", Map.of("param1", "value1", "param2", "value2"),
           "toolName2", Map.of("param1", "value3")
       )
       
      参数:
      presetParameters - Map from tool name to its preset parameters
      返回:
      This builder for chaining
    • extendedModel

      public Toolkit.ToolRegistration extendedModel(ExtendedModel extendedModel)
      Set the extended model for dynamic schema extension.
      参数:
      extendedModel - The extended model
      返回:
      This builder for chaining
    • apply

      public void apply()
      Apply the registration with all configured options.
      抛出:
      IllegalStateException - if none of tool(), agentTool(), mcpClient() or subAgent() was set
      IllegalStateException - if set multiple of: tool(), agentTool(), mcpClient(), or subAgent().