agents.dynamic_supervisor.modelsΒΆ

Data models for dynamic supervisor agent.

This module contains Pydantic models used by the dynamic supervisor for agent metadata, routing information, and configuration.

Classes:

AgentInfo: Metadata container for agents (v1 with exclusion) AgentInfoV2: Experimental version with full serialization AgentRequest: Model for agent addition requests RoutingDecision: Model for routing decisions

Example

Creating agent metadata:

info = AgentInfo(
    agent=search_agent,
    name="search",
    description="Web search specialist",
    active=True
)

ClassesΒΆ

AgentInfo

Information about an agent including instance and metadata.

AgentInfoV2

Experimental version with full agent serialization.

AgentRequest

Model for requesting a new agent be added.

RoutingDecision

Model for supervisor routing decisions.

Module ContentsΒΆ

class agents.dynamic_supervisor.models.AgentInfo(/, **data)ΒΆ

Bases: pydantic.BaseModel

Information about an agent including instance and metadata.

This model stores agent metadata and the agent instance itself. The agent field is excluded from serialization to avoid msgpack serialization issues with complex objects.

Parameters:

data (Any)

agentΒΆ

The actual agent instance (excluded from serialization)

nameΒΆ

Unique identifier for the agent

descriptionΒΆ

Human-readable description of capabilities

activeΒΆ

Whether the agent is currently active

capabilitiesΒΆ

List of capability keywords for discovery

metadataΒΆ

Additional metadata (versions, config, etc.)

Example

Creating agent info:

info = AgentInfo(
    agent=math_agent,
    name="math",
    description="Mathematics and calculation expert",
    capabilities=["math", "calculation", "statistics"]
)

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()ΒΆ

Activate the agent.

Return type:

None

deactivate()ΒΆ

Deactivate the agent.

Return type:

None

extract_agent_info()ΒΆ

Extract name and description from agent if not provided.

Returns:

Self with extracted information

Return type:

AgentInfo

get_agent()ΒΆ

Get the agent instance.

Returns:

The agent instance

Return type:

Any

is_active()ΒΆ

Check if agent is active.

Returns:

True if active, False otherwise

Return type:

bool

matches_capability(required)ΒΆ

Check if agent has a required capability.

Parameters:

required (str) – Capability keyword to check

Returns:

True if agent has the capability

Return type:

bool

model_configΒΆ

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

class agents.dynamic_supervisor.models.AgentInfoV2(/, **data)ΒΆ

Bases: pydantic.BaseModel

Experimental version with full agent serialization.

This version attempts to serialize the agent object. Requires custom serialization logic or agents that support model_dump().

Warning

Experimental - may not work with all agent types.

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)

serialize_agent(agent)ΒΆ

Attempt to serialize agent to dict.

Parameters:

agent (Any) – Agent instance

Returns:

Serialized representation

Return type:

dict[str, Any]

model_configΒΆ

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

class agents.dynamic_supervisor.models.AgentRequest(/, **data)ΒΆ

Bases: pydantic.BaseModel

Model for requesting a new agent be added.

Used when the supervisor identifies a missing capability and needs to request a new agent from an agent builder or registry.

Parameters:

data (Any)

capabilityΒΆ

The required capability (e.g., β€œtranslation”, β€œcode_analysis”)

task_contextΒΆ

Context about what task needs this capability

suggested_nameΒΆ

Suggested name for the new agent

requirementsΒΆ

Specific requirements or constraints

Example

Requesting a new agent:

request = AgentRequest(
    capability="translation",
    task_context="Need to translate search results to French",
    suggested_name="translator",
    requirements=["Support French", "Maintain formatting"]
)

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.

class agents.dynamic_supervisor.models.RoutingDecision(/, **data)ΒΆ

Bases: pydantic.BaseModel

Model for supervisor routing decisions.

Represents a decision made by the supervisor about which agent to route to or what action to take.

Parameters:

data (Any)

agent_nameΒΆ

Name of agent to route to (or β€œEND”)

taskΒΆ

Task to give to the agent

reasoningΒΆ

Explanation of the routing decision

confidenceΒΆ

Confidence level in the decision (0-1)

alternativesΒΆ

Other agents that could handle this

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.