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:

LLMIntentClassifier

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.

async get_agent_description(agent_id: str) str[source]

Retrieves the description of a specific agent by its ID.

Parameters:

agent_id – The agent ID for which to retrieve the description.

Returns:

The agent’s description.

async get_agent_descriptions() Dict[str, str | list[str]][source]

Retrieves descriptions of all registered agents.

Returns:

A dictionary mapping agent IDs to their descriptions.

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]
get_all_intents() Set[str][source]

Returns all available intent keys.

get_schema_override(intent: str) dict[source]

Returns all overriding schemas if any

get_description(intent: str) str[source]

Returns description for a specific intent.

get_agent_for_intent(intent: str) str[source]

Returns agent_id associated with the given intent.

get_all_agents() Set[str][source]

Returns all registered agent IDs.

get_agent_description(agent_id: str) str | list[str][source]

Returns description for the specified agent.

get_tool_schemas() list[dict][source]

Builds OpenAI-compatible tool definitions for all registered intents.

Returns:

List of function tool schema dictionaries for OpenAI-compatible models.

class agentopera.router.SemanticRouterAgent(name: str)[source]

Bases: RoutedAgent

async initialize()[source]
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

async classify_intent(message: TextMessage | MultiModalMessage, timeout: float | None = 80.0) str[source]

Returns the intent with the highest confidence score.