Skip to main content

ModelContext

Struct ModelContext 

Source
pub struct ModelContext { /* private fields */ }
Expand description

Ephemeral, capability-limited context for exactly one model attempt.

The context intentionally is not serializable. It carries stable execution identity, a finite remaining run-budget view, a wall-clock deadline for durable evidence, the equivalent monotonic deadline for timeout enforcement, and a cooperative cancellation signal. It contains no prompt, tool argument, bearer token, credential value, provider SDK client, or mutable property bag.

Model adapters must treat cancellation and deadline enforcement as separate from provider outcome certainty. Cancellation wins when both conditions are observed together, but neither condition proves that in-flight provider work did not complete or incur usage.

Implementations§

Source§

impl ModelContext

Source

pub fn new( tenant_id: TenantId, run_id: RunId, thread_id: ThreadId, attempt_id: AttemptId, budget: BudgetRemaining, observed_at: Timestamp, observed_instant: Instant, cancellation: CancellationSignal, ) -> Result<Self, ModelContextError>

Constructs an ephemeral attempt context from one paired wall/monotonic observation.

observed_at and observed_instant must represent the same runtime observation. The constructor converts the durable budget deadline into a monotonic deadline so wall-clock adjustments cannot lengthen an active provider call.

§Errors

Returns ModelContextError when the durable deadline is already reached or the platform cannot represent the corresponding monotonic deadline.

Source

pub const fn tenant_id(&self) -> &TenantId

Returns the tenant boundary for storage, policy, and audit correlation.

Source

pub const fn run_id(&self) -> RunId

Returns the durable enclosing run identifier.

Source

pub const fn thread_id(&self) -> ThreadId

Returns the durable conversation thread identifier.

Source

pub const fn attempt_id(&self) -> AttemptId

Returns the exact attempt identifier required on every response and event.

Source

pub const fn budget(&self) -> &BudgetRemaining

Returns the finite remaining run capacity captured for this attempt.

Source

pub const fn observed_at(&self) -> Timestamp

Returns the wall-clock observation paired with the monotonic clock.

Source

pub const fn deadline(&self) -> Timestamp

Returns the durable absolute wall-clock deadline.

Source

pub const fn deadline_instant(&self) -> Instant

Returns the equivalent process-local monotonic deadline.

Source

pub const fn cancellation(&self) -> &CancellationSignal

Returns the shared cooperative cancellation signal.

Source

pub fn remaining_time_at(&self, observed_instant: Instant) -> Option<Duration>

Returns remaining monotonic time, or None at and after the deadline.

Source

pub fn stop_reason_at( &self, observed_instant: Instant, ) -> Option<ModelStopReason>

Returns the deterministic stop reason observed at one monotonic instant.

Explicit cancellation wins if cancellation and deadline are both observable. This precedence matches the run state-machine contract for work that has not committed a result.

Trait Implementations§

Source§

impl Clone for ModelContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelContext

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.