Skip to main content

AgentStore

Trait AgentStore 

Source
pub trait AgentStore: Send + Sync {
    // Required methods
    fn put_if_version<'life0, 'async_trait>(
        &'life0 self,
        record: AgentRecord,
        expected: u64,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<AgentRecord>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<AgentRecord>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Where the kernel keeps the agents a person adds (spec 3.3 §5.7, §10 K7), beside the partition and driver stores, on every kernel backend, with one conformance suite (agent_store_conformance_tests!, feature conformance):

BackendTypeFeature
In-memoryInMemoryAgentStore—
SQLiteSqliteAgentStoresqlite (default)
PostgreSQLPostgresAgentStorepostgres
RedisRedisAgentStoreredis
MongoDBMongoAgentStoremongodb
FirestoreFirestoreAgentStorefirestore
Neo4jNeo4jAgentStoreneo4j

Every write is a compare-and-set on the stored version, so two replicas changing one agent change it once. A removed agent stays as a Removed tombstone, so its id is never given again (S-I14); only a suggestion nobody approved is ever deleted. Nothing outside the kernel’s agent table writes it (S-I17).

§Example

use adk_core::principal::SubjectRef;
use adk_kernel::agents::{AgentDefinition, AgentOrigin, AgentRecord, AgentRecordState, AgentStore};
use adk_kernel::stores::InMemoryAgentStore;

let store = InMemoryAgentStore::new();
let record = AgentRecord::new("finance", AgentDefinition::new("Finance", "default"),
    AgentRecordState::Active, AgentOrigin::ByHand, SubjectRef::human("alice"), chrono::Utc::now());
assert!(store.put_if_version(record.clone(), 0).await?);
assert!(!store.put_if_version(record.clone(), 0).await?, "the id is taken");
let mut paused = record.with_state(AgentRecordState::Paused);
paused.version = 2;
assert!(store.put_if_version(paused, 1).await?);
assert_eq!(store.get("finance").await?.unwrap().version, 2);
assert!(!store.delete("finance").await?, "only a suggestion is ever deleted");

Required Methods§

Source

fn put_if_version<'life0, 'async_trait>( &'life0 self, record: AgentRecord, expected: u64, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Writes record when the stored record with its id has version expected, or, with expected = 0, when there is none; false, writing nothing, otherwise.

§Errors

Returns KernelError::Store when the backend fails.

Source

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

The record id, tombstones included, or None.

§Errors

Returns KernelError::Store when the backend fails.

Source

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

Every record, tombstones included, ordered by id in byte order.

§Errors

Returns KernelError::Store when the backend fails.

Source

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

Deletes the record id when it is a suggestion nobody approved (Proposed); false, deleting nothing, for any other record or none.

§Errors

Returns KernelError::Store when the backend fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§