3.2: Create AgentRegistry

New file cheddahbot/agent_registry.py. Holds multiple Agent instances
keyed by name with methods: register(), get(), list_agents(), and
default property. First registered agent is the default.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cora-start
PeninsulaInd 2026-02-17 10:06:56 -06:00
parent 6c2c28e9b0
commit 537e3bd528
1 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,49 @@
"""Multi-agent registry.
Holds multiple Agent instances keyed by name. The first registered
agent is the default (used by scheduler and as fallback).
"""
from __future__ import annotations
import logging
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .agent import Agent
log = logging.getLogger(__name__)
class AgentRegistry:
"""Registry of named Agent instances."""
def __init__(self):
self._agents: dict[str, Agent] = {}
self._default_name: str | None = None
def register(self, name: str, agent: Agent, is_default: bool = False):
"""Register an agent by name."""
self._agents[name] = agent
if is_default or self._default_name is None:
self._default_name = name
log.info("Registered agent: %s (default=%s)", name, name == self._default_name)
def get(self, name: str) -> Agent | None:
return self._agents.get(name)
def list_agents(self) -> list[str]:
return list(self._agents.keys())
@property
def default(self) -> Agent | None:
if self._default_name:
return self._agents.get(self._default_name)
return None
@property
def default_name(self) -> str:
return self._default_name or "default"
def __len__(self) -> int:
return len(self._agents)