agents.supervisor.agent

Dynamic Supervisor V2 - Main agent implementation.

This module contains the core DynamicSupervisor class that orchestrates runtime agent discovery, creation, and task routing.

Classes

DynamicSupervisor

Advanced supervisor that discovers and creates agents at runtime.

Functions

create_dynamic_supervisor([name, agent_specs, ...])

Factory function to create a configured dynamic supervisor.

Module Contents

class agents.supervisor.agent.DynamicSupervisor(**data)

Bases: haive.agents.react.agent.ReactAgent

Advanced supervisor that discovers and creates agents at runtime.

The DynamicSupervisor extends ReactAgent to provide intelligent task routing with the ability to discover, create, and manage specialized agents dynamically based on task requirements.

Key capabilities:
  • Dynamic agent discovery from specifications

  • Runtime agent creation and lifecycle management

  • Intelligent task-to-agent matching

  • Performance tracking and optimization

  • Extensible discovery mechanisms

name

Supervisor identifier

engine

LLM configuration for supervisor reasoning

agent_specs

Initial specifications for creatable agents

discovery_config

Configuration for agent discovery

max_agents

Maximum number of active agents to maintain

auto_discover

Whether to automatically discover new agents

include_management_tools

Whether to include agent management tools

Examples

Basic usage with predefined agent specs:

supervisor = DynamicSupervisor(
    name="task_router",
    agent_specs=[
        AgentSpec(
            name="researcher",
            agent_type="ReactAgent",
            description="Research and analysis expert",
            specialties=["research", "analysis"],
            tools=[web_search_tool]
        ),
        AgentSpec(
            name="writer",
            agent_type="SimpleAgentV3",
            description="Content creation expert",
            specialties=["writing", "editing"]
        )
    ]
)

result = await supervisor.arun(
    "Research quantum computing and write a summary"
)

Initialize the dynamic supervisor.

Parameters:

**data – Configuration parameters

async arun(input_data)

Run the supervisor asynchronously.

Parameters:

input_data (str | dict[str, Any] | list[langchain_core.messages.BaseMessage]) – Task input (string, dict, or messages)

Returns:

Agent execution result

Return type:

Any

get_metrics()

Get supervisor performance metrics.

Returns:

Dictionary of metrics including agent stats

Return type:

dict[str, Any]

run(input_data)

Run the supervisor synchronously.

Parameters:

input_data (str | dict[str, Any] | list[langchain_core.messages.BaseMessage]) – Task input

Returns:

Agent execution result

Return type:

Any

classmethod validate_agent_specs(v)

Validate agent specifications have unique names.

Parameters:

v (list[haive.agents.supervisor.models.AgentSpec])

Return type:

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

agents.supervisor.agent.create_dynamic_supervisor(name='dynamic_supervisor', agent_specs=None, discovery_mode=AgentDiscoveryMode.MANUAL, **kwargs)

Factory function to create a configured dynamic supervisor.

Parameters:
  • name (str) – Supervisor name

  • agent_specs (list[haive.agents.supervisor.models.AgentSpec] | None) – Initial agent specifications

  • discovery_mode (haive.agents.supervisor.models.AgentDiscoveryMode) – How to discover new agents

  • **kwargs – Additional configuration

Returns:

Configured DynamicSupervisor instance

Return type:

DynamicSupervisor

Examples

>>> supervisor = create_dynamic_supervisor(
...     name="task_router",
...     agent_specs=[math_spec, research_spec],
...     discovery_mode="manual",
...     max_agents=20
... )