Skip to main content
Choosing between $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.stock to 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.discount to apply it when calculating the total
  • Temporary authentication: You get a token from your API and save it in $context.token to use in subsequent calls within the same flow
  • Intermediate calculations: The user selects products, you keep adding up the subtotal in $context.subtotal to display it before confirming the purchase
Example:

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
Example:
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 $memory

Summary

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.
Rule of thumb: if the data still has value when the user stops writing to you for a month, it does not live in $memory. It lives in Datum.