Class CheckpointerSnapshotStore

java.lang.Object
com.tnsai.context.snapshot.impl.CheckpointerSnapshotStore
All Implemented Interfaces:
com.tnsai.context.snapshot.SnapshotStore

public class CheckpointerSnapshotStore extends Object implements com.tnsai.context.snapshot.SnapshotStore
Checkpointer-backed implementation of SnapshotStore.

This implementation leverages the existing Checkpointer system (SQLite, PostgreSQL, MongoDB, Redis) for persistent snapshot storage.

Storage Format

Each snapshot is stored as a checkpoint with:

  • threadId = agentId
  • checkpointId = snapshotId
  • state = serialized snapshot data
  • metadata = snapshot metadata (trigger, timestamp, etc.)

Usage Example


 // Use with SQLite checkpointer
 Checkpointer checkpointer = new SQLiteCheckpointer("snapshots.db");
 SnapshotStore store = new CheckpointerSnapshotStore(checkpointer);

 // Enable context graph
 agent.enableContextGraph(store, new InMemoryDecisionTraceStore());
 
  • Constructor Details

    • CheckpointerSnapshotStore

      public CheckpointerSnapshotStore(com.tnsai.state.Checkpointer checkpointer)
      Creates a new CheckpointerSnapshotStore.
      Parameters:
      checkpointer - the underlying checkpointer for persistence
  • Method Details

    • save

      public void save(com.tnsai.context.snapshot.ContextSnapshot snapshot)
      Specified by:
      save in interface com.tnsai.context.snapshot.SnapshotStore
    • findById

      public Optional<com.tnsai.context.snapshot.ContextSnapshot> findById(String snapshotId)
      Specified by:
      findById in interface com.tnsai.context.snapshot.SnapshotStore
    • findLatestByAgent

      public Optional<com.tnsai.context.snapshot.ContextSnapshot> findLatestByAgent(String agentId)
      Specified by:
      findLatestByAgent in interface com.tnsai.context.snapshot.SnapshotStore
    • findByAgent

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByAgent(String agentId)
      Specified by:
      findByAgent in interface com.tnsai.context.snapshot.SnapshotStore
    • findByAgentAndTimeRange

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByAgentAndTimeRange(String agentId, Instant start, Instant end)
      Specified by:
      findByAgentAndTimeRange in interface com.tnsai.context.snapshot.SnapshotStore
    • findByConversation

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByConversation(String conversationId)
      Specified by:
      findByConversation in interface com.tnsai.context.snapshot.SnapshotStore
    • findByTrigger

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByTrigger(com.tnsai.context.snapshot.SnapshotTrigger trigger)
      Specified by:
      findByTrigger in interface com.tnsai.context.snapshot.SnapshotStore
    • findByTimeRange

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByTimeRange(Instant start, Instant end)
      Specified by:
      findByTimeRange in interface com.tnsai.context.snapshot.SnapshotStore
    • delete

      public boolean delete(String snapshotId)
      Specified by:
      delete in interface com.tnsai.context.snapshot.SnapshotStore
    • deleteByAgent

      public int deleteByAgent(String agentId)
      Specified by:
      deleteByAgent in interface com.tnsai.context.snapshot.SnapshotStore
    • deleteOlderThan

      public int deleteOlderThan(Instant cutoff)
      Specified by:
      deleteOlderThan in interface com.tnsai.context.snapshot.SnapshotStore
    • count

      public int count()
      Specified by:
      count in interface com.tnsai.context.snapshot.SnapshotStore
    • countByAgent

      public int countByAgent(String agentId)
      Specified by:
      countByAgent in interface com.tnsai.context.snapshot.SnapshotStore
    • getStatistics

      public com.tnsai.context.snapshot.SnapshotStore.SnapshotStoreStatistics getStatistics()
      Specified by:
      getStatistics in interface com.tnsai.context.snapshot.SnapshotStore
    • clear

      public void clear()
      Clears all data from the store.