agents.dynamic_supervisor.state¶
State schemas for dynamic supervisor agent.
from typing import Any This module defines the state management for the dynamic supervisor, including agent registry, routing control, and tool generation. Two versions are provided: - SupervisorState: Uses exclude=True for agent serialization (v1) - SupervisorStateV2: Attempts full agent serialization (experimental)
- Classes:
SupervisorState: Base supervisor state with agent registry SupervisorStateWithTools: Extends base with dynamic tool generation SupervisorStateV2: Experimental version with full serialization
Examples
Creating and managing supervisor state:
state = SupervisorState()
state.add_agent("search", search_agent, "Search specialist")
state.activate_agent("search")
# List active agents
active = state.list_active_agents()
Classes¶
Base state for dynamic supervisor with agent registry. |
|
Experimental supervisor state with full agent serialization. |
|
Supervisor state with dynamic tool generation. |
Module Contents¶
- class agents.dynamic_supervisor.state.SupervisorState(/, **data)¶
Bases:
haive.core.schema.prebuilt.messages.messages_with_token_usage.MessagesStateWithTokenUsage
Base state for dynamic supervisor with agent registry.
Inherits from MessagesState for message handling and adds agent management capabilities. Agents are stored in a registry with metadata for routing.
- Parameters:
data (Any)
- agents¶
Registry of available agents by name
- active_agents¶
List of currently active agent names (unique)
- next_agent¶
Name of agent to execute next (routing control)
- agent_task¶
Task to pass to the selected agent
- agent_response¶
Response from the last executed agent
Examples
Basic agent management:
state = SupervisorState() state.add_agent("math", math_agent, "Math specialist") state.set_routing("math", "Calculate 2+2")
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.
- activate_agent(name)¶
Activate an inactive agent.
- add_agent(name, agent, description, active=True)¶
Add an agent to the registry.
- Parameters:
- Return type:
None
Examples
state.add_agent(“search”, search_agent, “Web search expert”, active=True)
- clear_execution_state()¶
Clear execution state after completion.
- Return type:
None
- deactivate_agent(name)¶
Deactivate an active agent.
- classmethod ensure_unique_agents(v)¶
Ensure active agents list contains unique values.
- get_agent(name)¶
Get agent instance by name.
- Parameters:
name (str) – Agent name
- Returns:
Agent instance or None if not found
- Return type:
Any | None
- list_active_agents()¶
List all active agents with descriptions.
- list_all_agents()¶
List all agents (active and inactive) with descriptions.
- remove_agent(name)¶
Remove an agent from the registry completely.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agents.dynamic_supervisor.state.SupervisorStateV2(/, **data)¶
Bases:
haive.core.schema.prebuilt.messages.messages_with_token_usage.MessagesStateWithTokenUsage
Experimental supervisor state with full agent serialization.
This version attempts to serialize agents fully rather than excluding them. May require custom serialization logic or agent reconstruction.
Warning
This is experimental and may not work with all agent types or checkpointing systems. Use SupervisorState for production.
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)
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agents.dynamic_supervisor.state.SupervisorStateWithTools(/, **data)¶
Bases:
SupervisorState
Supervisor state with dynamic tool generation.
Extends SupervisorState with automatic tool generation from registered agents. Creates handoff tools for each agent and manages a dynamic choice model.
- Parameters:
data (Any)
- agent_choice_model¶
Dynamic model for validated agent selection
- generated_tools¶
List of tool names generated from agents
Examples
Using dynamic tools:
state = SupervisorStateWithTools() state.add_agent("search", agent, "Search expert") state.sync_agents() # Generates handoff_to_search tool tools = state.get_all_tools() # Get tool instances
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.
- activate_agent(name)¶
Override to trigger tool regeneration.
- add_agent(name, agent, description, active=True)¶
Override to trigger tool regeneration.
- deactivate_agent(name)¶
Override to trigger tool regeneration.
- get_all_tools()¶
Get all generated tools as callable instances.
- Returns:
List of tool instances ready for use
- Return type:
list[Any]
- sync_agents()¶
Public method to sync agents with tools and choice model.
Call this after adding/removing agents to regenerate tools.
- Return type:
None
- sync_on_init()¶
Sync tools and choice model after initialization.
- Return type: