> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jelou.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Context

> Context variables: temporary data from the current execution and system variables

You use context to store variables that persist only during the current execution — that is, they only live within the specific flow where you create them. If you need to store data that lasts up to 24 hours, use [Memory](/guides/variables/memory).

Think of context as a temporary whiteboard: every time a user starts a conversation, you get a fresh, clean whiteboard. Everything you write on it is available to all nodes in the flow, but when the conversation ends, the whiteboard is erased.

## System variables

When an execution starts, Brain Studio automatically injects system variables into the context. You can access them in all nodes without needing to declare them.

### executionId

Each workflow execution receives a unique identifier called `executionId`. Brain Studio generates it automatically when the flow starts and it remains constant throughout the entire execution, including branches between Workflows and calls to Tools.

```
{{$context.executionId}}
```

<Note>
  The `executionId` is read-only. Brain Studio generates it automatically at the start of each execution; you do not need to create or modify it.
</Note>

#### What it's used for

The `executionId` lets you uniquely identify each execution of your flow. This is useful when you need to:

* **Connect external systems**: Send the ID to your backend so it can track or correlate the conversation with your internal records.
* **Resume paused executions**: When an AI Agent pauses waiting for an external response (for example, an approval), the external system needs the `executionId` to resume the correct execution.
* **Auditing and traceability**: Record in your databases which execution generated each action, making it easier to track and troubleshoot.

#### Example: Sending to an external API

Suppose your flow queries an external service and you need that service to know which execution to respond to. In an **API** node, you can include the `executionId` in the request body:

```json theme={null}
{
  "orderId": "{{$context.orderId}}",
  "callbackExecutionId": "{{$context.executionId}}",
  "action": "process_payment"
}
```

Your external service receives the `callbackExecutionId` and uses it to send the response back to the correct execution.

#### Example: Resuming a paused AI Agent

When you configure an AI Agent with **external resumption pause**, the resumption payload requires the `executionId` to identify which execution to continue:

```json theme={null}
{
  "executionId": "{{$context.executionId}}",
  "message": "Payment approved successfully",
  "pauseInteraction": false
}
```

#### Example: Saving to Datum for auditing

In a **Datum** node, you can save the `executionId` along with the operation data to have full traceability:

```json theme={null}
{
  "user": "{{$user.name}}",
  "action": "credit_request",
  "executionId": "{{$context.executionId}}",
  "date": "{{$context.currentDate}}"
}
```

That way, if you need to investigate what happened in a specific conversation, you can search by `executionId` in your database and see exactly which steps were executed.

#### In code nodes

Inside a **Code** node, you access the `executionId` just like any other context variable:

```js theme={null}
const executionId = $context.get('executionId')

$output.set('log', `Processing execution: ${executionId}`)
```

## Custom variables

In addition to system variables, you can create your own context variables using **Variable** nodes, **Code** nodes, or any node that saves data to context (such as responses from interactive nodes).

### Reading variables

Inside any node you can access the context with the syntax `{{$context.variableName}}`. For example, if the variables in context are:

```json theme={null}
{
  "name": "John",
  "lastOrder": { "id": "ORD-123", "status": "on the way" }
}
```

Then:

* `{{$context.name}}` shows `John`.
* `{{$context.lastOrder.status}}` shows `on the way`.

### Context in code nodes

In code nodes, you use context methods differently:

* `$context.get(key, [defaultValue])` — Gets a value from context
* `$context.set(key, value)` — Saves or updates a value in context
* `$context.getHttpResponse(key)` — Gets the full response from an HTTP node
* `$context.getHttpRequest(key)` — Gets the request sent by an HTTP node

To get context variables:

```js theme={null}
const name = $context.get('name')

const name = $context.get('name', 'John')
```

To save variables inside a code node:

```js theme={null}
$context.set('lastOrder.status', 'delivered')

const user = { name: 'John', plan: 'gold' }
$context.set('user', user)

const orders = ['ORD-123', 'ORD-456']
$context.set('orders', orders)
```

<Tip>
  You can use dot notation to access nested keys in context. For example, `$context.get('lastOrder.status')` returns `"on the way"` without needing to retrieve the entire object.
</Tip>

## Context vs Memory

| Feature              | Context (`$context`)                   | Memory (`$memory`)                       |
| -------------------- | -------------------------------------- | ---------------------------------------- |
| **Duration**         | Current execution only                 | Up to 24 hours                           |
| **Scope**            | All nodes in the flow                  | All flows for the user                   |
| **Typical use**      | Temporary conversation data            | Data that persists between conversations |
| **System variables** | `executionId` (injected automatically) | None                                     |

<Tip>
  If you're unsure whether to use context or memory, ask yourself: **do I need this data after the conversation ends?** If yes, use [Memory](/guides/variables/memory). If you only need it during the current conversation, use Context.
</Tip>
