decision-cascade

Local engine for typed, calibrated decisions for AI agents.

View the Project on GitHub slavabars/decision-cascade

decision-cascade for AI agents

A short guide for agents and for people building agents: how to wire the engine in, what it does, and when to call it instead of generating text.

What it is

decision-cascade is a local engine for typed decisions. You pass a state (a string or JSON) and questions, and get probabilities back:

The model generates nothing: the answer is a calibrated probability you can threshold and log. The expensive LLM is reserved for cases that genuinely need generation.

When to call it:

When not to call it: free-form text, summarization, code generation — that is not the engine’s job.

Install

pip install decision-cascade

No model, no GPU, no keys: the server starts on a hash encoder. Trained heads come from Hugging Face packs (see docs/en/huggingface.md).

The package installs the library, the server and the training stack (torch, transformers, trl, datasets, pandas, scikit-learn, matplotlib): the same install covers local inference and head fine-tuning. A GPU is optional, but torch is the price of local execution.

MCP: one tool for any client

decision mcp --stdio          # the client starts the process
decision mcp --http           # opt-in, loopback only, port 8765

Client configuration:

{"command": "decision", "args": ["mcp", "--stdio"]}

Tools: capabilities, decide, feedback, calibrate. Full description, limits and the security model live in docs/en/mcp.md.

Minimal decide call:

{
  "state": "the customer has failed to pay for three days",
  "questions": {
    "escalate": {"type": "noul", "instructions": "Does this need a human?"},
    "team": {
      "type": "choice",
      "instructions": "Which team owns it?",
      "options": ["billing", "integration", "support"]
    }
  }
}

decide also accepts media: images/videos (paths inside DECISION_MEDIA_ROOT or data URIs) and media_kwargs (max_frames). Video is decoded by ffmpeg; without it the server advertises images only.

The response carries decisions with distributions, a trained flag and usage (what was saved versus the external model). state is an opaque string: the server does not parse it. If the state is JSON, serialize it canonically (sort_keys=True, compact separators) or semantically identical requests produce different features.

HTTP API and SDK

python -m uvicorn api.server.main:app --host 127.0.0.1 --port 8000
from api.sdk.client import DecisionClient

with DecisionClient(base_url="http://127.0.0.1:8000") as client:
    result = client.decisions(
        "The customer asks for a refund on a broken plan",
        {"refund": {"type": "noul", "instructions": "Refund the money?"}},
    )
print(result["decisions"]["refund"]["noul"]["p"])

Endpoints: POST /decisions, POST /decisions/batch, POST /v1/systemone, POST /v1/feedback, GET /v1/questions, GET /v1/stats, GET /health, GET /ready. The contract and schema_version are stable within 1.x (docs/en/stability.md).

Cascade: cheap step first, expensive only when unsure

DECISION_BACKEND=cascade escalates low-confidence decisions to an external service; the client-side variant is api/sdk/agent.py with route_ticket and --fallback. This is the main saving: a calibrated probability tells you when the big model is actually worth paying for.

Check that it is alive

curl -s http://127.0.0.1:8000/health
curl -s http://127.0.0.1:8000/info

/ready returns 503 until the encoder and heads are ready. trained=false in a response means there are no weights for this schema and the head answers randomly; connect packs for production.

Limitations