feat(graph): enforce USD budget at each agent invocation with pre-flight gate #79

Closed
CoreRasurae wants to merge 1 commits from feature/76-budget-pre-flight into master

1 Commits

Author SHA1 Message Date
Developer b85bc27e0b feat(graph): enforce USD budget at each agent invocation with pre-flight gate
CI / lint (pull_request) Successful in 47s
CI / typecheck (pull_request) Successful in 52s
CI / security (pull_request) Successful in 50s
CI / quality (pull_request) Successful in 34s
CI / unit_tests (pull_request) Successful in 3m6s
CI / integration_tests (pull_request) Successful in 1m8s
CI / build (pull_request) Successful in 35s
CI / coverage (pull_request) Successful in 3m9s
CI / status-check (pull_request) Successful in 3s
Enforces max_cost_usd as a hard pre-flight gate before every node
execution in both _execute_from_node and _stream_from_node (all three
branches: terminal AGENT, intermediate AGENT, non-AGENT).

Inside _execute_tool_loop, each main-agent ainvoke round (main,
synthesis, synthesis_followup, stuck_model, stuck_model_followup) is
gated by _check_budget_before_invoke. Pruning passes are silently
skipped when the budget is exhausted via _should_skip_pruning.

current_accumulated_cost and current_max_cost_usd ContextVars carry
the per-node budget from PureLangGraph into LLMAgent, set before
node.execute() and reset in finally blocks.

BDD scenarios in features/execution_limits.feature.

ISSUES CLOSED: #76
2026-07-07 22:31:43 +00:00