Chapter 5 of 10
Temporal state, memory, and event history
Durable cognition
About 4 minutes · includes examples, an exercise, and references
Chapter at a glance
- •Reconstruct task state from immutable typed events and versioned reducers.
- •Separate workflow chronology from the valid time of domain claims.
- •Publish long-term memory through validation, scope, and retention policy.
Agent state changes over time, and the world changes while an agent is paused. A reliable design distinguishes event history, current task state, domain facts, and memories derived from prior work. An append-only history records what happened; a reducer reconstructs current state; governed stores provide domain knowledge; optional memory systems propose reusable context under explicit trust and retention rules.
An event records type, task and sequence identifier, prior-state version, payload reference, actor, time, correlation, and policy context. Events include GoalAccepted, PlanProposed, ActionAuthorized, ToolRequested, ToolObserved, EvidenceAdded, ApprovalGranted, StateReplanned, WriteCommitted, and TaskTerminated. Do not place secrets or large source texts directly in an immutable event stream; store protected artifacts separately and reference them.
Event sourcing makes transitions auditable and replayable. The state reducer must be deterministic for recorded events. Snapshots accelerate long histories but include the last event sequence and reducer version. On replay, effects such as emails or payments are not executed again; their recorded observations are consumed. Code changes that alter reduction semantics require migration or versioned reducers.
Separate event time, ingestion time, and domain valid time. A tool observation received now may describe a fact valid yesterday. Late events should not be reordered silently if sequence affects decisions. Record causality and decide whether the new fact invalidates pending steps. OWL-Time concepts can represent domain intervals, while workflow event metadata handles execution chronology.
Working memory is the current state required for this task: goals, plan, evidence, and budgets. Episodic memory summarizes prior trajectories, including what succeeded and failed. Semantic memory extracts reusable claims. A memory write is a governed publication operation, not an automatic dump at task end. Validate source, sensitivity, expiry, tenant, and whether the content is a fact, preference, heuristic, or unresolved hypothesis.
Retrieving memories introduces the same risks as document RAG: stale claims, prompt injection, cross-user leakage, and generated summaries mistaken for truth. Filter by identity and purpose before ranking. Include memory origin, creation task, evidence, confidence method, valid time, last verification, and expiry. A memory can suggest an action but live preconditions still require current checks.
Temporal graph state needs assertion lifecycles. Rather than mutating “service status” in place, preserve assertions with valid and transaction time or event-derived versions. A current view selects applicable approved claims. A trajectory pinned to release R should not silently see release R+1 after resuming. Either continue against the pinned snapshot where safe or revalidate and explicitly transition to the new release.
Concurrency creates stale decisions. Use optimistic version checks when committing state: an action authorized against state version 12 cannot commit over version 14 without revalidation. External resources may require etags, compare-and-set, or transaction tokens. Serialize high-risk transitions even when evidence reads run in parallel.
Retention and deletion must traverse task state, event payloads, memory indexes, embeddings, traces, and backups. A compacted summary can still contain personal data. Design redaction or cryptographic deletion where permitted and preserve only necessary audit metadata. Test that deleted memory does not reappear from a replay or stale index.
Evaluate deterministic replay, snapshot equivalence, late-event handling, stale precondition invalidation, memory precision, expiry, cross-scope isolation, and deletion propagation. Time is not a timestamp field added at the end; it is a dimension of every fact, permission, plan, and effect.
Key points
- Reconstruct task state from immutable typed events and versioned reducers.
- Separate workflow chronology from the valid time of domain claims.
- Publish long-term memory through validation, scope, and retention policy.
- Revalidate paused work when graph, ontology, policy, or world state changes.
A replay-safe workflow event
Read the expected behavior in the surrounding walkthrough, then copy and run this reference implementation.
{
"taskId": "task-441",
"sequence": 18,
"type": "ToolObserved",
"stateVersionBefore": 12,
"actionId": "action-77",
"observationRef": "artifact://tool-observation/991",
"toolRequestKey": "idem-99c4c5d2",
"recordedAt": "2025-04-18T12:04:22Z",
"policyVersion": "agent-policy-9",
"graphRelease": "kg-2025-04-18.2"
}Worked examples
Toy
Expired preference memory
A previous task recorded that a user preferred morning meetings.
The memory is typed as a preference with origin and expiry, not a permanent fact. After expiry the agent asks or uses a neutral default rather than asserting the preference.
- Memory kind
- Validity
- Safe fallback
System
Resume after policy change
A workflow waits overnight for approval while authorization policy and graph release change.
On wake, the controller loads history, detects pinned-version drift, reevaluates preconditions and approval scope, and either creates a new authorized action or enters needs-review.
- Deterministic replay
- Version drift
- No stale execution
Exercise
Replay a temporal agent
Model a task that pauses for approval, receives a late fact, and resumes after an index change.
- Define events and deterministic reduction.
- Separate event and valid time.
- Add snapshot and version checks.
- Create, expire, and delete one memory.
Success criteria
- Replay never repeats external effects.
- Late evidence invalidates dependent steps explicitly.
- Memory retrieval is scope- and time-aware.
- Deletion reaches derived and indexed copies.
Reflect: Which current-state field cannot be understood correctly without its event history?
References and further reading
- Temporal Workflow DocumentationOfficial documentation for durable workflows, event histories, deterministic replay, and external activities.
- Time Ontology in OWLThe W3C Recommendation for describing temporal instants, intervals, durations, and relations.
- PROV-O: The PROV OntologyThe W3C Recommendation for representing entities, activities, agents, derivations, and attribution.