Expand description
Watcher agent (synaps agent) session accounting and turn driving.
The agent’s [limits] (session tokens, cost, time, tool calls, and the
daily cost cap) are enforced by the ENGINE inside each turn: before every
turn the role budget is narrowed to what the session has left
(SessionAllowance::turn_budget), so the engine stops the turn at a
round boundary with a valid history and a typed BudgetExceeded. Calls
past the tool-call allowance get the engine’s synthetic refusal result,
not a cancel; in-budget calls of the same parallel batch still run.
drive_turn meters one turn’s stream into SessionTotals: usage is
priced with the runtime’s pricing table (cache reads and writes
included), tool calls are counted when they produce a result (a refused
call is not counted), and a clean exit is recorded only when the
watcher_exit tool reports that the handoff was saved.
Structs§
- Session
Allowance - A session’s limits plus what was already spent today before it started.
- Session
Totals - What one watcher session has used so far.
- Turn
Report - How one watcher turn ended.
Enums§
- Session
Limit - A watcher session limit.
Constants§
- HANDOFF_
PROMPT - The prompt for the turn that asks for a handoff after a session limit.
- HANDOFF_
TIMEOUT - How long the post-limit handoff turn may run.
- TURN_
DEADLINE_ GRACE - Extra time past the session time limit before a turn still running is
cancelled. The engine stops a turn at the next provider call once the
session time is used up; this deadline only catches a turn stuck in a
long tool round (a slow command, a
timeout: 0subagent).
Functions§
- drive_
turn - Drain one turn’s stream, metering it into
totals.modelprices usage events that do not name their model.on_eventsees every event after it was metered (for logging). - push_
user_ prompt - Append a user prompt to
messageswithout creating two consecutive user messages: a turn that ended on its tool results (a budget stop) already ends with a user message, which then gets the prompt as a text block. - run_
handoff_ turn - After a session limit: ask for the handoff in one more turn, bounded by
HANDOFF_TIMEOUTand the role’s per-turn limits, and metered intototalslike every other turn (it is real spend). - run_
session_ turn - One turn of a watcher session, as
synaps agentruns it: the role budget narrowed to what the session has left. - run_
turn - Run one turn of
runtimeovermessagesunderbudget, metered intototals;messagesbecomes the turn’s final history. A signal cancels the turn; so doesdeadline(the handoff turn’s backstop). - usage_
cost - Price one request’s usage with the runtime’s pricing table (the same one the engine’s turn cost budget uses), cache reads and writes included.
- watch_
turn - Watches one streaming turn: cancels it on SIGINT/SIGTERM, or once
deadlinepasses, as a host stop (canceled tool results say so, not “by user”). Exits when the turn ends. Session limits are otherwise enforced by the engine inside the turn.