类 Toolkit.ToolRegistration
- 封闭类:
Toolkit
This builder provides a clear, type-safe way to register tools with various options without method proliferation.
-
方法概要
修饰符和类型方法说明Set the AgentTool instance to register.voidapply()Apply the registration with all configured options.disableTools(List<String> disableTools) Set the list of tools to disable from the MCP client.enableTools(List<String> enableTools) Set the list of tools to enable from the MCP client.extendedModel(ExtendedModel extendedModel) Set the extended model for dynamic schema extension.Set the tool group name.mcpClient(McpClientWrapper mcpClientWrapper) Set the MCP client to register.Set preset parameters that will be automatically injected during tool execution.subAgent(SubAgentProvider<?> provider) Register a sub-agent as a tool with default configuration.subAgent(SubAgentProvider<?> provider, SubAgentConfig config) Register a sub-agent as a tool with custom configuration.Set the tool object to register (scans for @Tool methods).
-
方法详细资料
-
tool
Set the tool object to register (scans for @Tool methods).- 参数:
toolObject- Object containing @Tool annotated methods- 返回:
- This builder for chaining
-
agentTool
Set the AgentTool instance to register.- 参数:
agentTool- The AgentTool instance- 返回:
- This builder for chaining
-
mcpClient
Set the MCP client to register.- 参数:
mcpClientWrapper- The MCP client wrapper- 返回:
- This builder for chaining
-
subAgent
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
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) andsession_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
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
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
Set the tool group name.- 参数:
groupName- The group name (null for ungrouped)- 返回:
- This builder for chaining
-
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
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 setIllegalStateException- if set multiple of: tool(), agentTool(), mcpClient(), or subAgent().
-