Skip to main content

Module budget

Module budget 

Source
Expand description

Per-response character budget (ADR-033) — a port of src/asdecided/mcp/budget.py (ORACLE-NEXT revision, which adds the items rule). Shared by the CLI retrieve surface (commands::cmd_retrieve) and the decided-mcp server.

The budget unit is CHARACTERS (Python len of the serialized string — Unicode code points, not bytes) of the payload serialized as json.dumps(payload, ensure_ascii=False) with DEFAULT separators — i.e. ", " / ": " WITH spaces (pyjson::dumps_compact). The docstring in the oracle says “no spaces”; the code does not pass separators, so the wire truth is with spaces (PORT-CONTRACT.d/10 §2) — port the code, not the comment.

Truncation is deterministic and whole-item wherever a repeated collection is involved. Every successful payload is either reduced to the configured character budget or replaced with a small explicit budget error; an over-budget success is never returned.

Constants§

BUDGET_ERROR
BUDGET_ERROR_HINT
DEFAULT_BUDGET
HINT_CONTENT
HINT_RELATED
HINT_RETRIEVE
HINT_SEARCH
HINT_SUMMARY
MARKER_HINT
MARKER_OMITTED
MARKER_TRUNCATED
MIN_BUDGET
Smallest supported configured budget. This leaves room for a structured budget error when fixed response fields alone cannot fit.

Functions§

char_len
len(text) in Python — code points, not bytes.
py_slice_to
text[:stop] with Python slice semantics (negative stop trims the tail; the truncators only pass non-negative stops, but the retrieve excerpt share can go negative).
serialize
budget.serialize(payload, budget).
valid_configured_budget
validate_call_budget