Build a Meal-Planning Agent with Redis Memory
A meal-planning agent should remember that you are vegetarian, have 25 minutes to cook on weeknights, and enjoyed the chickpea curry it suggested last time. You should be able to start a new conversation without explaining those preferences again.
In this guide, you will build a terminal assistant that searches a small recipe catalog and uses Redis Agent Memory to save, recall, and update information about you. The integration centers on createRedisAgentMemory from @redis/vercel-ai-sdk, which provides memory tools you can combine with your own AI SDK tools.
By the end, you will be able to:
- Save dietary preferences and cooking constraints.
- Start a fresh conversation and get suggestions based on those memories.
- Remember feedback about meals you actually cooked.
- Correct a preference without keeping contradictory memories.
How It Works
The assistant uses a ToolLoopAgent with two sources of information:
- A recipe catalog, accessed through a
searchRecipestool. It contains the recipes the assistant can recommend. - Personal memories, accessed through Redis's
search_memories,create_memories, andupdate_memorytools. They contain facts the user asks the assistant to remember.
When you ask for dinner ideas, the agent first recalls relevant preferences, then uses them to search the catalog. For example, it can turn a remembered vegetarian diet and 25-minute cooking limit into filters for searchRecipes.
Conversation messages stay in the running application. Personal memories live in Redis Agent Memory and remain available after you clear the conversation or restart the program. The tools approach lets the model decide when to retrieve and maintain those memories.
Prerequisites
You will need:
- Node.js 22 or later and pnpm.
- A Vercel AI Gateway API key.
- A Redis Agent Memory store and API key from Redis Cloud.
This integration requires AI SDK 7.0.114 or later in the 7.x series and Zod 4.1.8 or later in the 4.x series. Redis Agent Memory is a managed service; use its store ID and API key for this guide, rather than a Redis database connection URL.
Project Setup
Create a project using ES modules:
Install the dependencies:
Create a .env file:
If your store uses a different endpoint from the package's default, also set AGENT_MEMORY_URL to the endpoint provided by Redis Cloud.
Add .env and node_modules/ to .gitignore:
You will create three TypeScript files:
Step 1: Create the Recipe Search Tool
Start with a small catalog so you can see how recalled preferences affect the results. Create recipes.ts:
The filtering happens in code. The model chooses the arguments using the current request and retrieved memories. You can later replace the local array with your own recipe database without changing the memory integration.
Step 2: Create the Agent with Redis Memory
Create agent.ts. Initialize createRedisAgentMemory once, then create tools scoped to the application user:
createRedisAgentMemory configures the connection to the managed memory service. Calling memory.tools({ scope: { userId } }) returns tools that save and retrieve memories for that user. The model remains configured separately on ToolLoopAgent, so you can use another model that supports tool calling.
Only the three selected memory tools are exposed to this agent. They let it retrieve relevant facts, create new memories, and correct existing ones. This example manages conversation messages locally and writes long-term memories explicitly, so it does not depend on background extraction from session events.
Use a stable user ID across conversations. In an authenticated application, derive it from the signed-in user on the server. Scoping the tools does not authenticate the caller. The environment-based identity in the next step is for this local demo.
Step 3: Add a Terminal Chat
Create chat.ts. Keep the current conversation in a ModelMessage[] and provide /new to clear it:
Appending result.responseMessages preserves the assistant's messages and tool results for follow-up questions in the same conversation. The onToolExecutionEnd callback prints tool inputs and outcomes so you can inspect what the agent retrieved, saved, or used to filter recipes.
/new clears the messages passed to the model. It keeps the same user ID, so the agent can still find that user's saved memories. Restarting the program also clears the local conversation history.
Step 4: Try It Across Conversations
Run the application:
Save Your Preferences
Start with:
Look for a create_memories result confirming the saved facts. The agent should store the diet, ingredient preference, and cooking limit separately so it can update one without replacing the others.
Start a Fresh Conversation
Type /new, then ask:
The earlier messages are no longer in the model's input. Look for a search_memories result containing your preferences, followed by a searchRecipes call with arguments like these:
The catalog contains four matching meals: chickpea curry, lentil salad, black bean tacos, and tomato pasta. The agent can choose three and explain why they fit.
Memory writes and search indexing can take a moment to become visible. If a confirmed save is not returned by the first search, ask the agent to check again before creating another memory. The exact wording and tool sequence can vary by model.
Remember a Meal You Cooked
Tell the assistant:
After the save succeeds, type /exit and run pnpm tsx chat.ts again. Ask:
The agent should recall both your constraints and the meal feedback, then search the catalog with chickpea-curry in excludeRecipeIds. Lentil salad, black bean tacos, and tomato pasta still match. This demonstrates that the useful context survived a process restart.
Correct a Preference
Next, say:
Look for search_memories followed by update_memory using the existing ingredient preference's ID. The agent should keep your vegetarian diet and weeknight cooking limit, and the mushroom and tofu stir-fry becomes a suitable suggestion.
Start another conversation with /new and ask what the agent remembers about your food preferences to check the correction.
Try Another User
Exit the application and start it with a different demo identity:
Ask what it remembers about your diet. A new user's memory search should be empty; the agent should ask for preferences instead of borrowing the first user's facts.
What to Build Next
The same pattern works for a shopping assistant that recalls sizes and product feedback, a tutor that remembers learning goals, or a project assistant that retrieves previous decisions. Keep the domain tool responsible for accessing application data and use the memory tools to bring relevant personal context into the task.
For a web interface, use this agent with AI SDK UI and resolve the memory scope from your authenticated server context. To also record conversation events, see Redis's session recording hooks.
Learn More
- Redis Agent Memory integration for configuration and package requirements.
- Redis memory tools for tool schemas, scopes, and write behavior.
- Tools and Tool Calling for composing AI SDK tools.
- Build a Custom Memory Tool for implementing your own memory storage.