Skip to main content

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.

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 AgentNotFound if the chosen agent cannot be resolved.
  • Registry validation uses RegistryError; routing errors derive from RoutingError.
  • 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_chars can bound the generated prompt.
  • Observability: PydanticAIDispatcher accepts on_event callback (receives RoutingEvent) 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), and RoutingEvent.
  • Adapter: agent_registry_router.adapters.pydantic_ai exposes PydanticAIDispatcher, DispatchResult. 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 agent and confidence or InvalidRouteDecision is raised.
  • Prompt determinism: preserves registration order; only routable agents; optional max_prompt_chars; description cap 512 chars.
  • Hooks: on_event receives RoutingEvent(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

agent_registry_router-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

agent_registry_router-0.2.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file agent_registry_router-0.2.0.tar.gz.

File metadata

  • Download URL: agent_registry_router-0.2.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agent_registry_router-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dc374491bf9618734a24fe704ac368240bbb3e114ed9ead430e6d0838e6426db
MD5 99c643b18fa77b521a988d39685b087c
BLAKE2b-256 13316c7333563c74eace863258f015451ce9cddeb69657a8fe5bf9037cdf4d9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_registry_router-0.2.0.tar.gz:

Publisher: publish-pypi.yml on agibson22/agent-registry-router

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_registry_router-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_registry_router-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd0087dac15bdd87aa4f05c3a015ab20a70166a25ff85a814f9e1cb57227f64b
MD5 b88db96977c2bb5cb455c616b1f58d7a
BLAKE2b-256 a554d8263e79758528d8c8d73acd22a5801d4ff4d7e1c255607841974c3507f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_registry_router-0.2.0-py3-none-any.whl:

Publisher: publish-pypi.yml on agibson22/agent-registry-router

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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