Skip to content

API Reference parrot.registry.routing.rules

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.registry.routing.rules

View source

Fast-path rules engine for the store-level router (FEAT-111 Module 4).

Provides a stateless :func:apply_rules function that scores candidate stores based on heuristic keyword/regex rules. Hardcoded default rules cover the most common cases; per-agent StoreRule lists can be merged on top.

Usage::

from parrot.registry.routing import apply_rules, DEFAULT_STORE_RULES
from parrot.models import StoreType

scores = apply_rules(
    "what is the relationship between suppliers and warehouses?",
    DEFAULT_STORE_RULES,
    [StoreType.PGVECTOR, StoreType.ARANGO],
    ontology_annotations={"action": "graph_query"},
)
# → [StoreScore(store=ARANGO, confidence=1.0, ...), ...]

Attribute DEFAULT_STORE_RULES

Type: list[StoreRule]

Alias StoreRule

Re-exported from parrot.registry.routing.models.StoreRule.

Alias StoreScore

Re-exported from parrot.registry.routing.models.StoreScore.

Alias StoreType

Re-exported from parrot.models.StoreType.

Function apply_rules

Score available_stores for query using the provided rules.

Algorithm:

  1. Lowercase the query once.
  2. For each rule, check whether the query matches (substring or regex). If the rule's store is not in available_stores the rule is silently skipped.
  3. For each store, keep only the maximum weight across all matching rules (do NOT sum — keeps confidences bounded in [0, 1]).
  4. Apply ontology boosts (if ontology_annotations signals a preference).
  5. Sort descending by confidence.

apply_rules(query: str, rules: list[StoreRule], available_stores: list[StoreType], ontology_annotations: Optional[dict]) -> list[StoreScore]

Parameter Type Default Description
query str Raw user query string.
rules list[StoreRule] StoreRule list to evaluate. Typically the built-in :data:DEFAULT_STORE_RULES plus any per-agent custom rules.
available_stores list[StoreType] Stores actually configured on the bot. Rules targeting other stores are filtered out.
ontology_annotations Optional[dict] Output of OntologyPreAnnotator.annotate(). Pass None or {} when the ontology is not configured.

Returns: list[StoreScore] — Ranked list[StoreScore] — descending by confidence. Empty list when no rules matched and no ontology signal applied.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally