agents.dynamic_supervisor.toolsΒΆ
Dynamic tool generation for supervisor agent.
This module handles the creation of dynamic tools based on registered agents. It generates handoff tools for each agent and a choice validation tool.
- Functions:
create_agent_tools: Generate all tools from supervisor state create_handoff_tool: Create a handoff tool for a specific agent create_choice_tool: Create the agent choice validation tool
Example
Generating tools from state:
state = SupervisorStateWithTools()
state.add_agent("search", agent, "Search expert")
tools = create_agent_tools(state)
# Returns: [handoff_to_search, choose_agent]
FunctionsΒΆ
Create tool for requesting a new agent be added. |
|
|
Generate all tools from current agents in state. |
|
Create agent choice validation tool. |
|
Create a handoff tool for a specific agent. |
Module ContentsΒΆ
- agents.dynamic_supervisor.tools.create_add_agent_tool()ΒΆ
Create tool for requesting a new agent be added.
This tool allows the supervisor to formally request a new agent when it identifies a missing capability. In a full implementation, this would interface with an agent builder or registry service.
- Returns:
Add agent request tool
- Return type:
Any
Example
Requesting a new agent:
tool = create_add_agent_tool() tool.invoke({ "capability": "translation", "reason": "Need to translate results to French" })
- agents.dynamic_supervisor.tools.create_agent_tools(state)ΒΆ
Generate all tools from current agents in state.
Creates handoff tools for each registered agent and a choice validation tool. Tools are generated dynamically based on the current agent registry.
- Parameters:
state (haive.agents.dynamic_supervisor.state.SupervisorStateWithTools) β Supervisor state with agent registry
- Returns:
List of tool instances ready for use
- Return type:
list[Any]
Example
Getting tools for supervisor:
tools = create_agent_tools(state) # Use tools in an engine or pass to LLM
- agents.dynamic_supervisor.tools.create_choice_tool(state)ΒΆ
Create agent choice validation tool.
This tool provides validated agent selection with dynamic options based on the current agent registry. It includes βENDβ as an option for when no suitable agent exists.
- Parameters:
state (haive.agents.dynamic_supervisor.state.SupervisorStateWithTools) β Supervisor state instance
- Returns:
Choice validation tool
- Return type:
Any
Example
Using the choice tool:
tool = create_choice_tool(state) result = tool.invoke({"agent": "search_agent"})
- agents.dynamic_supervisor.tools.create_handoff_tool(state, agent_name)ΒΆ
Create a handoff tool for a specific agent.
The handoff tool executes the agent directly and returns results, following the pattern from our experimental implementation.
- Parameters:
state (haive.agents.dynamic_supervisor.state.SupervisorStateWithTools) β Supervisor state instance
agent_name (str) β Name of the agent to create tool for
- Returns:
Tool instance for handing off to the agent
- Return type:
Any
Example
Creating a handoff tool:
tool = create_handoff_tool(state, "search_agent") # Creates: handoff_to_search_agent tool