Learning Paths

Persist Conversations

Store and replay Anvia message history across prompt runs.

Use this path when an agent needs to remember previous turns.

Goal

By the end, you should know:

  • the Message[] history shape
  • how to pass an explicit transcript into a prompt
  • how to use durable session memory
  • how to append response.messages
  • where tool calls and tool results appear in history

Path

  1. Read Messages and History to understand the raw Message[] shape.
  2. Read Prompt Responses to understand response.messages.
  3. Read Memory and Sessions for the core-managed durable conversation model.
  4. Read Memory for raw SQL, Prisma, and Drizzle storage adapters.
  5. Read Agent History for agent-specific history examples.
  6. Read Messages and History if your history includes attachments or rich content.

Minimal Shape

import { Message } from "@anvia/core";

const history = await conversations.loadMessages(conversationId);
const currentPrompt = Message.user(userInput);

const response = await agent.prompt([...history, currentPrompt]).send();

await conversations.saveMessages(conversationId, [
  ...history,
  ...response.messages,
]);

Key Rule

response.messages is only the new part of the run. Append it to the history you loaded if you want a full transcript.

For core-managed durable conversations, configure memory and prompt through a session:

const response = await agent.session(conversationId).prompt(userInput).send();

Add Next

NeedRead
Tool-call historyMessages and History
Streaming conversation UIReadable Streams
Long-term knowledgeAdd Retrieval