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.

Graph Compiler

Declarative YAML templates compiled into secure LangGraph state machines with platform tool dispatch.

LLM Provider Routing

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

Platform Tools

Universal LLM capabilities (classify, generate, review, filter, plan, match) composable by any project.

Security by Construction

Frozen Pydantic configs, per-node token attenuation, and Shield integration for prompt injection defence.

Architecture

src/contextunity/router/
├── modules/ # Capability modules
│ ├── models/ # LLM providers (14 backends)
│ │ ├── registry.py # Model registry with fallback
│ │ └── llm/ # openai, anthropic, vertex, groq, perplexity, openrouter, rlm, ...
│ ├── connectors/ # Data source connectors (Web, RSS, API, File)
│ ├── providers/storage/ # Brain, Postgres, Vertex, GCS
│ ├── tools/ # LLM tool registry
│ ├── retrieval/rag/ # RAG pipeline
│ └── protocols/ # A2A, AG-UI adapters
├── cortex/ # AI orchestration core
│ ├── graphs/ # LangGraph agents
│ │ ├── dispatcher.py # Central graph router
│ │ ├── compiler/ # ⭐ Graph Compiler Engine
│ │ │ ├── builder.py # build_from_template(), build_local_graph()
│ │ │ ├── template_loader.py # YAML → Pydantic → TemplateDefinition
│ │ │ ├── topology.py # Edge auto-completion, tool ref parsing
│ │ │ ├── node_factory.py # Node compilation (type → executor)
│ │ │ ├── platform_registry.py # PlatformToolRegistry
│ │ │ └── platform_tools/ # Router, SQL, Content, Brain, Services
│ │ ├── dispatcher_agent/ # Multi-agent dispatcher
│ │ └── states/ # Shared graph state schemas
│ ├── templates/ # ⭐ YAML graph templates
│ │ ├── retrieval_augmented.yaml # Unified RAG + SQL
│ │ ├── gardener.yaml # Product normalisation
│ │ ├── enricher.yaml # Product enrichment
│ │ ├── rlm_bulk_matcher.yaml # RLM bulk matching
│ │ └── news_pipeline.yaml # News processing
│ └── utils/ # Shared utilities
├── service/ # gRPC service
│ ├── dispatcher_service.py # Dispatcher RPC handler
│ ├── graph_registration.py # Graph compilation and registry
│ ├── stream_executors.py # Bi-directional stream handling
│ └── mixins/ # execution, registration, stream, persistence
├── core/ # Configuration, registry, plugins
├── api/ # REST/protocol adapters
└── cli/ # CLI utilities