Conversation Memory & State Management
Overview
Conversation Memory (IConversationMemory) is the heart of EDDI's stateful architecture. It's a Java object that represents the complete state of a conversation, including history, user data, context, and intermediate processing results. This object is passed through the entire Lifecycle Pipeline, with each task reading from and writing to it.
What is Conversation Memory?
Think of Conversation Memory as a living document that captures everything about a conversation:
Who: User ID and agent ID
What: All messages exchanged (both user inputs and agent outputs)
When: Timestamp of each interaction
Context: Data passed from external systems (user profile, session info, etc.)
State: Current processing stage (READY, IN_PROGRESS, ENDED, etc.)
Properties: Extracted and stored data (user preferences, entities, variables)
History: Complete record of all previous conversation steps
Key Concepts
1. Conversation Steps
A conversation is divided into steps, where each step represents one complete interaction cycle:
Each step contains:
Input: What the user said
Actions: Actions triggered by behavior rules
Data: Results from lifecycle tasks (parsed expressions, API responses, LLM outputs)
Output: Agent's response
2. Current Step vs Previous Steps
Current Step: Writable, being built during lifecycle execution
Previous Steps: Read-only, provides conversation history
3. Memory Scopes
EDDI supports different scopes for storing data:
step
Single interaction
Temporary data needed only for this response. Cleared at the end of the turn, however it ends — except a HITL pause, whose turn is not over
conversation
Entire conversation
User preferences, extracted entities (persists across steps)
longTerm
Across conversations
User profile data that should persist between sessions. Written to the user memory store when a turn completes
secret
Entire conversation
API keys, tokens and other credentials. The plaintext goes into the Secrets Vault the moment the instruction runs, and the property holds only a ${vault:...} reference. Needs EDDI_VAULT_MASTER_KEY; without it the turn fails rather than storing plaintext. See Properties
These are the values of the Property.Scope enum (step, conversation, longTerm, secret).
4. Undo/Redo Support
Conversation Memory supports undo/redo operations:
This enables scenarios like:
User makes a mistake and wants to go back
Testing different conversation paths
Debugging agent behavior
Undo and redo carry the conversation properties with the step. Each completed turn records which properties it changed (step data properties:changes, uncommitted and non-public, so the LLM never sees it); undo restores their values from before the turn — including removing a property the turn created — and redo re-applies them. For longTerm properties the change is carried into the user memory store as well, but only where the store still holds exactly the value the undone turn wrote: a value another conversation or agent has written since is left alone. A new turn clears the redo stack, because the undone steps now belong to an abandoned branch. A turn completed through a HITL resume records no property changes; undoing it leaves its properties as they are.
Conversation Memory Structure
Core Properties
Conversation States
How Lifecycle Tasks Use Memory
Each lifecycle task follows this pattern:
Example: Behavior Rules Task
Example: Reading history
The snippets on this page are illustrative sketches, not copy-paste code. Real keys are the constants in MemoryKeys (input, input:initial, expressions:parsed, actions, output:*, context:*, taskErrors, properties:changes).
The LLM task does not read this raw history. It builds its message list through ConversationHistoryBuilder (see What the LLM sees).
Example: HTTP Calls Task
Accessing Memory in Configurations
In Output Templates (Qute)
In HTTP Call Body Templates
In Behavior Rule Conditions
Memory Persistence
Storage Mechanism
During a turn: the memory is a Java object on the heap, read and written by the pipeline's tasks
After the turn: it is converted to a
ConversationMemorySnapshotand saved to the datastore — MongoDB or PostgreSQL, whichever the deployment uses. A turn that only added a step is appended; undo, redo, rerun and HITL pause/resume rewrite the document. Writes are guarded by an optimistic revision (_rev), so two writers cannot silently overwrite each otherOn the next turn: the snapshot is loaded from the datastore again and converted back into a live memory object
What Is Cached
Conversation memory is not cached. Every turn loads it from the datastore and saves it back:
What is cached is the conversation state (READY, IN_PROGRESS, …): ConversationService keeps it in a Caffeine cache named conversationState with a 30-second TTL, so clients polling GET /agents/{conversationId}/status during a running turn do not hit the database on every poll. The cache is local to each instance; in a NATS cluster a node that changes a conversation's state tells the others to drop their copy, and the TTL bounds how stale an entry can be in any case.
Stored Document Structure
In MongoDB the snapshot is a document in the conversationmemories collection; in PostgreSQL the same JSON is the data column (JSONB) of the conversation_memories table. Abridged, with the HITL bookkeeping fields omitted:
Two things the shape makes visible: a step's data lives under workflows[].lifecycleTasks[], keyed by memory key (prefixed keys such as input:initial and output:text:<action>), not as a flat list; and the rendered outputs are stored separately in conversationOutputs, which is what the conversation log and the LLM's history are built from.
Best Practices
1. Use Appropriate Scopes
2. Bound Large API Responses
A saved API response stays in the conversation step it was received in — that step is persisted, and memory is loaded on every turn. Extract the values later turns need into properties, and cap the size of what is kept:
The postResponse instruction adds temperature as a property; it does not remove the saved response, which remains under memory.current.httpCalls.weatherResponse for that step. What bounds it is maxResponseSizeInBytes (default 2 MB, eddi.httpcalls.default-max-response-size-bytes): a longer body is truncated before it is stored. saveResponse: false keeps the body out of memory entirely, but then no postResponse instruction can read it either. Inside the call's own postResponse the path starts at its responseObjectName; the value is stored with its type (a number stays a number). Later turns read the property ({properties.temperature}), not the old step's response.
3. Leverage History for Context
When calling LLMs, you can control how much history is sent:
4. Use Context for External Data
Pass data from your application via context instead of hardcoding:
Then access in agent logic:
Memory Flow Example
Let's trace how memory flows through a complete conversation step:
1. User Request
2. Memory Load and Step Preparation
The conversation already exists (POST /agents/{agentId}/start created it and ran its first, CONVERSATION_START step). For this turn:
Context entries are step data (context:<name>), not conversation properties: they belong to the turn they arrive with. Templates read them as {context.userId}.
3. Parser Task Execution
4. Behavior Rules Execution
5. HTTP Call Execution
6. Output Generation
7. Memory Persistence
8. Response to User
Advanced Topics
Accessing Nested Data
Iterating Over History
Conditional Memory Access
Template Variable Reference
When tasks process templates (system prompts, HTTP call bodies, property instructions, output templates), MemoryItemConverter.convert(memory) produces a map with these top-level keys:
context
Map<String, Object>
Input context variables set per turn
{context.language}
properties
Map<String, Object> (raw values)
All conversation properties — includes both session-scoped and longTerm properties loaded from persistent storage
{properties.preferred_language}
memory
Map with current, last, past
Conversation step data from the pipeline
{memory.current.output}, {memory.last.input}
snippets
Map<String, Object>
Prompt Snippets — auto-injected from PromptSnippetService
{snippets.cautious_mode}
vars
Map<String, Object>
Global Variables — deployment-wide config from GlobalVariableResolver
{vars.default-model}
userInfo
Map with userId
Authenticated user identity
{userInfo.userId}
conversationInfo
Map with conversationId, agentId, etc.
Conversation metadata
{conversationInfo.agentId}
conversationLog
String
Formatted conversation history
{conversationLog}
Key insight:
longTermproperties are loaded intoconversationPropertiesat conversation init and are immediately available via{properties.key}in any template. You do NOT need a separate template namespace for persistent data — properties IS the namespace.
⚠️
propertiesholds raw values, notPropertyobjects.MemoryItemConverter.convert()insertsConversationProperties.toMap(), andtoMap()returns the unwrapped Java value (String,Integer,Boolean,List,Map) that was stored — thePropertywrapper is gone by the time a template sees it. Write{properties.preferred_language};{properties.preferred_language.valueString}resolves against aStringand fails at render time. See Agent Config Authoring for the authoritative template data model.
When to Use Which
Data from your application
{context.X}
Per-request, set by caller
Persistent user preferences
{properties.X}
Survives across conversations (scope=longTerm)
Current turn's input/output
{memory.current.X}
Step-level data from the pipeline
Previous turn's data
{memory.last.X}
One step back
Who the user is
{userInfo.userId}
Authenticated identity
Which agent/conversation
{conversationInfo.agentId}
Conversation metadata
Full conversation history
{conversationLog}
Formatted string of all turns
Conversation Lifecycle: Init and Teardown
Understanding what happens at conversation boundaries is critical for features that manage persistent state.
Initialization (Conversation.init())
init() runs once, when the conversation is created by POST /agents/{agentId}/start (Agent.startConversation). It does not load anything from the conversation store — the memory is new:
Recalled longTerm properties then travel inside the conversation document; later turns do not reload them from the user memory store.
Each Turn (Conversation.say())
Pipeline Execution
The LifecycleManager of each workflow runs its configured tasks in sequence, for example:
Teardown
After the pipeline, still inside Conversation:
ConversationService then saves the snapshot to the datastore and updates the cached state. secret properties are not handled here: they were vaulted when their property instruction ran.
Key insight: Persistent state is a session concern handled in
Conversation.javainit/teardown — NOT a pipeline task. If a feature needs to load/save cross-conversation state, it extends the Conversation init/teardown logic. The pipeline processes data for a single turn; session boundaries manage what persists between turns.
What the LLM sees
Conversation memory has two audiences. Pipeline tasks (behavior rules, property setter, and so on) see the full memory: every step and every data key. The LLM sees only a windowed view that ConversationHistoryBuilder assembles from the last N conversation outputs, converted to chat messages. "The conversation is too long" is therefore two different problems: the LLM context window (what the model sees) and the stored document size. Windowing and summaries change only the first; the full conversation always stays in the database. See Conversation Window Management and Rolling Conversation Summary, and Memory Policy for what is hidden from the model after a failed task.
Conversation store and lifecycle
The stored snapshot is served by /conversationstore/conversations (read a simple or raw log, list, DELETE one conversation or a set, POST end-inactive and POST end to end conversations, GET active/{agentId}). Deleting a conversation goes through ConversationPurgeService, which removes the conversation together with what hangs off it: vault slots, attachments, checkpoints, the HITL journal, the stored memory and the conversation descriptor. Checkpoints (IConversationCheckpointStore) are saved snapshots of the conversation properties and the step index (MemoryCheckpoint), not of the steps or outputs. A rollback restores the properties only, so a checkpoint is not a backup of the whole conversation. For erasure on behalf of a data subject see GDPR compliance.
Related Documentation
Architecture Overview - Understanding the big picture
Properties - Property system, scopes, and persistence
Behavior Rules - Using memory in conditions
Output Templating - Accessing memory in outputs
HTTP Calls - Storing API responses in memory
LLM Integration - Using conversation history with LLMs
Passing Context Information - Injecting external data
Last updated
Was this helpful?