Skip to main content

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

ctx.memory.available is false when the request does not come from an active conversation or the workflow API key is not configured. Calling methods on an unavailable client throws an Error.

Primitives vs JSON

Use set()/get() for simple values and setJson()/getJson() for objects:
The return type of get() matches the type of the default value:

TTL (time to live)

There are two expiration layers in Memory:
  1. Per-variable TTL (the one you pass to set) — controls when that individual variable expires.
  2. 30-day hashTTL (managed by the platform) — controls when the user’s entire memory expires. When it elapses, all of their Memory is wiped.
hashTTL renewal from ctx.memory: writes through ctx.memory only initialize the hashTTL when the user’s memory is empty; subsequent writes do not extend it. Writes through $memory in the builder do extend the hashTTL on every write. If your flow persists exclusively through Functions and needs continuous activity, combine with at least one write from the builder.
The per-variable TTL is specified in seconds:

Limits

Values from set() that exceed 255 characters throw an Error. For larger data, use setJson().

Common patterns

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 with ctx.memory.for(userId):
ctx.memory.for() only works from cron or event triggers. In regular HTTP requests, ctx.memory is already bound to the current user’s session — calling .for() throws an error.