agents.supervisor.toolsΒΆ

Tools and utilities for Dynamic Supervisor V2.

This module provides tools for agent creation, discovery, matching, and workflow coordination.

ClassesΒΆ

AgentManagementTools

Collection of tools for managing agents in the supervisor.

FunctionsΒΆ

create_agent_from_spec(spec)

Create an agent instance from a specification.

create_handoff_tool(agent_name, description)

Create a tool for handing off tasks to a specific agent.

discover_agents(task, discovery_config[, existing_agents])

Discover new agents based on task requirements.

find_matching_agent_specs(task, available_specs[, ...])

Find agent specifications that match a given task.

Module ContentsΒΆ

class 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

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)
agents.supervisor.tools.create_handoff_tool(agent_name, description)ΒΆ

Create a tool for handing off tasks to a specific agent.

Parameters:
  • agent_name (str) – Name of the agent to hand off to

  • description (str) – Description of what the agent does

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"})
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:

list[haive.agents.supervisor.models.AgentSpec]

Note

Currently implements MANUAL mode. Other modes (COMPONENT_DISCOVERY, RAG_DISCOVERY, MCP_DISCOVERY) are planned for future releases.

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:

list[haive.agents.supervisor.models.AgentSpec]

Examples

>>> specs = [math_spec, research_spec, writing_spec]
>>> matches = find_matching_agent_specs(
...     "Calculate the compound interest",
...     specs
... )
>>> assert matches[0].name == "math_expert"