Expand description
What srv does as an agent’s spend on a model route reaches its caps (docs/specs/SPEC_ROUTE_AGENT_BRAKES_2026_11_10.md
section 3.3). The gateway counts each response and refuses a request once a cap is used
(model_gateway::cap); it tells this watcher of both, and the watcher, off the stream’s task:
- 50% of the agent’s cap: one non-urgent note to its leader.
- 80%: the agent’s pane gets a warning line (block meta
agent:spend_warning). - 100% (or the route’s cap): the pane carries
agent:spend_stopped, its turn in flight is interrupted, and the leader is told. The gateway has refused (or will refuse) the agent’s next request.
Each level is acted on once per agent per UTC day; the level already sent is kept with the day’s spend, so a restart does not send it again. A raised or reset cap, or the first response of a new day, takes the stop off.
Structs§
- CapChange 🔒
- The cap before and after a change.
Enums§
Constants§
- DAY_MS 🔒
- REFRESH_
EVERY 🔒 - How often every active agent’s figure is written again, so a skipped one and a new pane catch up.
- STOPPED_
META_ KEY - Block meta the pane’s stop card reads; absent when the agent is not stopped.
- TODAY_
EVERY_ 🔒MS - The least time between two writes of
TODAY_META_KEYfor an agent, unless its level or cap changed. - TODAY_
META_ KEY - Block meta the chips read: what the agent has used today and its cap (
dayis days since the epoch, UTC). - WARNING_
META_ KEY - Block meta the pane’s warning line reads, from 80% of the cap.
Functions§
- card 🔒
- change_
cap 🔒 - Sets the agent’s daily cap (
None: no cap). The alert level goes back to where the day now stands, and a stop the new cap no longer reaches is taken off the agent’s panes. The caller has checked who may do this and records it. - clear 🔒
- Takes
keyoff every open pane of the agent that carries it. - clear_
cap 🔒 - Takes the agent’s own cap away, so it has the default again, and does what
change_capdoes for the cap that gives. - drop_
stale 🔒 - forget_
alert_ 🔒off_ route - An agent off a model route has had its stop and warning taken off its panes, so the alert level the gateway’s refusals check goes back to zero with them. Left at 100, an agent stopped at its cap that returns to a route the same UTC day is refused on its first request and gets no stop card, because the stop was already counted as sent.
- handle 🔒
- inbox 🔒
- name_of 🔒
- on_
a_ 🔒key - A Claude agent linked to an Anthropic key: the gateway carries its requests. An agent of another provider that holds such a link sends its own requests to the vendor, where nothing is counted or capped.
- on_
a_ 🔒route - A cap, and a day of spend, belong to an agent on a model route or an API key: a login agent has plan limits instead.
- on_
settled 🔒 - place_
of 🔒 - “OpenRouter (DeepSeek V4.1 Flash)”: where the agent’s spend goes.
- publish_
today 🔒 - Writes the figure the chips show to the agent’s open panes: at most every
TODAY_EVERY_MSunlessforce. - refresh_
chips 🔒 - Brings every agent’s panes up to date once a minute: the figure of an agent on a route that has spent today, and the
removal of what no longer holds (see
stale_keys). - refused 🔒
- The gateway refused
grant’s agent a request becausehitis used. - reset_
today 🔒 - Zeroes the agent’s spend for today and takes its stop and warning off. Returns the dollars that were counted.
- set_
meta 🔒 - settled 🔒
- A response of
grant’s agent has been counted. - spends_
through_ 🔒gateway - Whether the agent’s requests go through the gateway and are counted there: it is on a model route, or on an API key.
- stale_
keys 🔒 - The spend keys on a pane’s
metathat no longer hold. An agent that is not on a model route has no cap and no day of spend to show, so it carries none of them; on a route, a stop or warning written on an earlier UTC day belongs to a day the gateway has since reset, and nothing else would take it off an agent that stays idle through midnight. - start 🔒
- Starts the watcher.
- stop 🔒
- view 🔒
- What
Agents listshows for an agent on a model route: what it has used today and its cap. For an agent on the DeepSeek Harness, which uses its own key and reports no spend, that nothing is measured.Nonefor any other. - warn 🔒
- write_
cap 🔒