Expand description
PlanBudget — cumulative complexity-class + operation-count
accumulator for chained solves.
ADR-001 roadmap item #4’s phase-2 MCP gate refuses one solve
that exceeds the caller’s max_complexity_class. That’s necessary
but not sufficient: an agent that issues 10 000 SubLinear solves in
a tight loop can still blow a real-world J/decision budget without
ever tripping a single per-call gate.
This module closes the gap with a budget accumulator that lives
across the chain. Callers try_consume(class) once per solve;
the budget refuses the call if either:
classexceedsmax_class(per-call class gate, same semantics as the existing MCPenforceComplexityBudget), or- the remaining operation count has dropped to zero.
The “operation count” abstraction is number of solves, not number of inner-loop iterations — the unit a budget-aware agent actually reasons about. A 100-event reflex loop with a 100-op budget runs to completion; a 10 000-event one trips the budget at iteration 100 and short-circuits gracefully.
§Composition
Pair this with the per-call class gate that’s already wired into
the MCP solve handlers. The MCP layer enforces budget per call;
PlanBudget enforces budget per plan.
§Why not Rc<RefCell<...>>?
The accumulator is intentionally &mut self — borrow-checker
catches accidental shared mutation. Callers running planners on
multiple threads should Arc<Mutex<PlanBudget>> or partition the
budget per worker. The single-threaded planning case (the
common one) stays zero-cost.
Structs§
- Plan
Budget - Cumulative budget for a chain of solves.
Enums§
- Budget
Exhausted - Reason a
try_consumewas rejected.