Efficient Agent Router — routes tasks to the best LLM under quality, latency, cost, and safety constraints
Project description
Efficient Agent Router (EAR)
Efficient Agent Router (EAR) is a Python-first orchestration service that selects and executes the best LLM for a request based on quality, cost, latency, context window, and safety constraints.
Goals
- Route each request to the most suitable model for the task.
- Reduce token burn through cost-aware model ranking.
- Protect sensitive input with prompt-injection and PII safeguards.
- Provide a clean CLI first, then expose the same logic through MCP.
Current Delivery Strategy
- Build and validate core routing engine through CLI.
- Harden reliability, guardrails, and observability.
- Expose stable capabilities through MCP server.
Tech Stack
- Python 3.12+
- asyncio
- Typer CLI
- Pydantic v2
- httpx for OpenRouter model metadata
- pytest, pytest-asyncio, pytest-cov
- bandit and pip-audit for security controls
Planned Repository Layout
- docs/
- system_prompt.md
- execution_plan.md
- adr/
- src/
- ear/
- router_engine.py
- registry.py
- guardrails.py
- fallback.py
- metrics.py
- cli.py
- mcp_server.py
- ear/
- tests/
- test_registry.py
- test_router_engine.py
- test_guardrails.py
- test_fallback.py
- test_cli.py
- test_mcp_server.py
Core Workflow
- Accept user task input and options (task hint, budget priority, context profile).
- Run safety prechecks (injection and PII policy).
- Load model metadata from OpenRouter registry cache.
- Compute suitability score and candidate ranking.
- Return model recommendation, rationale, and fallback chain (execution runtime is tracked in E10).
- Emit session metrics snapshot for observability.
Routing Model
The router evaluates candidate models using a weighted suitability function:
S = Quality / (Cost * Latency)
Where score inputs are normalized and constrained by policy:
- Context window threshold
- Budget priority
- Safety allowlist and PII policy
- Task-specific boosts (coding, planning, research)
CLI Design (Phase 1)
Expected commands:
- ear route "" --task coding --budget medium
- ear inspect-models
- ear stats --session
Expected output modes:
- Human-readable summary
- JSON output for scripting pipelines
MCP Design (Phase 2)
- Tool: route_and_execute
- Resources: model performance metrics, cost per session
- Transport: stdio first, optional SSE extension
Interactive LLM Explorer UI
- File:
docs/llm_explorer.html - Purpose: interactive OpenRouter model table for leadership and investor demos.
What it includes:
- Live model fetch from OpenRouter (
/api/v1/models) with auto-refresh options and last-updated indicator. - Search, provider pills, min-context, max-cost, and priced/unpriced filters.
- Radio filter for free vs paid models.
- Excel-style sortable table with per-column filters.
- Side-by-side comparison cards for selected models (up to 4).
How to run:
- Open
docs/llm_explorer.htmldirectly in a browser, or - Serve repo root with a static server and open
/docs/llm_explorer.html.
Example with Python static server:
python -m http.server 8080
# then browse http://localhost:8080/docs/llm_explorer.html
Configuration
Environment variables (minimum):
- OPENROUTER_API_KEY
- EAR_REGISTRY_TTL_SECONDS
- EAR_DEFAULT_BUDGET
- EAR_MAX_RETRIES
- EAR_OPENROUTER_BASE_URL
- EAR_REQUEST_TIMEOUT_SECONDS
Recommended local setup steps:
- Create and activate virtual environment.
- Install dependencies.
- Copy
.env.exampleto.envand set values. - Run tests and quality checks before first run.
Quality and Security Requirements
- 100% statement and branch coverage for routing core.
- Deterministic tests with mocked external dependencies.
- Security linting with bandit.
- Dependency auditing with pip-audit.
- No plaintext secret logging.
Security Report HTML Generation
- Security workflows generate JSON first, then render HTML using sec-report-kit.
- pip-audit workflow outputs: security_reports/pip_audit_latest.html.
- Trivy workflow outputs: security_reports/trivy_latest.html.
- Both HTML files are uploaded in the workflow artifacts alongside JSON and SARIF outputs.
- Local scripts also generate HTML from JSON:
- run_pip_audit.bat / run_pip_audit.sh
- run_trivy.bat / run_trivy.sh
- one-command wrapper: run_security_audits.bat / run_security_audits.sh
MCP Server: sec-report-kit
Install sec-report-kit locally:
pip install sec-report-kit
Configured MCP server command:
srk mcp serve --transport stdio
Workspace configuration is stored in .vscode/mcp.json.
Milestones
- M1: Registry and schema baseline
- M2: Router core and CLI
- M3: Guardrails and metrics
- M4: MCP server and CI/CD gates
- M5: Execution runtime and adaptive routing intelligence (completed)
- M6: Leadership/investor demo frontend (completed)
Contributing Expectations
- Preserve clean architecture boundaries.
- Add tests for every logic branch touched.
- Update ADRs when making architecture-affecting decisions.
- Keep operational docs current with behavior changes.
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 efficient_agent_router_ear-0.10.13.tar.gz.
File metadata
- Download URL: efficient_agent_router_ear-0.10.13.tar.gz
- Upload date:
- Size: 64.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f46be47261fa774989ece2980efd2e564f6699afe5d9d4353f60855e260769a
|
|
| MD5 |
c079a823660617ab119d87135d7367a6
|
|
| BLAKE2b-256 |
495fb3553073b46ac1a33d05e3a91cbefd021de18c23f592b616769457911376
|
Provenance
The following attestation bundles were made for efficient_agent_router_ear-0.10.13.tar.gz:
Publisher:
publish-pypi.yml on ShanKonduru/efficient-agent-router-ear
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
efficient_agent_router_ear-0.10.13.tar.gz -
Subject digest:
7f46be47261fa774989ece2980efd2e564f6699afe5d9d4353f60855e260769a - Sigstore transparency entry: 1431131679
- Sigstore integration time:
-
Permalink:
ShanKonduru/efficient-agent-router-ear@4311c7de81289819e3a7edea3139b915b9aaa73f -
Branch / Tag:
refs/tags/v0.10.13 - Owner: https://github.com/ShanKonduru
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4311c7de81289819e3a7edea3139b915b9aaa73f -
Trigger Event:
push
-
Statement type:
File details
Details for the file efficient_agent_router_ear-0.10.13-py3-none-any.whl.
File metadata
- Download URL: efficient_agent_router_ear-0.10.13-py3-none-any.whl
- Upload date:
- Size: 42.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f45542b6fc99d78fc154cc608b0660bc0f3bc0e7d1534a0342eb7f1fc55c1400
|
|
| MD5 |
053ab1b09b48e42175eaccca239a0c2b
|
|
| BLAKE2b-256 |
5444edabc6698d11aa2e502b4f74a78f471030b6defca5a4435fbf5e05d4998f
|
Provenance
The following attestation bundles were made for efficient_agent_router_ear-0.10.13-py3-none-any.whl:
Publisher:
publish-pypi.yml on ShanKonduru/efficient-agent-router-ear
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
efficient_agent_router_ear-0.10.13-py3-none-any.whl -
Subject digest:
f45542b6fc99d78fc154cc608b0660bc0f3bc0e7d1534a0342eb7f1fc55c1400 - Sigstore transparency entry: 1431131793
- Sigstore integration time:
-
Permalink:
ShanKonduru/efficient-agent-router-ear@4311c7de81289819e3a7edea3139b915b9aaa73f -
Branch / Tag:
refs/tags/v0.10.13 - Owner: https://github.com/ShanKonduru
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4311c7de81289819e3a7edea3139b915b9aaa73f -
Trigger Event:
push
-
Statement type: