pub struct TurnBudget {
pub max_provider_rounds: Option<u32>,
pub max_tool_calls: Option<u32>,
pub max_elapsed: Option<Duration>,
pub max_accumulated_tool_result_bytes: Option<usize>,
pub max_context_tokens: Option<u64>,
pub max_cost_usd: Option<f64>,
pub max_total_tokens: Option<u64>,
pub max_round_renewals: u32,
}Expand description
Per-turn limits (spec §8.1).
Fields§
§max_provider_rounds: Option<u32>Provider rounds per turn (per renewal). None means no limit — the
foreground default. Autonomous (24) and worker (64, x3 with renewals)
turns are bounded by default. Set with
turn_budget.<role>.max_provider_rounds.
max_tool_calls: Option<u32>Tool calls per turn. None means no limit — the foreground and worker
default; autonomous turns default to 96. Set with
turn_budget.<role>.max_tool_calls.
max_elapsed: Option<Duration>Wall-clock limit for one turn. None (the default for every role)
means no limit: a turn that is still making progress is never cut off
for taking long. Opt in with turn_budget.<role>.max_elapsed_secs or
/budget time.
max_accumulated_tool_result_bytes: Option<usize>Accumulated tool-result bytes per turn. None means no limit — the
foreground and worker default; autonomous turns default to 8 MiB. Set
with turn_budget.<role>.max_accumulated_tool_result_bytes.
max_context_tokens: Option<u64>§max_cost_usd: Option<f64>§max_total_tokens: Option<u64>Uncached input + output tokens summed over the turn’s requests (cache
reads and writes are priced into max_cost_usd, not counted here).
No role sets it by default; the watcher agent uses it to carry its
remaining max_session_tokens into the turn.
max_round_renewals: u32Bounded auto-renewals of the provider-round allowance (spec §8.1).
On exhaustion the stream loop may reset the round counter this many
times so a long, legitimate task continues instead of hard-failing.
Round renewal never resets wall-clock (durable context successors do); a
value of 0 means no graceful continuation (immediate hard stop). Only
matters when max_provider_rounds is configured.
Implementations§
Source§impl TurnBudget
impl TurnBudget
Sourcepub fn for_role(role: TurnRole) -> TurnBudget
pub fn for_role(role: TurnRole) -> TurnBudget
Compiled per-role defaults. No role has a wall-clock limit unless
configured. Foreground (a human is watching and can interrupt) has no
round, tool-call or tool-result-byte limit either. Unattended roles
stay bounded: autonomous (watcher) and event-started turns hard-stop
at 24 rounds / 96 tool calls / 8 MiB (nobody is watching), and a
worker stops after 64 rounds x (1 + 2 renewals) = 192 rounds per run
(a timeout: 0 worker has no other bound).
Sourcepub fn tighter(&self, other: &TurnBudget) -> TurnBudget
pub fn tighter(&self, other: &TurnBudget) -> TurnBudget
The stricter of two budgets, dimension by dimension (None = no
limit loses to any limit). Used to narrow a role budget to what a
session has left, or to combine a session’s budget with the event
role’s.
Sourcepub fn for_event_turn(&self, config: &TurnBudgetsConfig) -> TurnBudget
pub fn for_event_turn(&self, config: &TurnBudgetsConfig) -> TurnBudget
The budget for a turn the session starts by itself because events
arrived: this (session) budget narrowed by the event role’s
(turn_budget.event.*), so a /budget the user set still applies.
Sourcepub fn has_time_limit(&self) -> bool
pub fn has_time_limit(&self) -> bool
Whether a wall-clock limit can end (or checkpoint) a turn. A zero limit counts as exhausted at once and never as a time checkpoint.
Sourcepub fn max_elapsed_secs(&self) -> Option<u64>
pub fn max_elapsed_secs(&self) -> Option<u64>
The wall-clock limit in seconds, for diagnostics (None = no limit).
Sourcepub fn from_config(role: TurnRole, config: &TurnBudgetsConfig) -> TurnBudget
pub fn from_config(role: TurnRole, config: &TurnBudgetsConfig) -> TurnBudget
Role defaults overlaid with the typed config. Unset fields keep the
compiled defaults; unlimited clears a round, tool-call or
tool-result-byte limit (0 means none allowed, deprecated); 0
seconds means no wall-clock limit.
Trait Implementations§
Source§impl Clone for TurnBudget
impl Clone for TurnBudget
Source§fn clone(&self) -> TurnBudget
fn clone(&self) -> TurnBudget
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TurnBudget
impl Debug for TurnBudget
Source§impl PartialEq for TurnBudget
impl PartialEq for TurnBudget
impl StructuralPartialEq for TurnBudget
Auto Trait Implementations§
impl Freeze for TurnBudget
impl RefUnwindSafe for TurnBudget
impl Send for TurnBudget
impl Sync for TurnBudget
impl Unpin for TurnBudget
impl UnsafeUnpin for TurnBudget
impl UnwindSafe for TurnBudget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more