haive.agents.supervisor.tools¶
Tools and utilities for Dynamic Supervisor V2.
This module provides tools for agent creation, discovery, matching, and workflow coordination.
Classes¶
Collection of tools for managing agents in the supervisor. |
Functions¶
|
Create an agent instance from a specification. |
|
Create a tool for handing off tasks to a specific agent. |
|
Discover new agents based on task requirements. |
|
Find agent specifications that match a given task. |
Module Contents¶
- class haive.agents.supervisor.tools.AgentManagementTools¶
Collection of tools for managing agents in the supervisor.
These tools can be provided to the supervisor to enable dynamic agent management capabilities.
- static create_agent_stats_tool(state_accessor)¶
Create a tool for viewing agent statistics.
- Parameters:
state_accessor – Function to access current state
- Returns:
Tool for viewing agent stats
- Return type:
langchain_core.tools.BaseTool
- static create_list_agents_tool(state_accessor)¶
Create a tool for listing available agents.
- Parameters:
state_accessor – Function to access current state
- Returns:
Tool for listing agents
- Return type:
langchain_core.tools.BaseTool
- haive.agents.supervisor.tools.create_agent_from_spec(spec)¶
Create an agent instance from a specification.
This function instantiates the appropriate agent type based on the spec, configuring it with the provided settings and tools.
- Parameters:
spec (haive.agents.supervisor.models.AgentSpec) – Agent specification containing type, config, and tools
- Returns:
Instantiated agent instance
- Raises:
ValueError – If agent_type is not supported
- Return type:
Any
Examples
>>> spec = AgentSpec( ... name="calculator", ... agent_type="ReactAgent", ... config={"temperature": 0.1} ... ) >>> agent = create_agent_from_spec(spec)
- haive.agents.supervisor.tools.create_handoff_tool(agent_name, description)¶
Create a tool for handing off tasks to a specific agent.
- Parameters:
- Returns:
Tool that can be used to route tasks to the agent
- Return type:
langchain_core.tools.BaseTool
Examples
>>> tool = create_handoff_tool("math_expert", "Handles math problems") >>> result = tool.invoke({"task": "Calculate 2+2"})
- haive.agents.supervisor.tools.discover_agents(task, discovery_config, existing_agents=None)¶
Discover new agents based on task requirements.
This function implements various discovery strategies to find or create agent specifications that can handle the given task.
- Parameters:
task (str) – Task description requiring agents
discovery_config (haive.agents.supervisor.models.DiscoveryConfig) – Configuration for discovery process
existing_agents (set[str] | None) – Set of already discovered agent names to avoid duplicates
- Returns:
List of discovered agent specifications
- Return type:
Note
Currently implements MANUAL mode. Other modes (COMPONENT_DISCOVERY, RAG_DISCOVERY, MCP_DISCOVERY) are planned for future releases.
- haive.agents.supervisor.tools.find_matching_agent_specs(task, available_specs, threshold=0.3, max_results=5)¶
Find agent specifications that match a given task.
Uses specialty matching and keyword analysis to find the most suitable agent specifications for a task.
- Parameters:
task (str) – Task description to match against
available_specs (list[haive.agents.supervisor.models.AgentSpec]) – List of available agent specifications
threshold (float) – Minimum match score (0-1) to include a spec
max_results (int) – Maximum number of results to return
- Returns:
List of matching specs, sorted by relevance
- Return type:
Examples
>>> specs = [math_spec, research_spec, writing_spec] >>> matches = find_matching_agent_specs( ... "Calculate the compound interest", ... specs ... ) >>> assert matches[0].name == "math_expert"