Add long-term memory to an AI agent by saving information outside the conversation and retrieving it for future tasks. You can use structured profiles, conversation summaries, task journals, searchable records, or persistent files. Choose the approach based on what the agent needs to remember and how it will use that information.
Copy link to headingWhich memory pattern fits your agent?
Combine memory patterns when future tasks need known facts alongside relevant material from a larger collection.
Support agents can use profiles for customer preferences, summaries for earlier troubleshooting, and search for relevant documentation. Start with the information your agent needs most often and add patterns as needed.
AI SDK supports memory integrations and custom tools that connect agents to storage. Your application decides what to retain and how each task retrieves it.
Profiles, summaries, and task journals can share a database. Scope records by user or project and coordinate concurrent writes to prevent lost updates.
Copy link to heading1. Store user preferences and project settings
Use a structured profile for confirmed preferences and project settings when the agent can identify the user or project. Named fields such as preferred language or runtime support direct lookups of specific facts.
Key an agent_profiles table by user or project ID, using columns for predictable fields and JSON for flexible preferences. Record each preference's source and last update. Vercel Marketplace offers database integrations.
Load the relevant profile fields before a model call, or let the agent retrieve them through an AI SDK lookup tool. Save confirmed corrections to the current record. Keep earlier values in an audit record when you need a history of changes.
Copy link to headingProfile tradeoffs
Use summaries or search for information that doesn't fit predictable profile fields.
Copy link to heading2. Carry conversation decisions forward with summaries
Planning assistants can save the agreed launch plan and unresolved requirements as a summary for the next discussion. Summaries carry those decisions and open questions forward in fewer words than a full transcript.
Store summaries in a table such as conversation_summaries. Include the summary text, user or project ID, source conversation ID, and range of messages covered. Keep the original messages separately so the agent can check the exact wording.
Generate summaries at checkpoints, such as a confirmed decision or the end of a conversation. Record the source version and select summaries relevant to later tasks. Store exact dates, identifiers, and requirements separately when an omission could change the agent's next action.
Copy link to headingSummary tradeoffs
Copy link to heading3. Record task attempts and outcomes
For a data import agent, record which parser handled a file, whether validation passed, and any errors returned. Keeping these methods, outcomes, and conditions in a task journal gives the agent evidence to consult on similar tasks.
Store each attempt in a task_attempts table with task and project IDs, input characteristics, method, outcome, timestamp, and evidence references. Keep large logs and output files in persistent storage such as Vercel Blob, and save their storage references in the record.
Write an entry after each attempt finishes. Before retrieving past attempts, filter by task type, access permissions, and input versions. Retain failures for diagnosis, but load only those relevant to the current task.
Copy link to headingTask-journal tradeoffs
In the Evo-Memory experiments, some baseline methods performed worse when their memories included unfiltered failed attempts. Recording more outcomes does not necessarily improve an agent's performance; it also needs a way to select and refine useful experience.
“The import timed out” records what happened. “The batch is too large” is a possible explanation. Test that explanation with a smaller batch before saving “reduce the batch size” as a reusable procedure.
Copy link to heading4. Retrieve relevant memories with search
Use retrieval-augmented generation (RAG) to find relevant passages in saved notes, decisions, and documents, then supply them to the model. This approach fits collections that are too large or varied to load for every question.
Keep original documents in a database or file store. Index passages with source IDs, versions, and access metadata. For each question, enforce the user's access permissions before returning passages and source references to the model.
Generate embeddings with AI SDK and store them alongside source records using pgvector. Your application still needs to handle document updates, retrieval queries, and access rules.
Copy link to headingRetrieval tradeoffs
Anthropic's Contextual Retrieval experiments show how adding context to passages and combining semantic retrieval with keyword search can improve retrieval. Test these techniques on your own documents and questions before choosing a setup. Use a direct lookup for a known record ID.
Copy link to heading5. Keep memory in persistent files
Keep profiles in JSON files and summaries or task journals in Markdown when the agent works through file tools. For example, a planning agent can update decisions.md as requirements change, then read it before proposing the next milestone. The same workspace can also retain scripts, datasets, and outputs.
Use Vercel Sandbox to run file tools and the generated code, and expose scoped tools through the AI SDK. Record the workspace ID, file paths, and input versions with each task.
Vercel Sandbox can save and restore its own filesystem. Vercel Drives can retain a directory independently of the sandbox, so later runs can reuse files in a different environment.
Copy link to headingFile-memory tradeoffs
Anthropic's long-running agent harness uses progress files and Git history to help later coding sessions continue. At the start of a session, the coding agent reads those records and tests the application before making further changes.
Retaining files does not keep processes running. To reproduce earlier results, later runs also need the required tools, dependencies, and input versions.
Copy link to headingFrequently asked questions
Copy link to headingDo you need a vector database for long-term AI agent memory?
No. Structured profiles can use direct database lookups, and agents can read retained files through tools. Vector search is useful when a task needs to find relevant information within a large collection based on similarity.
Copy link to headingHow do you add long-term memory to an AI SDK agent?
Choose a memory integration or define AI SDK tools that read and write your storage backend. Scope records to the correct user or project, retrieve relevant information for each task, and define correction and deletion rules. The integration or backend retains the information between conversations.
Copy link to headingShould you store full conversations or summaries?
Keep full conversations when you need exact wording or an audit trail. Use summaries when future tasks need a shorter account of decisions, and link each summary to its source messages. Update the summary when a source correction changes its meaning.
Copy link to headingWhen should agent memory updates run in the background?
Run extraction or indexing in the background when the current answer doesn't depend on it. Later tasks may start before the new information is available, so define how your application handles pending updates. Save a confirmed fact before continuing when the next action depends on it.
Copy link to headingHow do you stop an agent from recalling stale memories?
Record each memory's source version, owner, and update time. When a fact changes, replace or invalidate the record and refresh summaries and indexes that use it. Then ask for the fact in a new conversation and verify that retrieval returns the corrected value.
Copy link to headingCan an agent use RAG and persistent files together?
Yes. Use a retrieval store to locate relevant passages while a workspace retains the underlying documents, scripts, and editable outputs. Keep source IDs and file versions aligned so retrieved information points to the material used by the task.
Copy link to headingCan multiple sandboxes read the same Vercel Drive?
Yes. Once a drive has been mounted read-write and written to, multiple sandboxes can mount read-only snapshots concurrently. Only one sandbox can mount the drive read-write at a time.
Each snapshot shows files at mount time; mount a new one for updates.