haive.agents.supervisor.state¶

State management for Dynamic Supervisor V2.

This module defines the state structures used by the dynamic supervisor to track agents, tasks, metrics, and workflow execution.

Classes¶

ActiveAgent

Represents an active agent instance in the supervisor.

DynamicSupervisorState

State structure for dynamic supervisor execution.

SupervisorMetrics

Metrics tracking for the supervisor's performance.

Functions¶

create_initial_state([available_specs, discovery_cache])

Create initial state for dynamic supervisor.

Module Contents¶

class haive.agents.supervisor.state.ActiveAgent(/, **data)¶

Bases: pydantic.BaseModel

Represents an active agent instance in the supervisor.

Parameters:

data (Any)

name¶

Unique identifier for the agent

instance¶

The actual agent instance (excluded from serialization)

capability¶

Full capability metadata for this agent

created_at¶

When this agent was instantiated

last_task¶

Description of the last task assigned

task_count¶

Number of tasks completed

total_execution_time¶

Cumulative execution time in seconds

error_count¶

Number of errors encountered

state¶

Current agent state (idle, busy, error)

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.

update_metrics(execution_time, success=True)¶

Update agent metrics after task execution.

Parameters:
  • execution_time (float) – Time taken for the task in seconds

  • success (bool) – Whether the task completed successfully

Return type:

None

property average_execution_time: float¶

Calculate average execution time per task.

Return type:

float

model_config¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property success_rate: float¶

Calculate task success rate.

Return type:

float

class haive.agents.supervisor.state.DynamicSupervisorState¶

Bases: TypedDict

State structure for dynamic supervisor execution.

This TypedDict defines the state that flows through the supervisor’s execution graph in LangGraph.

messages¶

Conversation history (LangGraph standard)

active_agents¶

Currently instantiated agents

agent_capabilities¶

All known agent capabilities

discovered_agents¶

Set of agent names that have been discovered

available_specs¶

Agent specifications that can be instantiated

current_agent¶

Name of agent handling current task

agent_task¶

Task assigned to current agent

agent_response¶

Response from current agent

next_agent¶

Next agent to route to

supervisor_metrics¶

Performance metrics

discovery_cache¶

Cache of discovery results

workflow_state¶

Current workflow state (routing, executing, etc.)

Initialize self. See help(type(self)) for accurate signature.

class haive.agents.supervisor.state.SupervisorMetrics(/, **data)¶

Bases: pydantic.BaseModel

Metrics tracking for the supervisor’s performance.

Parameters:

data (Any)

total_tasks¶

Total tasks processed

successful_tasks¶

Tasks completed successfully

failed_tasks¶

Tasks that failed

agent_creations¶

Number of agents created

discovery_attempts¶

Number of discovery attempts

successful_discoveries¶

Successful discoveries

total_execution_time¶

Total time spent on tasks

start_time¶

When supervisor was created

last_task_time¶

Timestamp of last task

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.

property discovery_success_rate: float¶

Calculate discovery success rate.

Return type:

float

property success_rate: float¶

Calculate overall success rate.

Return type:

float

property uptime_hours: float¶

Calculate supervisor uptime in hours.

Return type:

float

haive.agents.supervisor.state.create_initial_state(available_specs=None, discovery_cache=None)¶

Create initial state for dynamic supervisor.

Parameters:
Returns:

Initialized supervisor state

Return type:

DynamicSupervisorState