pub struct ModelContext<'a> {Show 17 fields
pub author: &'a MessageAuthor,
pub model: &'a ModelRouter,
pub provider: &'a str,
pub context_provider: &'a str,
pub session_id: &'a str,
pub cancellation: Option<&'a ModelCancellation>,
pub session_context: &'a SessionContext,
pub metadata: &'a BTreeMap<String, Value>,
pub turn_id: &'a str,
pub model_step: usize,
pub context_window: i64,
pub token_estimate: TokenEstimate,
pub instructions: &'a str,
pub last_usage: Option<&'a TokenUsage>,
pub tools: &'a Catalog,
pub events: &'a mut Vec<EventMsg>,
pub usage: &'a mut Vec<(String, TokenUsage)>,
/* private fields */
}Expand description
Mutable state exposed immediately before a model request.
Fields§
Trusted provenance of the message that initiated the active turn.
model: &'a ModelRouterThe model.
provider: &'a strThe provider.
context_provider: &'a strThe route whose accepted output last contributed to durable context.
session_id: &'a strThe session identifier.
cancellation: Option<&'a ModelCancellation>Cause recorded before model preparation is cancelled.
session_context: &'a SessionContextThe session context.
metadata: &'a BTreeMap<String, Value>The metadata.
turn_id: &'a strThe turn identifier.
model_step: usizeThe model step.
context_window: i64The context window.
token_estimate: TokenEstimateShared byte-based estimate used by context policies.
instructions: &'a strThe instructions.
last_usage: Option<&'a TokenUsage>The last usage.
tools: &'a CatalogThe tools.
events: &'a mut Vec<EventMsg>The events.
usage: &'a mut Vec<(String, TokenUsage)>Completed preparation calls, with their actual routes and usage.
Implementations§
Source§impl ModelContext<'_>
impl ModelContext<'_>
Sourcepub fn record_usage(&mut self, route: &str, usage: TokenUsage)
pub fn record_usage(&mut self, route: &str, usage: TokenUsage)
Accounts for a preparation call on its actual model route.
Sourcepub fn disable_hosted_tools(&mut self)
pub fn disable_hosted_tools(&mut self)
Prevents provider-hosted tools for this model step.
Sourcepub fn input(&self) -> ModelInput<'_>
pub fn input(&self) -> ModelInput<'_>
Returns durable provider-neutral model context.
Sourcepub fn rewrite_input(
&mut self,
reason: ContextRewriteReason,
input: impl IntoIterator<Item = impl Into<Arc<Value>>>,
) -> Result<()>
pub fn rewrite_input( &mut self, reason: ContextRewriteReason, input: impl IntoIterator<Item = impl Into<Arc<Value>>>, ) -> Result<()>
Replaces active model context and advances its rewrite epoch once per boundary.
§Errors
Returns an error if validation or an operation required by this function fails.
Sourcepub fn append_model_input(&mut self, item: Value)
pub fn append_model_input(&mut self, item: Value)
Appends durable provider context without adding synthetic replay history.
Sourcepub fn push_input(&mut self, item: Value) -> Result<MessageTarget>
pub fn push_input(&mut self, item: Value) -> Result<MessageTarget>
Appends durable input to model context and its transcript journal.
§Errors
Returns an error if validation or an operation required by this function fails.
Sourcepub fn estimated_input_tokens(&self) -> i64
pub fn estimated_input_tokens(&self) -> i64
Estimates visible history, instructions, and tool schemas using the session policy.