Skip to main content

Classify-then-Dispatch for AI agents under constraint-driven canonical cases

Project description

qadiya (قضية) — Classify + Dispatch under Constraint-Driven Cases

Part of the Mizan stack — the Arabic-first reliability scale for AI agents.

License: MIT Python 3.10+ Tests: 15 passing

The third + fourth primitives of the reversible-agent-operations pattern: case classification under a constraint set, and dispatch to registered procedures.


What it does

Given a list of constraints (e.g., "operation type", "target scope", "reversibility"), qadiya enumerates the Cartesian product of constraint values, prunes infeasible combinations, and gives you a registry. You register one procedure per surviving case. dispatch() classifies an incoming input by evaluating constraints, then runs the registered procedure for the matching case. If no case matches, it raises — never silently falls through to a "general" handler.

from qadiya import Constraint, CaseRegistry, Dispatch

c_op = Constraint("op", values=("read", "write"),
                   evaluate=lambda r: r["op"])
c_target = Constraint("target", values=("user_file", "system_file"),
                       evaluate=lambda r: r["target"])
c_in_repo = Constraint("in_repo", values=(True, False),
                        evaluate=lambda r: r["in_repo"])

# Pruning: writes outside the repo are infeasible (escalate path)
def feasible(d):
    return not (d["op"] == "write" and not d["in_repo"])

reg = CaseRegistry(constraints=[c_op, c_target, c_in_repo], feasible=feasible)

# 2 × 2 × 2 = 8 combinations; pruning leaves 6
assert reg.case_count() == 6

# Register a procedure for every surviving case
for case in reg.cases:
    reg.register(case.case_id, make_handler_for(case))
reg.verify_complete()  # raises if any case is unhandled

dispatch = Dispatch(registry=reg)
result = dispatch({"op": "read", "target": "user_file", "in_repo": True})
# DispatchResult(outcome=DISPATCHED, case_id="op=read|target=user_file|in_repo=True", output=...)

Why this is the missing primitive

Agent frameworks have intent routers, skill registries, and tool-call dispatchers. They lack the constraint-driven enumeration step. With qadiya:

  • Cases are generated, not invented. The constraint Cartesian product produces a complete, verifiable enumeration.
  • Infeasible combinations are explicitly pruned, not silently merged with feasible ones.
  • Every case must be registered or escalatedverify_complete() raises if any case is unhandled. There is no implicit "default fallback procedure."
  • Classification is deterministic — same input always maps to the same case_id.

Properties

  1. Determinism — same input → same case_id every time.
  2. Completeness verificationverify_complete() ensures no case is silently dropped.
  3. Explicit escalation — cases that should not run automatically must be marked with .escalate(). Silent fallback is forbidden.
  4. No generation outside proceduresqadiya itself produces no value. It only routes inputs to registered procedures.

Install

pip install -e .

Tests

pytest tests/ -v

15/15 pass on Python 3.10+, including a worked end-to-end example with 4 binary constraints, feasibility pruning, complete coverage verification, and round-trip dispatch.

How it composes with jabr and muqabalah

The three libraries form the four primitives of the pattern:

input
  │
  ▼
jabr.restore()      ← Restore: insert missing terms (al-jabr)
  │
  ▼
muqabalah.balance() ← Balance: cancel duplicates, fail-loud on contradictions
  │
  ▼
qadiya.classify()   ← Classify: which canonical case is this?
  │
  ▼
qadiya.dispatch()   ← Dispatch: run the registered procedure for that case
  │
  ▼
output

Each stage is reversible (where applicable), audited, and independently testable. Together they implement the discipline: every transformation an agent performs is a Restore, a Balance, or a Dispatch; every Restore and Balance preserves the original meaning recoverably; every Dispatch is the only place new value is created.

Failure modes

See FAILURES.md.

License

MIT.

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

qadiya-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

qadiya-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file qadiya-0.1.0.tar.gz.

File metadata

  • Download URL: qadiya-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for qadiya-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e68942207ab2bedcf2a54572d2705241b1515721451d9997e55f4e2697c82394
MD5 3dde7b0f779f3255d0457440278114e7
BLAKE2b-256 8aca6484e1034d3fef854c4da07ba4dccacfe70072a17030e85e9a39c3042a94

See more details on using hashes here.

Provenance

The following attestation bundles were made for qadiya-0.1.0.tar.gz:

Publisher: release.yml on Moshe-ship/qadiya

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

File details

Details for the file qadiya-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qadiya-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for qadiya-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b1c411c451a93ccb84f681bcc03cc6ec5a737c1e5b6a9622545105fef92834e
MD5 35d62b74a6ef5bb796404f7d865d1246
BLAKE2b-256 fa3a516cccf99e8dc1f1306cff0d5df836892831116fb8cf7f5c06b892e257e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for qadiya-0.1.0-py3-none-any.whl:

Publisher: release.yml on Moshe-ship/qadiya

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