Registry-driven LLM routing: build classifier prompts from agent descriptions, validate decisions, and dispatch.
Project description
agent-registry-router
Registry-driven LLM routing: build classifier prompts from agent descriptions, validate decisions, and dispatch to other agents.
What is this? Why use it?
agent-registry-router helps you route LLM traffic to the right agent by:
- Keeping a registry of agents
- Building classifier prompts from that registry
- Validating classifier decisions with clear, typed errors
- Dispatching to runtime agents with optional observability hooks (
on_event) for logging/metrics.
Use it when you need:
- A stable contract between your classifier and execution layer
- Deterministic, size-aware prompt construction
- Lightweight integration with frameworks like PydanticAI
- Extensibility: plug your own classifier/agents, add hooks for monitoring, and keep routing logic decoupled from business logic
Features
- Registry-driven classifier prompts (deterministic order, routable-only, size-aware)
- Fail-fast validation with typed errors (no silent fallbacks)
- PydanticAI dispatcher with pinned bypass and observability hooks (
on_event) - Typed package (
py.typed) and CI gates (ruff/black/mypy/pytest-cov) - FastAPI demo with pinned bypass:
examples/fastapi_pinned_bypass/README.md
Scope
- Routing, validation, observability; bring your own LLM clients/agents.
- Adapters are opt-in; core stays lightweight.
Status
- v0.2.3 — fail-fast by default; adapters namespaced; PydanticAI adapter supports streaming dispatch.
Install (uv)
From PyPI:
uv pip install agent-registry-router
From a checkout of this repo (dev/editable):
uv venv
source .venv/bin/activate
uv pip install -e .
Core usage
from agent_registry_router.core import (
AgentRegistration,
AgentRegistry,
RouteDecision,
build_classifier_system_prompt,
validate_route_decision,
)
registry = AgentRegistry()
registry.register(AgentRegistration(name="general", description="General help."))
registry.register(AgentRegistration(name="special", description="Special help."))
prompt = build_classifier_system_prompt(
registry,
preamble="You are a query classifier that routes user messages to the appropriate agent.",
default_agent="general",
)
decision = RouteDecision(agent="special", confidence=0.9, reasoning="Clear match.")
validated = validate_route_decision(decision, registry=registry, default_agent="general")
Behavior & errors
- Default agent must be routable; unknown agents or empty registries raise.
- Classifier selecting a non-routable agent raises
InvalidRouteDecision. - Missing default or no routable agents raises
InvalidFallback. - Dispatcher raises
AgentNotFoundif the chosen agent cannot be resolved. - Registry validation uses
RegistryError; routing errors derive fromRoutingError. - Confidence adjustment on invalid routes is unchanged; pinned invalid falls back to the classifier.
- Prompt listing preserves registration order; only routable agents are included.
- Agent descriptions are capped at 512 characters; prompts cannot be built without routable agents. Optional
max_prompt_charscan bound the generated prompt. - Observability:
PydanticAIDispatcheracceptson_eventcallback (receivesRoutingEvent) and optional logger; emits events for classifier run, validation, pinned bypass, agent resolution, and agent run.
API contracts
- Public imports (
agent_registry_router.core):AgentRegistry,AgentRegistration,RouteDecision,ValidatedRouteDecision,validate_route_decision,build_classifier_system_prompt, exceptions (AgentRegistryRouterError,RegistryError,RoutingError,InvalidRouteDecision,InvalidFallback,AgentNotFound), andRoutingEvent. - Adapter:
agent_registry_router.adapters.pydantic_aiexposesPydanticAIDispatcher,DispatchResult,AgentStreamChunk. Adapters stay namespaced (not re-exported at package root). - Routing invariants: default agent must be routable; empty registry errors; non-routable selections error; pinned invalid falls back to classifier; classifier output must include
agentandconfidenceorInvalidRouteDecisionis raised. - Prompt determinism: preserves registration order; only routable agents; optional
max_prompt_chars; description cap 512 chars. - Hooks:
on_eventreceivesRoutingEvent(kind, payload, error); hook failures are swallowed; logger is optional.
Adapters
- PydanticAI dispatcher:
src/agent_registry_router/adapters/pydantic_ai/README.md
Tests (uv)
uv pip install -e ".[dev]"
ruff check .
black --check .
mypy --config-file pyproject.mypy.ini .
pytest --cov=agent_registry_router --cov-fail-under=85
Example: FastAPI pinned bypass
See examples/fastapi_pinned_bypass/.
License
Apache-2.0 (see LICENSE).
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
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 agent_registry_router-0.2.3.tar.gz.
File metadata
- Download URL: agent_registry_router-0.2.3.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f153516ca4a64e2160f9850ee40c9b09a6f3210d4ea321207a4e4171f89d3424
|
|
| MD5 |
b7025ac3c7d6dc03db08ab97783a1341
|
|
| BLAKE2b-256 |
c23b915ead3890c0235344a89bc2944fbb21c1f68e532d3a4a7797d25850ec54
|
Provenance
The following attestation bundles were made for agent_registry_router-0.2.3.tar.gz:
Publisher:
publish-pypi.yml on agibson22/agent-registry-router
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_registry_router-0.2.3.tar.gz -
Subject digest:
f153516ca4a64e2160f9850ee40c9b09a6f3210d4ea321207a4e4171f89d3424 - Sigstore transparency entry: 803501412
- Sigstore integration time:
-
Permalink:
agibson22/agent-registry-router@9ce1ca1e845911432dcd40bb03b3b672cbe9d957 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/agibson22
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@9ce1ca1e845911432dcd40bb03b3b672cbe9d957 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agent_registry_router-0.2.3-py3-none-any.whl.
File metadata
- Download URL: agent_registry_router-0.2.3-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f81646a3dacf2b0757081a3715ccf8057fe70b0f365ea69697539c73d6f22f4
|
|
| MD5 |
c8dda0491d7e66f637c14458adc43af5
|
|
| BLAKE2b-256 |
88a83f357b88831a5995f76fa22315dea0f50a746a4494f705ae41b62de3ce45
|
Provenance
The following attestation bundles were made for agent_registry_router-0.2.3-py3-none-any.whl:
Publisher:
publish-pypi.yml on agibson22/agent-registry-router
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_registry_router-0.2.3-py3-none-any.whl -
Subject digest:
8f81646a3dacf2b0757081a3715ccf8057fe70b0f365ea69697539c73d6f22f4 - Sigstore transparency entry: 803501423
- Sigstore integration time:
-
Permalink:
agibson22/agent-registry-router@9ce1ca1e845911432dcd40bb03b3b672cbe9d957 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/agibson22
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@9ce1ca1e845911432dcd40bb03b3b672cbe9d957 -
Trigger Event:
push
-
Statement type: