pub struct GoalAccounting { /* private fields */ }Expand description
Per-turn token accounting service for the active long-horizon goal.
Wraps GoalStore with an in-memory cache of the active goal ID so that
turns without an active goal incur no database round-trips.
§Invariant (G4)
on_turn_complete is fire-and-forget. A DB write failure logs WARN and never
aborts the turn. Budget exhaustion auto-pauses the goal via a best-effort
background task.
Implementations§
Source§impl GoalAccounting
impl GoalAccounting
Sourcepub fn snapshot(&self) -> Option<GoalSnapshot>
pub fn snapshot(&self) -> Option<GoalSnapshot>
Build a lightweight snapshot of the cached active goal, if any.
Returns None when no goal is active (the goal was cleared, completed,
paused, or never created).
Sourcepub fn on_turn_complete(
&self,
turn_tokens: u64,
spawn_bg: impl FnOnce(Pin<Box<dyn Future<Output = ()> + Send + 'static>>),
)
pub fn on_turn_complete( &self, turn_tokens: u64, spawn_bg: impl FnOnce(Pin<Box<dyn Future<Output = ()> + Send + 'static>>), )
Notify the accounting service that a turn completed, consuming turn_tokens tokens.
If no active goal is cached, this is a cheap no-op (no DB access).
When a token budget is set and exceeded, the goal is auto-paused via a best-effort background task.
Background tasks are spawned via the provided closure so the caller controls how they are tracked (typically via the agent supervisor).
Auto Trait Implementations§
impl !Freeze for GoalAccounting
impl !RefUnwindSafe for GoalAccounting
impl Send for GoalAccounting
impl Sync for GoalAccounting
impl Unpin for GoalAccounting
impl UnsafeUnpin for GoalAccounting
impl !UnwindSafe for GoalAccounting
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> 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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request