Skip to main content

SqliteStore

Struct SqliteStore 

Source
pub struct SqliteStore { /* private fields */ }
Available on crate feature sqlite only.
Expand description

Single-file SQLite-backed implementation of every SDK store trait.

See the module docs for resume semantics and a wiring example. Cloning shares the same single Arc<Mutex<Connection>> (not a pool), so a clone handed to the agent builder observes everything the kept handle records (and vice versa); all database calls serialize on that one mutex.

Implementations§

Source§

impl SqliteStore

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open (creating if absent) the SQLite database at path and ensure the store schema exists.

Reopening an existing file is the resume path: the schema creation is a no-op and all previously persisted rows remain available.

This constructor is synchronous — it opens the file, converts it to WAL, and applies the schema on the calling thread (waiting up to five seconds if another process holds the write lock). Call it during startup, or wrap it in spawn_blocking on a latency-sensitive async runtime.

§Errors

Returns an error if the database cannot be opened, the schema cannot be initialized, or the file carries a schema version newer than this SDK understands.

Trait Implementations§

Source§

impl Clone for SqliteStore

Source§

fn clone(&self) -> SqliteStore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl EventStore for SqliteStore

Source§

fn append<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, turn: usize, envelope: AgentEventEnvelope, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Append an event envelope for the given thread and turn. Read more
Source§

fn finish_turn<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, turn: usize, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mark the given turn as finished and flush any buffered writes. Read more
Source§

fn get_turn<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, turn: usize, ) -> Pin<Box<dyn Future<Output = Result<Option<StoredTurnEvents>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve the stored data for a single turn. Read more
Source§

fn get_turns<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<Vec<StoredTurnEvents>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve all stored turns for the given thread in ascending turn order. Read more
Source§

fn get_events<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<Vec<AgentEventEnvelope>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve all event envelopes for the given thread across every stored turn. Read more
Source§

fn event_count<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Count the stored events for thread_id without materializing them. Read more
Source§

fn get_events_since<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, offset: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<AgentEventEnvelope>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve event envelopes for thread_id from offset onward, in overall append order, skipping the earlier ones. Read more
Source§

fn clear<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Clear all events for the given thread. Read more
Source§

impl MessageStore for SqliteStore

Source§

fn append<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, message: Message, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Append a message to the thread’s history Read more
Source§

fn get_history<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<Vec<Message>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get all messages for a thread Read more
Source§

fn clear<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Clear all messages for a thread Read more
Source§

fn count<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<usize>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get the message count for a thread Read more
Source§

fn replace_history<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, messages: Vec<Message>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Replace the entire message history for a thread. Used for context compaction to replace old messages with a summary. Read more
Source§

impl StateStore for SqliteStore

Source§

fn save<'life0, 'life1, 'async_trait>( &'life0 self, state: &'life1 AgentState, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Save the current agent state Read more
Source§

fn load<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<Option<AgentState>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load the most recent state for a thread Read more
Source§

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 ThreadId, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete state for a thread Read more
Source§

impl ToolExecutionStore for SqliteStore

Source§

fn get_execution<'life0, 'life1, 'async_trait>( &'life0 self, tool_call_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<ToolExecution>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get an execution by tool_call_id. Read more
Source§

fn record_execution<'life0, 'async_trait>( &'life0 self, execution: ToolExecution, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Record a new execution (write-ahead, before calling tool). Read more
Source§

fn update_execution<'life0, 'async_trait>( &'life0 self, execution: ToolExecution, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Update an existing execution (after completion or to set operation_id). Read more
Source§

fn get_execution_by_operation_id<'life0, 'life1, 'async_trait>( &'life0 self, operation_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<ToolExecution>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get execution by operation_id (for async tool resume). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more