What is ctx.memory?
ctx.memory is an HTTP client to Jelou’s Memory API. It talks to the same key-value store as the user’s memory ($memory in the builder). Anything you write from a Function is visible in {{$memory.key}} placeholders in the workflow and vice versa — it is a single memory per user, not a parallel copy.
Automatically available when the request comes from an active conversation and the company has a workflow API key configured.
Typical use cases:
- Multi-step flows — remember which step the user is on
- Shopping carts — accumulate products during the conversation
- Counters — limit login attempts, retry tracking
- User preferences — language, format, filters that persist across conversations
Quick start
index.ts
Check availability
Primitives vs JSON
Useset()/get() for simple values and setJson()/getJson() for objects:
get() matches the type of the default value:
TTL (time to live)
There are two expiration layers in Memory:- Per-variable TTL (the one you pass to
set) — controls when that individual variable expires. - 30-day hashTTL (managed by the platform) — controls when the user’s entire memory expires. When it elapses, all of their Memory is wiped.
Limits
Values from
set() that exceed 255 characters throw an Error. For larger data, use setJson().
Common patterns
- Multi-step flow
- Shopping cart
- Attempt limit
Error handling
When to use ctx.memory vs a database?
Accessing another user’s memory
From cron or event triggers, you can access a specific user’s memory withctx.memory.for(userId):