$memory and $context comes down to one simple question: do you need this data after the conversation ends?
Use $context when
Use$context when the data is only needed during the current conversation.
Use cases:
- Checking product availability: The user asks about a product, you query your inventory and save the available stock in
$context.stockto display it and validate the quantity they want to buy in the following nodes - Validating a discount code: The user enters a coupon, you validate it with your API and save the percentage in
$context.discountto apply it when calculating the total - Temporary authentication: You get a token from your API and save it in
$context.tokento use in subsequent calls within the same flow - Intermediate calculations: The user selects products, you keep adding up the subtotal in
$context.subtotalto display it before confirming the purchase
Use $memory when
Use$memory when the data must persist between conversations. You can configure the time-to-live (TTL) for each variable.
Use cases:
- Remembering the user’s name to greet them personally
- Saving the last shipping address to offer it as a default
- Storing preferences that improve the experience in future interactions
- Remembering that the user completed a verification step
For details on data types, TTL, files, and available methods, see the complete Memory guide.
Quick decision criteria
1
Do you need the data in future conversations?
No → Use
$contextYes → Use $memorySummary
What if I need to store data for longer or share it across users?
$memory is not a database: it is per-user working memory with a limited lifetime (30 days of inactivity, per-variable TTL up to 1 day for JSON or 1 week for files). If your use case needs real persistence, cross-user data, queries by field, or audit history, use Datum instead.
Signs that $memory is not the right tool:
- You need to keep the data for more than 30 days, even if the user stops writing.
- The data is business data (orders, invoices, catalogs), not per-turn user state.
- Several users or workflows in the same project must read the same record.
- You need to filter, search by field, or audit changes.