Router - Agent Dispatcher
Overview
The Router is a core component in the TKM AI Agency Platform that manages the dispatching and handling of requests between agents. It provides specialized handlers for each agent type, ensuring proper request preparation and response processing.
Directory Structure
Backend/Core_Components/
├── agent_router.py # Main router implementation
├── agent_router_handlers.py # Agent-specific handlers
└── types.py # Type definitions
Main Components
AgentRouter Class
The core component that manages request routing:
- Handler management
- Request dispatching
- Response processing
- State tracking
Agent Handlers
Specialized handlers for each agent:
- PrometheusHandler (General Chat)
- OrionHandler (Knowledge Organization)
- CarinaHandler (Search)
- PegasoHandler (Web Crawler)
Processing Pipeline
-
Request Reception
- Handler selection
- Request validation
- Context preparation
- State verification
-
Request Processing
- Data transformation
- Context enrichment
- Handler execution
- Response formatting
-
Response Management
- Response validation
- State updates
- Context updates
- History tracking
API Operations
Prepare Request
- Method:
prepare_request
- Purpose: Prepares agent-specific requests
- Parameters:
{ "conversation_data": Dict[str, Any] }
Handle Response
- Method:
handle_response
- Purpose: Processes agent responses
- Parameters:
{ "response": Dict[str, Any], "conversation_data": Dict[str, Any], "mediator": Any }
Key Features
-
Handler Management
- Dynamic handler selection
- Agent specialization
- Default handling
- State management
-
Request Processing
- Context preparation
- Data transformation
- Validation rules
- Error handling
-
Response Processing
- Response formatting
- State updates
- History tracking
- Error recovery
Handler Types
Specialized Handlers
-
PrometheusHandler
- Chat context management
- Message history
- Response formatting
-
OrionHandler
- Document processing
- Structure determination
- State management
-
CarinaHandler
- Search preparation
- Result processing
- Context enrichment
-
PegasoHandler
- Crawl request preparation
- Result analysis
- Data extraction
Error Handling
-
Request Errors
- Invalid data
- Missing context
- Handler errors
- State conflicts
-
Processing Errors
- Transformation failures
- Validation errors
- Context errors
- Recovery procedures
Performance Features
-
Optimization
- Efficient routing
- Context caching
- Resource management
- Memory control
-
Monitoring
- Request tracking
- Response timing
- Error logging
- Performance metrics
Data Models
Request Context
{
"conversation_id": str,
"messages": List[Dict[str, Any]],
"metadata": Dict[str, Any],
"state": Dict[str, Any]
}
Handler Response
{
"success": bool,
"data": Dict[str, Any],
"errors": Optional[List[str]],
"metadata": Dict[str, Any]
}