pub struct ConversationContext {
pub config: ContextConfig,
pub messages: VecDeque<Message>,
pub total_tokens: usize,
}Expand description
Multi-turn conversation context with automatic token budget enforcement.
Fields§
§config: ContextConfigConfiguration (strategy, budgets, system prompt).
messages: VecDeque<Message>Ordered message history (front = oldest).
total_tokens: usizeRunning total of estimated tokens across all messages.
Implementations§
Source§impl ConversationContext
impl ConversationContext
Sourcepub fn new(config: ContextConfig) -> Self
pub fn new(config: ContextConfig) -> Self
Create a new context. If the config has a system_prompt, it is
added as the first message immediately.
Sourcepub fn add_message(&mut self, role: Role, content: &str)
pub fn add_message(&mut self, role: Role, content: &str)
Append a new message and enforce the token budget.
Sourcepub fn enforce_budget(&mut self)
pub fn enforce_budget(&mut self)
Apply the configured TruncationStrategy if the effective budget is
exceeded.
Sourcepub fn messages_for_api(&self) -> Vec<&Message>
pub fn messages_for_api(&self) -> Vec<&Message>
Return the messages that should be sent to the LLM API.
Sourcepub fn token_utilization(&self) -> f64
pub fn token_utilization(&self) -> f64
Token utilisation ratio in [0.0, 1.0].
Sourcepub fn summary(&self) -> ContextSummary
pub fn summary(&self) -> ContextSummary
Return a lightweight summary snapshot.
Auto Trait Implementations§
impl Freeze for ConversationContext
impl RefUnwindSafe for ConversationContext
impl Send for ConversationContext
impl Sync for ConversationContext
impl Unpin for ConversationContext
impl UnsafeUnpin for ConversationContext
impl UnwindSafe for ConversationContext
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§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>
Wrap the input message
T in a tonic::Request