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.
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 escalated —
verify_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
- Determinism — same input → same case_id every time.
- Completeness verification —
verify_complete()ensures no case is silently dropped. - Explicit escalation — cases that should not run automatically must be marked with
.escalate(). Silent fallback is forbidden. - No generation outside procedures —
qadiyaitself 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e68942207ab2bedcf2a54572d2705241b1515721451d9997e55f4e2697c82394
|
|
| MD5 |
3dde7b0f779f3255d0457440278114e7
|
|
| BLAKE2b-256 |
8aca6484e1034d3fef854c4da07ba4dccacfe70072a17030e85e9a39c3042a94
|
Provenance
The following attestation bundles were made for qadiya-0.1.0.tar.gz:
Publisher:
release.yml on Moshe-ship/qadiya
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qadiya-0.1.0.tar.gz -
Subject digest:
e68942207ab2bedcf2a54572d2705241b1515721451d9997e55f4e2697c82394 - Sigstore transparency entry: 1688006790
- Sigstore integration time:
-
Permalink:
Moshe-ship/qadiya@5a9c64d01416db483f7201bfe32c830be232311e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Moshe-ship
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5a9c64d01416db483f7201bfe32c830be232311e -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b1c411c451a93ccb84f681bcc03cc6ec5a737c1e5b6a9622545105fef92834e
|
|
| MD5 |
35d62b74a6ef5bb796404f7d865d1246
|
|
| BLAKE2b-256 |
fa3a516cccf99e8dc1f1306cff0d5df836892831116fb8cf7f5c06b892e257e1
|
Provenance
The following attestation bundles were made for qadiya-0.1.0-py3-none-any.whl:
Publisher:
release.yml on Moshe-ship/qadiya
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qadiya-0.1.0-py3-none-any.whl -
Subject digest:
4b1c411c451a93ccb84f681bcc03cc6ec5a737c1e5b6a9622545105fef92834e - Sigstore transparency entry: 1688006838
- Sigstore integration time:
-
Permalink:
Moshe-ship/qadiya@5a9c64d01416db483f7201bfe32c830be232311e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Moshe-ship
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5a9c64d01416db483f7201bfe32c830be232311e -
Trigger Event:
push
-
Statement type: