Skip to main content

GraphMemory

Struct GraphMemory 

Source
pub struct GraphMemory { /* private fields */ }
Expand description

High-level graph memory API - the main entry point for AINL memory.

Wraps a GraphStore implementation with a simplified 5-method API.

Implementations§

Source§

impl GraphMemory

Source

pub fn upsert_anchored_summary( &self, agent_id: &str, summary_payload: &str, ) -> Result<Uuid, String>

Upsert a serialized anchored summary for agent_id.

summary_payload should be a JSON-serialized AnchoredSummary from the ainl-context-compiler crate. Returns the stable node id (same value for repeated calls with the same agent_id).

Source

pub fn fetch_anchored_summary( &self, agent_id: &str, ) -> Result<Option<String>, String>

Fetch the most recent anchored-summary payload for agent_id, if any.

Returns the raw JSON string (caller deserializes into AnchoredSummary).

Source§

impl GraphMemory

Source

pub fn new(db_path: &Path) -> Result<Self, String>

Create a new graph memory at the given database path.

This will create the database file if it doesn’t exist, and ensure the AINL graph schema is initialized.

Source

pub fn from_connection(conn: Connection) -> Result<Self, String>

Create from an existing SQLite connection (for integration with existing memory pools)

Source

pub fn from_sqlite_store(store: SqliteGraphStore) -> Self

Wrap an already-open SqliteGraphStore (for hosts that manage connections externally).

Source

pub fn write_episode( &self, tool_calls: Vec<String>, delegation_to: Option<String>, trace_event: Option<Value>, ) -> Result<Uuid, String>

Write an episode node (what happened during an agent turn).

§Arguments
  • tool_calls - List of tools executed during this turn
  • delegation_to - Agent ID this turn delegated to (if any)
  • trace_event - Optional orchestration trace event (serialized JSON)
§Returns

The ID of the created episode node

Source

pub fn write_fact( &self, fact: String, confidence: f32, source_turn_id: Uuid, ) -> Result<Uuid, String>

Write a semantic fact (learned information with confidence).

§Arguments
  • fact - The fact in natural language
  • confidence - Confidence score (0.0-1.0)
  • source_turn_id - Turn ID that generated this fact
§Returns

The ID of the created semantic node

Source

pub fn store_pattern( &self, pattern_name: String, compiled_graph: Vec<u8>, ) -> Result<Uuid, String>

Store a procedural pattern (compiled workflow).

§Arguments
  • pattern_name - Name/identifier for the pattern
  • compiled_graph - Binary representation of the compiled graph
§Returns

The ID of the created procedural node

Source

pub fn write_procedural( &self, pattern_name: &str, tool_sequence: Vec<String>, confidence: f32, ) -> Result<Uuid, String>

Store a procedural pattern derived from a live tool sequence (heuristic extraction).

This path treats the row as curated (prompt-eligible) so a single write is visible in suggested-procedure style recall; use Self::write_node with a hand-built node if you need candidate-only semantics.

Source

pub fn write_procedure_artifact( &self, artifact: &ProcedureArtifact, ) -> Result<Uuid, String>

Store a portable procedure artifact as a procedural graph node.

The canonical JSON artifact is stored in compiled_graph so older graph consumers can ignore it safely, while new consumers can recall and deserialize validated procedure artifacts without adding a separate table.

Source

pub fn write_procedure_artifact_for_agent( &self, agent_id: &str, artifact: &ProcedureArtifact, ) -> Result<Uuid, String>

Store a portable procedure artifact for a specific agent.

Source

pub fn upsert_procedure_artifact_for_agent( &self, agent_id: &str, artifact: &ProcedureArtifact, ) -> Result<Uuid, String>

Update an existing procedural node for artifact.id, or write a new one if no node exists.

Source

pub fn recall_procedure_artifacts( &self, ) -> Result<Vec<ProcedureArtifact>, String>

Recall portable procedure artifacts previously stored with Self::write_procedure_artifact.

Source

pub fn search_procedure_artifacts_for_agent( &self, agent_id: &str, intent: &str, available_tools: &[String], limit: usize, ) -> Result<Vec<ProcedureArtifact>, String>

Search validated/promoted procedure artifacts by intent text and required tool overlap.

Source

pub fn record_procedure_reuse_outcome_for_agent( &self, agent_id: &str, outcome: &ProcedureReuseOutcome, ) -> Result<Uuid, String>

Update artifact lifecycle and fitness after an attempted reuse.

Source

pub fn write_edge( &self, source: Uuid, target: Uuid, rel: &str, ) -> Result<(), String>

Write a graph edge between nodes (e.g. episode timeline follows).

Source

pub fn recall_recent( &self, seconds_ago: i64, ) -> Result<Vec<AinlMemoryNode>, String>

Recall recent episodes (within the last N seconds).

§Arguments
  • seconds_ago - Only return episodes from the last N seconds
§Returns

Vector of episode nodes, most recent first

Source

pub fn recall_by_type( &self, kind: AinlNodeKind, seconds_ago: i64, ) -> Result<Vec<AinlMemoryNode>, String>

Recall nodes of a specific kind written in the last seconds_ago seconds.

Source

pub fn find_procedural_by_tool_sequence( &self, agent_id: &str, tool_sequence: &[String], ) -> Result<Option<AinlMemoryNode>, String>

Find a recent procedural (tool-sequence) row for this agent whose tool_sequence matches tool_sequence (per-element trim). Returns the newest match if several exist (e.g. legacy duplicates before merge).

Source

pub fn write_persona( &self, trait_name: &str, strength: f32, learned_from: Vec<Uuid>, ) -> Result<Uuid, String>

Write a persona trait node.

Source

pub fn store(&self) -> &dyn GraphStore

Get direct access to the underlying store for advanced queries

Source

pub fn sqlite_store(&self) -> &SqliteGraphStore

SQLite backing store (for components such as ainl-graph-extractor that require concrete SQL access).

Source

pub fn validate_graph( &self, agent_id: &str, ) -> Result<GraphValidationReport, String>

SqliteGraphStore::validate_graph for the same backing database (checkpoint / boot gate).

Source

pub fn export_graph(&self, agent_id: &str) -> Result<AgentGraphSnapshot, String>

Source

pub fn import_graph( &mut self, snapshot: &AgentGraphSnapshot, allow_dangling_edges: bool, ) -> Result<(), String>

SqliteGraphStore::import_graph — use allow_dangling_edges: false for normal loads; true only for repair.

Source

pub fn agent_subgraph_edges( &self, agent_id: &str, ) -> Result<Vec<SnapshotEdge>, String>

Source

pub fn write_node_with_edges( &mut self, node: &AinlMemoryNode, ) -> Result<(), String>

SqliteGraphStore::write_node_with_edges (transactional; fails if embedded edge targets are missing).

Source

pub fn insert_graph_edge_checked( &self, from_id: Uuid, to_id: Uuid, label: &str, ) -> Result<(), String>

Source

pub fn read_runtime_state( &self, agent_id: &str, ) -> Result<Option<RuntimeStateNode>, String>

Read persisted RuntimeStateNode for agent_id (most recent row).

Source

pub fn write_runtime_state( &self, state: &RuntimeStateNode, ) -> Result<(), String>

Upsert persisted RuntimeStateNode for the given agent (stable node id per agent_id).

Source

pub fn write_node(&self, node: &AinlMemoryNode) -> Result<(), String>

Write a fully constructed node (additive API for callers that set extended metadata).

Source

pub fn insert_trajectory_detail( &self, row: &TrajectoryDetailRecord, ) -> Result<(), String>

Insert a detailed trajectory row (see SqliteGraphStore::insert_trajectory_detail).

Source

pub fn list_trajectories_for_agent( &self, agent_id: &str, limit: usize, since_timestamp: Option<i64>, ) -> Result<Vec<TrajectoryDetailRecord>, String>

Recent trajectory detail rows for an agent (see SqliteGraphStore::list_trajectories_for_agent).

Source

pub fn count_trajectory_details_before( &self, agent_id: &str, before_recorded_at: i64, ) -> Result<usize, String>

How many ainl_trajectories detail rows would be removed by Self::prune_trajectory_details_before (same before_recorded_at semantics).

Source

pub fn prune_trajectory_details_before( &self, agent_id: &str, before_recorded_at: i64, ) -> Result<usize, String>

Remove persisted trajectory detail rows with recorded_at strictly before before_recorded_at (seconds).

This targets the ainl_trajectories table only. Graph Trajectory nodes and cross-links are not deleted here; use exports / graph tooling if you need a full-store consistency pass after pruning.

Source

pub fn search_failures_for_agent( &self, agent_id: &str, query: &str, limit: usize, ) -> Result<Vec<AinlMemoryNode>, String>

Search persisted FailureNode rows for an agent (FTS5 over ainl_failures_fts).

Source

pub fn search_all_nodes_fts( &self, agent_id: &str, query: &str, project_id: Option<&str>, limit: usize, ) -> Result<Vec<AinlMemoryNode>, String>

Full-graph FTS5 search (ainl_nodes_fts); see SqliteGraphStore::search_all_nodes_fts_for_agent.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.