Class ContextSnapshot

java.lang.Object
com.tnsai.context.snapshot.ContextSnapshot

public final class ContextSnapshot extends Object
Captures the complete state of an agent's context at a specific moment.

ContextSnapshot represents the "world state" at decision time, including:

  • BDI state (Beliefs, Desires, Intentions)
  • Resolved entities from the context graph
  • Operational variables and metadata

Usage Example


 ContextSnapshot snapshot = ContextSnapshot.builder()
     .agentId("customer-support-agent")
     .trigger(SnapshotTrigger.PRE_DECISION)
     .belief(new Belief("Customer has premium account", 0.95, "crm"))
     .desire(new Desire("Resolve customer issue", Priority.HIGH, "Support SLA"))
     .intention(new Intention("Check account status", "Query CRM API"))
     .entity(customerEntity)
     .variable("sessionId", "abc123")
     .build();

 // Compare snapshots
 SnapshotDiff diff = beforeSnapshot.diff(afterSnapshot);
 

Thread Safety

This class is immutable and thread-safe.

  • Method Details

    • builder

      public static ContextSnapshot.Builder builder()
      Creates a new builder.
    • getSnapshotId

      public String getSnapshotId()
    • getAgentId

      public String getAgentId()
    • getTimestamp

      public Instant getTimestamp()
    • getTrigger

      public SnapshotTrigger getTrigger()
    • getBeliefs

      public List<Belief> getBeliefs()
    • getDesires

      public List<Desire> getDesires()
    • getIntentions

      public List<Intention> getIntentions()
    • getEntities

      public List<Entity> getEntities()
    • getVariables

      public Map<String,Object> getVariables()
    • getSpec

      public Map<String,Object> getSpec()
    • getConversationId

      public String getConversationId()
    • getMessageCount

      public int getMessageCount()
    • getVariable

      public Optional<Object> getVariable(String name)
      Gets a variable value by name.
      Parameters:
      name - variable name
      Returns:
      Optional containing the value if present
    • getVariable

      public <T> Optional<T> getVariable(String name, Class<T> type)
      Gets a typed variable value.
      Parameters:
      name - variable name
      type - expected type
      Returns:
      Optional containing the typed value if present and castable
    • getBeliefsBySource

      public List<Belief> getBeliefsBySource(String sourceId)
      Finds beliefs matching a predicate.
      Parameters:
      sourceId - source to filter by
      Returns:
      list of matching beliefs
    • getHighConfidenceBeliefs

      public List<Belief> getHighConfidenceBeliefs()
      Finds high-confidence beliefs.
      Returns:
      list of beliefs with confidence >= 0.9
    • getExpiredBeliefsCount

      public int getExpiredBeliefsCount()
      Gets the count of expired beliefs.
      Returns:
      number of expired beliefs
    • diff

      public SnapshotDiff diff(ContextSnapshot other)
      Computes the difference between this snapshot and another.
      Parameters:
      other - snapshot to compare with
      Returns:
      SnapshotDiff describing the changes
    • hasEntities

      public boolean hasEntities()
      Returns true if this snapshot has any entities.
    • hasBeliefs

      public boolean hasBeliefs()
      Returns true if this snapshot has any beliefs.
    • hasIntentions

      public boolean hasIntentions()
      Returns true if this snapshot has any intentions.
    • getBDICount

      public int getBDICount()
      Gets the total number of BDI elements.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object