yaab.limits¶
Usage limits and run control.
yaab.limits ¶
Usage limits and run cancellation — bounded, interruptible runs.
Two small, composable controls the ecosystem repeatedly asks for:
- :class:
UsageLimits— hard caps on requests, input/output/total tokens, tool calls (overall and per-tool), and wall-clock seconds. Checked by the Runner between steps and before each tool call; breaching one raises :class:~yaab.exceptions.UsageLimitExceeded. - :class:
CancellationToken— a cooperative stop signal. Call :meth:CancellationToken.cancel(from a signal handler, a timeout, another task, an API endpoint) and the Runner stops at the next checkpoint with :class:~yaab.exceptions.RunCancelled. Atimeouton the run wires an automatic deadline to the same mechanism.
Both are optional; with neither set, runs behave exactly as before.
UsageLimits ¶
Declarative caps enforced across an agent run.
Any limit left None is unbounded. per_tool_calls maps a tool name to
its own maximum call count (e.g. {"charge": 1}).
check_usage ¶
check_usage(usage: Usage) -> None
Raise if the accumulated token/request usage breaches a cap.
check_wall_clock ¶
Raise if the run has exceeded its wall-clock budget.
started_at is a time.monotonic() timestamp from the run's start.
check_tool_call ¶
Raise if invoking tool_name would breach an overall/per-tool cap.
counts is the running tally of calls per tool including this one.
CancellationToken ¶
A cooperative cancellation signal shared with a run.
The Runner checks :meth:raise_if_cancelled between supersteps and before
each tool call. A token can carry a wall-clock deadline so timeouts and
explicit cancels flow through one path.