The Tri-Tier Memory Architecture

To solve the problem of context decay and token bloat in long-running AI sessions, the EDASM (Event-Driven Agent State Machine) architecture employs a three-tier memory hierarchy. This structure balances performance, persistence, and semantic retrieval:

  • Tier 1 (Redis): Acts as the high-speed, short-term cache for immediate session state. It stores the most recent interactions to ensure low-latency responses.
  • Tier 2 (PostgreSQL): Serves as the source of truth for structured session history and audit logs, ensuring that state is never lost even if the cache is cleared.
  • Tier 3 (pgvector): Provides semantic search capabilities. By offloading long-term memory to a vector database, the agent can retrieve relevant historical context without needing to keep the entire conversation history in the active prompt window.

Relevance Scoring for Token Optimization

To maintain performance within strict LLM token budgets, the system uses a relevance scoring formula to dynamically prune context. Instead of a simple "first-in, first-out" approach, the system calculates a score based on the recency of the interaction and its semantic similarity to the current task. By filtering out low-relevance data, the agent maintains a high-quality context window, reducing hallucinations and preventing the "context collapse" common in long-running sessions.

Durable Execution with Temporal

AI agents often fail when external side effects (like API calls or database writes) are interrupted. The architecture integrates Temporal to manage these actions as durable workflows. By wrapping external calls in a workflow, the system ensures that if a process crashes or a network timeout occurs, the action can be retried automatically from the exact point of failure. This creates a "checkpointed" execution environment where every side effect is recoverable, effectively eliminating the risk of duplicate or partial actions that occur when agents lose track of their own progress.