haive.agents.dynamic_supervisor.agent¶

Dynamic Supervisor Agent - routes tasks to sub-agents via tool calls.

The supervisor extends ReactAgent. Each sub-agent becomes a handoff tool. The LLM decides which agent to call by making tool calls. Adding or removing agents triggers graph recompilation so the LLM always sees current tools.

Example:

supervisor = DynamicSupervisor(name="boss", engine=AugLLMConfig())
supervisor.add_agent(math_agent, "Solves math problems")
supervisor.add_agent(writer_agent, "Writes creative content")
result = supervisor.run("What is 42 * 17?")  # routes to math_agent

Classes¶

DynamicSupervisor

Supervisor that routes tasks to sub-agents via tool calls.

Module Contents¶

class haive.agents.dynamic_supervisor.agent.DynamicSupervisor(/, **data)¶

Bases: haive.agents.react.agent.ReactAgent

Supervisor that routes tasks to sub-agents via tool calls.

Agents are added at runtime with add_agent(). Each becomes a handoff_to_{name} tool. The ReactAgent loop handles routing - the LLM makes tool calls to delegate work.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

add_agent(agent, description=None, name=None)¶

Add a sub-agent. Creates a handoff tool and recompiles the graph.

Parameters:
  • agent (Any) – The agent to add (must have .run() or .arun())

  • description (str | None) – What this agent does (shown to LLM)

  • name (str | None) – Override agent name (defaults to agent.name)

Return type:

None

compile(**kwargs)¶

Compile using the LangGraph path (not SimpleAgent’s create_runnable).

SimpleAgent.compile() uses create_runnable() which doesn’t rebuild properly after tool changes. We go through BaseGraph.to_langgraph() instead.

Return type:

Any

create_agent(name, system_message, description, tools=None, temperature=0.7)¶

Create a new agent on the fly and add it to the supervisor.

Parameters:
  • name (str) – Agent name

  • system_message (str) – System prompt for the new agent

  • description (str) – What this agent does

  • tools (list | None) – Optional tools for the new agent

  • temperature (float) – LLM temperature

Returns:

The created agent

Return type:

Any

model_post_init(__context)¶

Store base system message before super init.

Parameters:

__context (Any)

Return type:

None

remove_agent(name)¶

Remove a sub-agent and its handoff tool.

Parameters:

name (str)

Return type:

None

property agents: dict[str, Any]¶

Get the current agent registry.

Return type:

dict[str, Any]