pub struct Context { /* private fields */ }Implementations§
Source§impl Context
impl Context
pub fn new(messages: Vec<ChatMessage>, tools: Vec<ToolDefinition>) -> Self
pub fn prompt_cache_key(&self) -> Option<&str>
pub fn set_prompt_cache_key(&mut self, key: Option<String>)
pub fn reasoning_effort(&self) -> Option<ReasoningEffort>
pub fn set_reasoning_effort(&mut self, effort: Option<ReasoningEffort>)
pub fn add_message(&mut self, message: ChatMessage)
pub fn set_tools(&mut self, tools: Vec<ToolDefinition>)
pub fn messages(&self) -> &Vec<ChatMessage>
pub fn tools(&self) -> &Vec<ToolDefinition>
Sourcepub fn message_count(&self) -> usize
pub fn message_count(&self) -> usize
Returns the number of messages in the context
Sourcepub fn estimated_token_count(&self) -> u32
pub fn estimated_token_count(&self) -> u32
Estimate total token count using the ~4 bytes/token heuristic. Includes messages and tool definitions. Used for pre-flight overflow detection.
Sourcepub fn push_assistant_turn(
&mut self,
content: &str,
reasoning: AssistantReasoning,
completed_tools: Vec<Result<ToolCallResult, ToolCallError>>,
)
pub fn push_assistant_turn( &mut self, content: &str, reasoning: AssistantReasoning, completed_tools: Vec<Result<ToolCallResult, ToolCallError>>, )
Build an assistant turn and its tool call results and append them to messages.
Sourcepub fn filter_encrypted_reasoning(&self, model: &LlmModel) -> Self
pub fn filter_encrypted_reasoning(&self, model: &LlmModel) -> Self
Return a copy with encrypted reasoning filtered for the given model. Encrypted content is kept only when its source model matches.
Sourcepub fn clear_conversation(&mut self)
pub fn clear_conversation(&mut self)
Clear all non-system messages, retaining only system prompts.
Sourcepub fn messages_for_summary(&self) -> Vec<&ChatMessage>
pub fn messages_for_summary(&self) -> Vec<&ChatMessage>
Get all non-system messages for summarization
Sourcepub fn with_compacted_summary(&self, summary: &str) -> Context
pub fn with_compacted_summary(&self, summary: &str) -> Context
Create a new context with all messages replaced by a summary. Preserves the system prompt and tools.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Context
impl<'de> Deserialize<'de> for Context
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.