router
- class agentopera.router.AgentFactory[source]
Bases:
object
- classmethod create_agent_registry(intent_registry: IntentRegistry) AgentRegistryBase [source]
Creates an AgentRegistry from an IntentRegistry.
- Parameters:
intent_registry (IntentRegistry) – The shared config source.
- Returns:
A runtime-compatible registry.
- Return type:
AgentRegistryBase
- classmethod create_intent_classifier(intent_registry: IntentRegistry) LLMIntentClassifier [source]
Creates an LLM-powered intent classifier using the provided intent registry.
- Parameters:
intent_registry (IntentRegistry) – The shared config source.
- Returns:
Configured classifier using OpenAI-compatible tools.
- Return type:
- classmethod create_intent_registry(intent_descriptions: dict[str, str], agent_intent_mapping: dict[str, str], agent_descriptions: dict[str, str], schema_overrides: Dict[str, dict] | None = None) IntentRegistry [source]
- class agentopera.router.AgentRegistry(intent_registry: IntentRegistry)[source]
Bases:
AgentRegistryBase
Runtime-compatible agent registry adapter.
Wraps around IntentRegistry to expose methods required by SemanticRouterAgent and other runtime components.
Responsibilities: - Asynchronously fetch agents based on classified intent - Serve agent metadata for monitoring and validation
- async get_agent(intent: str) str [source]
Retrieves the agent type corresponding to a given intent.
Falls back to ‘chat’ if intent is not mapped.
- Parameters:
intent – The intent for which to retrieve an agent.
- Returns:
The agent type (e.g., ‘chat’, ‘vercel’, etc.)
- async get_agents() Set[str] [source]
Retrieves the set of all registered agent IDs.
- Returns:
A set of agent IDs.
- class agentopera.router.IntentRegistry(intent_descriptions: Dict[str, str], agent_intent_mapping: Dict[str, str], agent_descriptions: Dict[str, str | list[str]], schema_overrides: Dict[str, dict] | None = None)[source]
Bases:
object
Internal configuration holder for intent and agent relationships.
This class is designed to manage: - Intent descriptions for classification models - Mapping from intent → agent_id - Mapping from agent_id → descriptions
It acts as the source of truth for the classifier and agent registry.
- classmethod from_api_data(api_data: List[UserAgentInfo]) IntentRegistry [source]
- merge(other: IntentRegistry) IntentRegistry [source]
- class agentopera.router.SemanticRouterAgent(name: str)[source]
Bases:
RoutedAgent
- async route_to_agent(message: TextMessage | MultiModalMessage, ctx: MessageContext) None [source]
- event_log(session_id: str, agent_id: str) None [source]
Logs the agent selection event to PostHog.
- Parameters:
session_id (str) – The ID of the current customer session.
agent_id (str) – The ID of the agent handling the message.
- async contact_agent(agent_name: str, message: TextMessage | MultiModalMessage, ctx: MessageContext, session_id: str) None [source]
- class agentopera.router.LLMIntentClassifier(intent_registry: IntentRegistry, model='Llama-3.1-8B-Instruct')[source]
Bases:
IntentClassifierBase