MEMORY / CONVERSATION STATE
Keep the conversation state.
The agent’s normal memory is its transcript: prior user messages, assistant responses, and tool interactions. Persist that state when you want a session to continue across turns or requests.
Conversation history is the working state
runAgent accepts prior AI SDK messages in messages and returns the updated transcript in result.messages. Use it to continue a conversation with its recent context intact. The transcript is not a separate retrieval system and is not automatically stored by the core loop.
const previousMessages = await loadConversation(sessionId);
const run = runAgent({
model,
system,
prompt: userMessage,
tools,
messages: previousMessages,
});
const result = await run.result;
await saveConversation(sessionId, result.messages);Store transcripts by a stable conversation or session ID. In a multi-user app, authorize access to that ID on the server; do not accept another user’s session key as proof of access.
Persist a run with the Node session store
createJsonlSessionStore provides append-only JSONL persistence for AI SDK messages. Load the transcript before a run, then use sessionUpdate to decide whether the result can be appended or must replace the stored transcript after compaction.
import { createJsonlSessionStore, runAgent, sessionUpdate } from "not-another-harness";
const store = createJsonlSessionStore(`.nah/sessions/${sessionId}.jsonl`);
const before = await store.load();
const run = runAgent({ model, system, prompt: userMessage, tools, messages: before });
const result = await run.result;
const update = sessionUpdate(before, result);
if (update.mode === "replace") {
await store.replace(update.messages);
} else {
await store.append(update.messages);
}Store conversation state in a web runtime
The HTTP runtime separates the conversation store from the in-memory run loop. A NahSessionStore loads, appends, and replaces messages by session ID. The built-in memory store is useful for local development or a single long-lived process; use your database, KV store, or another durable adapter when sessions must survive restarts or move between instances.
import { createNahRuntime } from "not-another-harness/js";
const runtime = createNahRuntime({
session: {
load: (id) => database.loadMessages(id),
append: (id, messages) => database.appendMessages(id, messages),
replace: (id, messages) => database.replaceMessages(id, messages),
},
agent: async ({ messages }) => ({
model, system, tools,
// The runtime owns the transcript and current prompt.
}),
});The runtime loads the session, applies the new turn or resume decision, runs the agent, and persists the transcript before completing the response. It also supports in-memory stores via createMemorySessionStore() for development.
Transcript memory and cognitive memory
Conversation history lets the model refer to what was said in this session. Cognitive memory is a separate, optional layer for durable facts and preferences that should remain useful across sessions. It can build prompt context, learn from completed turns, and persist its own state independently of the transcript.
Choose conversation state for continuity within a chat. Add cognitive memory when you need cross-session retrieval or a configurable memory backend.
Configure cognitive memory →