pub struct FileHistoryProvider { /* private fields */ }Expand description
A HistoryProvider that persists to a JSON file on disk, loading any
existing history from path on construction and rewriting the whole file
after every successful run.
Persistence is atomic and concurrency-safe: after_run serializes the
whole append→snapshot→write sequence behind an async write_lock (shared
across clones), writes to a temporary sibling file, and atomically renames
it into place. The in-memory history is only updated after the on-disk
write succeeds, so a failed write never diverges memory from disk, and two
concurrent runs sharing cloned providers can’t lose each other’s messages
via a snapshot/overwrite race.
Implementations§
Source§impl FileHistoryProvider
impl FileHistoryProvider
Sourcepub fn new(path: impl Into<PathBuf>) -> Result<FileHistoryProvider, Error>
pub fn new(path: impl Into<PathBuf>) -> Result<FileHistoryProvider, Error>
Open (or create) a file-backed history provider at path. A missing
or empty file starts with no history; an existing file is parsed
eagerly, so a malformed file fails the constructor rather than
silently discarding history.
Sourcepub fn list_messages(&self) -> Vec<Message>
pub fn list_messages(&self) -> Vec<Message>
The stored messages, in chronological order.
Trait Implementations§
Source§impl Clone for FileHistoryProvider
impl Clone for FileHistoryProvider
Source§fn clone(&self) -> FileHistoryProvider
fn clone(&self) -> FileHistoryProvider
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ContextProvider for FileHistoryProvider
impl ContextProvider for FileHistoryProvider
Source§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,
FileHistoryProvider: '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,
FileHistoryProvider: 'async_trait,
Source§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,
FileHistoryProvider: '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,
FileHistoryProvider: 'async_trait,
Source§fn is_history_provider(&self) -> bool
fn is_history_provider(&self) -> bool
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.