Skip to main content

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 Router protocol from accuralai-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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

accuralai_router-0.2.1.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

accuralai_router-0.2.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file accuralai_router-0.2.1.tar.gz.

File metadata

  • Download URL: accuralai_router-0.2.1.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for accuralai_router-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7e55526752ea08fcfc95668f03114c0ed1f3c9038f0bdfee87d008e23d44c64e
MD5 bca9d4f21fc364a43d977039665419cb
BLAKE2b-256 4eb63830b25e12ed3b878e92777fc2874dd7bf498694830f0df9b4d1af199b0d

See more details on using hashes here.

File details

Details for the file accuralai_router-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for accuralai_router-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71f2eee56cd33f42784470b13db60fbe618fe743d1111b357bba128772b24928
MD5 e78cab2cae1c3e151d97db0d5b524647
BLAKE2b-256 b51f7aa9f7d049ee703c8a2ca6f0854cf23d5f3df1b85c04b564d3b50a60a96f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page