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¶
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.ReactAgentSupervisor 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.
- 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.
- model_post_init(__context)¶
Store base system message before super init.
- Parameters:
__context (Any)
- Return type:
None