Agent Memory Workshop with TypeScript
Engineer the context of a TypeScript agent built in TypeScript. Build a knowledge graph of what the agent learns, compare semantic search with graph retrieval, then build an agent of your own with guardrails, all backed by Neo4j.
In this 3-hour workshop, you will learn
The Agent Memory Workshop with Mastra is a hands-on workshop on context engineering. Over roughly three hours, you take a TypeScript agent whose memory is scoped to a single conversation, and you build the context pipeline around it that makes it remember, explain itself and stay safe, with Neo4j as the memory.
The model only knows what is in its context window, and the agent's context pipeline decides what goes in. In this workshop, you control that pipeline. Most agent failures are context failures: a rule that scrolled out of the window, a fact that was never saved, a note nobody checked. You reproduce each failure on purpose, then fix it, one capability at a time.
This workshop is for developers building agents that act on a user's behalf and need to remember, justify and constrain what they do. You should be comfortable reading TypeScript and running commands in a terminal, and have a little experience of CypherNeo4j's implementation of GQL, the ISO standard query language for graph databases. It is declarative: you describe the pattern to find, and the database decides how to find it.. If you have built an agent with Mastra or a similar framework and hit the limits of a growing message list, this workshop shows a structured alternative where memory is data you can query. Every lesson includes the commands and expected output you need to follow along at your own pace.
You work with a personal assistant that has tools for email, calendar and tickets over a fake but deterministic workspace. You start with an agent that has no memory, build a knowledge graphA representation of real-world entities and their relationships, stored according to organizing principles, typically in a graph database. of what it learns, and then build an agent of your own. Along the way, you will:
- See how an agent loses a rule, and why traces and long-term memory fix it
- Introduce yourself to the agent, then have it save facts, rules and entities as long-term memory and keep your rules in front of the model at every step
- Compare semantic search with querying a knowledge graph, and see why the two work best together
- See why approvals and recipient rules belong in code instead of in the prompt
- Build an agent of your own: connect tools and MCP servers, have it build a knowledge graph in the background from what they return, and stop it writing without your approval
By the end of the workshop, you will be able to:
- Explain why agent failures are usually context failures, and reproduce them deliberately
- Store long-term memory as facts, rules and entities in a Neo4j graph, and keep the rules that matter in front of the model
- Choose between semantic search and a knowledge graph query for retrieval, and combine them
- Explain why safety constraints belong in code rather than in the prompt, and write a guard of your own
- A GitHub account, to open the Codespace that comes with the workshop (or NodeA vertex in a graph. In a property graph it can carry labels and properties..js 22.13 or later, npm and Docker, to run it locally)
- A workshop API key from GraphAcademy (or your own OpenAI API key)
- A terminal, which the Codespace includes
The first lesson walks through the setup.
- Context Graphs: Agent Memory with Neo4j covers the same memory concepts as a self-paced course.
- Building GraphRAG TypeScript MCP tools shows you how to expose tools like these to any MCP client.
- Neo4j Agent Memory Service (NAMS) is a managed memory service you can use for your own agent, over REST or MCP.
- The Python version of this workshop, Neo4j Agent Memory Workshop, builds the same ideas with Pydantic AI.
- This workshop counts toward the Neo4j & Generative AI Certification.
Context engineering
Treat the context window as something you design. The model only knows what is in it, and you decide what goes in at each step of the agent loop.
Agent memory
Use message history to keep and trim context, and see what happens when a rule scrolls out of the window.
Context traces
Record what was in the context at every model step as Step, Message and ToolCall nodes in Neo4j, so you can answer why the agent did something.
Long-term memory
Introduce yourself to the agent, then see it save a knowledge graph of facts, entities and preferences that is available in every new session.
Retrieval
Know when similarity search fits and when it does not, and when to query the knowledge graph for connections, counts and exact values.
Safety and trust
See why approval and recipient rules belong in code rather than in the prompt, and write a guard of your own.
Build your own
Connect tools and MCP servers to an agent of your own, build a knowledge graph in the background from what they return, and guard its writes.
What you need to take part.
A GraphAcademy account
The workshop is delivered here on GraphAcademy, so you need to be signed in to work through the lessons and keep your progress. Creating an account is free.
A GitHub account, or Git on your own machine
You write code against the workshop-agent-memory-ts repository. The quickest route is a GitHub Codespace, an online editor that clones the code and installs everything for you — that needs a GitHub account.
If you would rather work locally, clone the repository with Git and run it in your own editor instead. No GitHub account is needed for that.