Agenda token accounting currently hooks call_llm / _call_provider, and agenda_scope(agenda_id, operation) is only entered on the discovery paths (signal harvest, tier1/tier2 discovery, selection), so ledger rows and token_spent cover the discovery stage only. LLM calls made by execution workers dispatched after agenda_orchestrator hands a selection over to the auto_research path run outside any agenda scope and are not attributed, which undercounts an agenda's real spend once execution starts.
Goal: extend agenda_scope into the execution path so that worker-side LLM calls write agenda_token_ledger rows and bump token_spent exactly like discovery calls do. Budget enforcement should reuse the existing semantics unchanged: check_budget before each provider request, flip to paused_budget on exhaustion, and recovery via raising the budget or the resume endpoint as today. Budgets of 0/NULL/negative stay accounting-only on this path as well.
Agenda token accounting currently hooks
call_llm/_call_provider, andagenda_scope(agenda_id, operation)is only entered on the discovery paths (signal harvest, tier1/tier2 discovery, selection), so ledger rows andtoken_spentcover the discovery stage only. LLM calls made by execution workers dispatched afteragenda_orchestratorhands a selection over to the auto_research path run outside any agenda scope and are not attributed, which undercounts an agenda's real spend once execution starts.Goal: extend
agenda_scopeinto the execution path so that worker-side LLM calls writeagenda_token_ledgerrows and bumptoken_spentexactly like discovery calls do. Budget enforcement should reuse the existing semantics unchanged:check_budgetbefore each provider request, flip topaused_budgeton exhaustion, and recovery via raising the budget or the resume endpoint as today. Budgets of 0/NULL/negative stay accounting-only on this path as well.