Routing strategies for the AccuralAI orchestration pipeline.
Project description
accuralai-router
accuralai-router provides pluggable routing strategies for the AccuralAI orchestration core. Routers map canonicalized requests to backend identifiers using deterministic policies, weighted load balancing, failover rules, metadata-aware predicates, or complexity-based tiering.
Features
- Async routers that satisfy the
Routerprotocol fromaccuralai-core. - Direct routing honoring request hints or configured defaults.
- Weighted distribution with deterministic seeding and optional per-backend capacity limits.
- Health-aware failover that cycles through fallback backends.
- Rules engine that matches tags, metadata, or parameter values.
- Complexity-based routing that intelligently routes simple tasks to efficient models and complex tasks to powerful models.
Install alongside the core orchestrator:
pip install accuralai-core accuralai-router
Complexity Router
The complexity router analyzes request characteristics to automatically route tasks to appropriate model tiers, optimizing cost and performance.
Scoring Factors
The router calculates a complexity score using configurable weights:
- Token count: Base complexity from prompt + system_prompt + history length
- History depth: Additional points per conversation turn (default: 2.0 per turn)
- Tool presence: Flat bonus for requests with tools defined (default: 10.0)
- Parameter complexity: Advanced generation parameters like extreme temperatures, top_k, custom params (default: 5.0 weight)
Tier Assignment
Requests are routed to three tiers based on score thresholds:
- Low tier (
< 50): Simple tasks → efficient models (e.g.,gemini-2.0-flash-lite) - Medium tier (
50-199): Moderate tasks → balanced models (e.g.,gemini-2.0-flash) - High tier (
≥ 200): Complex tasks → powerful models (e.g.,gemini-2.5-flash)
Configuration Example
[router]
plugin = "complexity"
[router.options]
low_threshold = 50.0
high_threshold = 200.0
honor_explicit_complexity = true
backend_id = "google"
[router.options.scoring]
token_weight = 1.0
history_weight = 2.0
tool_weight = 10.0
parameter_complexity_weight = 5.0
[[router.options.tiers]]
tier = "low"
models = ["gemini-2.0-flash-lite"]
[[router.options.tiers]]
tier = "medium"
models = ["gemini-2.0-flash", "gemini-2.0-flash-lite"]
[[router.options.tiers]]
tier = "high"
models = ["gemini-2.5-flash", "gemini-2.0-flash"]
# Single backend configuration
[backends.google]
plugin = "google"
[backends.google.options]
model = "gemini-2.5-flash" # Default model, overridden by router
Explicit Complexity Override
You can override automatic scoring by setting explicit complexity in request metadata:
request = GenerateRequest(
prompt="Complex task that should use powerful model",
metadata={"complexity": "high"} # Forces high-tier routing
)
Tuning Complexity Scoring
Adjust scoring weights based on your use case:
- Higher
token_weight: Emphasize prompt length - Higher
history_weight: Penalize long conversations more - Higher
tool_weight: Treat tool usage as more complex - Higher
parameter_complexity_weight: Weight advanced generation parameters more
Development
python -m venv .venv && source .venv/bin/activate
pip install -e packages/accuralai-core[dev]
pip install -e packages/accuralai-router[dev]
pytest packages/accuralai-router/tests -q
Routers register entry points under accuralai_core.routers so accuralai-core can discover them automatically.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file accuralai_router-0.2.0.tar.gz.
File metadata
- Download URL: accuralai_router-0.2.0.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dc9a2752918daa67a03d002d451e698332478eb20c4d8b5cfddb8eef82fe6c6
|
|
| MD5 |
a0927277d55ad0004e926674c978ed9d
|
|
| BLAKE2b-256 |
9a4ea40c033b090ee9fd24ef1fa1d4baed1f8b90a5a0745ae397e141d6b4334b
|
File details
Details for the file accuralai_router-0.2.0-py3-none-any.whl.
File metadata
- Download URL: accuralai_router-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc6fab53d63c8f21a2c1504f6fa6e4831f37946990a5b04adfe75e967a2da21c
|
|
| MD5 |
1c45df60f0976728625c9b067f212d36
|
|
| BLAKE2b-256 |
ae6e973ddfb42fbabe5cae62f0ff608a9bf897974ab140f5ee287874e5202c84
|