Package com.tnsai.context.snapshot
Class ContextSnapshot
java.lang.Object
com.tnsai.context.snapshot.ContextSnapshot
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for ContextSnapshot. -
Method Summary
Modifier and TypeMethodDescriptionstatic ContextSnapshot.Builderbuilder()Creates a new builder.diff(ContextSnapshot other) Computes the difference between this snapshot and another.booleanintGets the total number of BDI elements.getBeliefsBySource(String sourceId) Finds beliefs matching a predicate.intGets the count of expired beliefs.Finds high-confidence beliefs.intgetSpec()getVariable(String name) Gets a variable value by name.<T> Optional<T> getVariable(String name, Class<T> type) Gets a typed variable value.booleanReturns true if this snapshot has any beliefs.booleanReturns true if this snapshot has any entities.inthashCode()booleanReturns true if this snapshot has any intentions.toString()
-
Method Details
-
builder
Creates a new builder. -
getSnapshotId
-
getAgentId
-
getTimestamp
-
getTrigger
-
getBeliefs
-
getDesires
-
getIntentions
-
getEntities
-
getVariables
-
getSpec
-
getConversationId
-
getMessageCount
public int getMessageCount() -
getVariable
Gets a variable value by name.- Parameters:
name- variable name- Returns:
- Optional containing the value if present
-
getVariable
Gets a typed variable value.- Parameters:
name- variable nametype- expected type- Returns:
- Optional containing the typed value if present and castable
-
getBeliefsBySource
Finds beliefs matching a predicate.- Parameters:
sourceId- source to filter by- Returns:
- list of matching beliefs
-
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
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
-
hashCode
public int hashCode() -
toString
-