Skip to content

ContextRouter

ContextRouter is the “Mind” of the ContextUnity ecosystem. It receives requests from various protocols (Telegram, Web, API), orchestrates LangGraph agents, routes to LLM providers, and delegates memory to Brain.

Agent Orchestration

LangGraph state machines for complex multi-step reasoning workflows with full provenance tracking.

LLM Provider Routing

13 LLM providers with automatic fallback: OpenAI, Anthropic, Vertex AI, Groq, Perplexity, and more.

Tool Integration

Exposes Brain (search), Commerce (products), and custom tools for LLM function calling.

Observability

Full OpenTelemetry tracing and Langfuse integration for agent step visibility.

Architecture

src/contextrouter/
├── modules/ # Capability modules
│ ├── models/ # LLM providers (13 backends)
│ │ ├── registry.py # Model registry with fallback
│ │ ├── llm/
│ │ │ ├── openai.py # OpenAI (GPT-5, o1, o3)
│ │ │ ├── anthropic.py # Anthropic (Claude Sonnet/Haiku)
│ │ │ ├── vertex.py # Google Vertex AI (Gemini 2.x)
│ │ │ ├── perplexity.py # Perplexity (Sonar)
│ │ │ ├── groq.py # Groq (ultra-fast Llama)
│ │ │ ├── rlm.py # RLM (Recursive Language Model)
│ │ │ └── ... # HuggingFace, OpenRouter, LiteLLM, etc.
│ │ └── embeddings/ # Embedding providers
│ ├── connectors/ # Data source connectors (Web, RSS, API, File)
│ ├── transformers/ # NER, taxonomy, summarization, ontology
│ ├── providers/storage/ # Brain, Postgres, Vertex, GCS
│ ├── tools/ # LLM tool registry
│ ├── retrieval/rag/ # RAG pipeline
│ └── observability/ # OpenTelemetry tracing
├── cortex/ # AI orchestration core
│ ├── graphs/ # LangGraph agent definitions
│ │ ├── dispatcher.py # Central graph router
│ │ ├── rag_retrieval/ # RAG pipeline graph
│ │ ├── commerce/gardener/ # Taxonomy classifier
│ │ ├── commerce/matcher/ # Product linking (RLM-based)
│ │ ├── news_engine/ # Multi-stage news pipeline
│ │ └── analytics/ # Data analytics graphs
│ ├── services/graph/ # Graph execution service
│ ├── subagents/ # Sub-agent orchestration
│ ├── prompting/ # Prompt templates
│ └── runners/ # Stream/invoke helpers
├── core/ # Configuration, registry, plugins
│ ├── registry.py # Module registry
│ ├── plugins.py # Plugin architecture
│ ├── interfaces.py # Base classes for Connector/Transformer/Provider
│ ├── memory.py # Agent memory management
│ └── tokens.py # Token utilities
├── service/ # gRPC service
│ ├── server.py # gRPC server setup
│ ├── dispatcher_service.py # Dispatcher RPC handler
│ ├── stream_executors.py # Bi-directional stream handling
│ └── security.py # Shield client integration
├── api/ # REST/protocol adapters
└── cli/ # CLI utilities