Skip to content

OSSS.ai.dependencies.dynamic_composition

OSSS.ai.dependencies.dynamic_composition

Dynamic agent composition with runtime discovery and hot-swapping.

This module provides capabilities for discovering, loading, and dynamically composing agents at runtime, including hot-swapping of failed agents and dynamic graph reconfiguration.

DiscoveryStrategy

Bases: Enum

Strategies for discovering agents.

CompositionEvent

Bases: Enum

Events in the dynamic composition lifecycle.

DiscoveredAgentInfo

Bases: BaseModel

Metadata about a discovered agent.

can_replace(other)

Check if this agent can replace another agent.

to_dict()

Convert to dictionary representation.

Note: This method is kept for backward compatibility. For new code, use model_dump() instead.

CompositionRule

Bases: BaseModel

Rule for dynamic composition decisions.

Migrated from dataclass to Pydantic BaseModel for enhanced validation, serialization, and integration with the OSSS Pydantic ecosystem.

evaluate(context, metadata)

Evaluate if this rule should be applied.

apply(context, metadata)

Apply the rule's action.

AgentDiscoverer

Bases: ABC

Abstract base for agent discovery implementations.

discover_agents() abstractmethod async

Discover available agents.

can_hot_reload() abstractmethod

Check if this discoverer supports hot reloading.

FilesystemDiscoverer

Bases: AgentDiscoverer

Discover agents by scanning the filesystem.

discover_agents() async

Discover agents by scanning filesystem.

can_hot_reload()

Filesystem discoverer supports hot reloading.

RegistryDiscoverer

Bases: AgentDiscoverer

Discover agents using the agent registry.

discover_agents() async

Discover agents from registry.

can_hot_reload()

Registry discoverer has limited hot reload support.

DynamicAgentComposer

Dynamic agent composer with runtime discovery and hot-swapping.

Provides capabilities for discovering agents at runtime, dynamically composing execution graphs, and hot-swapping failed or outdated agents.

add_discoverer(discoverer)

Add an agent discoverer.

add_composition_rule(rule)

Add a dynamic composition rule.

add_event_handler(event, handler)

Add an event handler for composition events.

discover_agents(force_rediscovery=False) async

Run discovery across all configured discoverers.

load_agent(agent_id, force_reload=False) async

Load an agent by ID.

hot_swap_agent(old_agent_id, new_agent_id, context) async

Hot-swap one agent for another.

auto_discover_and_swap(context) async

Automatically discover new agents and perform beneficial swaps.

optimize_composition(context) async

Optimize the current agent composition using composition rules.

get_composition_status()

Get comprehensive composition status.

enable_auto_discovery(interval_seconds=300)

Enable automatic agent discovery.

enable_auto_swap()

Enable automatic agent swapping.

create_version_upgrade_rule()

Create a rule that swaps agents when newer versions are available.

create_failure_recovery_rule()

Create a rule that swaps failing agents.