$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
Summary
| Aspect | $context | $memory |
|---|---|---|
| Duration | Only during the conversation | Configurable (TTL): up to 1 day (JSON) or 1 week (files) |
| Types | Any JavaScript value | Primitives, JSON (5 KB), Files (10 MB) |
| Use | Temporary conversation data | Improve experience between conversations |
| Security | Ideal for temporary sensitive data | Do not use for sensitive data |