pub trait ContextProvider: Send + Sync {
// Required method
fn before_run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut SessionContext,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
// Provided methods
fn after_run<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_request_messages: &'life1 [Message],
_response_messages: &'life2 [Message],
_error: Option<&'life3 Error>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn is_history_provider(&self) -> bool { ... }
}Expand description
A source of per-invocation context (memory, RAG, etc.). Upstream renamed invoking/invoked -> before_run/after_run and REMOVED thread_created. before_run mutates the SessionContext in place instead of returning a Context.
Required Methods§
Sourcefn before_run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut SessionContext,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn before_run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 mut SessionContext,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Called before the model is invoked; mutate ctx to inject instructions, messages, and/or tools. Read ctx.input_messages / ctx.session_id.
Provided Methods§
Sourcefn after_run<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_request_messages: &'life1 [Message],
_response_messages: &'life2 [Message],
_error: Option<&'life3 Error>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn after_run<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_request_messages: &'life1 [Message],
_response_messages: &'life2 [Message],
_error: Option<&'life3 Error>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Called after an invocation completes, on BOTH success and failure. On success, error is None and response_messages holds the output. On failure, error is Some and response_messages is empty.
Sourcefn is_history_provider(&self) -> bool
fn is_history_provider(&self) -> bool
Whether this provider manages conversation history (a
HistoryProvider). Agent
and WorkflowAgent use this to
detect an already-attached history provider among a session’s
context_providers and avoid auto-attaching a redundant
InMemoryHistoryProvider.
Defaults to false; history providers override it to true.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".