> For the complete documentation index, see [llms.txt](https://whitepaper.aitech.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.aitech.io/agentforge/variables.md).

# Variables

Variables in Agent Forge act as a global store for data that can be accessed and modified by any block in your workflow. They provide a powerful way to share information between different parts of your workflow, maintain state, and create more dynamic applications.

{% hint style="info" %}
Variables allow you to store and share data across your entire workflow, making it easy to maintain state and create complex, interconnected systems.
{% endhint %}

## Overview

The Variables feature serves as a central data store for your workflow, enabling you to:

{% stepper %}
{% step %}

#### Store global data

Create variables that persist throughout workflow execution
{% endstep %}

{% step %}

#### Share information between blocks

Access the same data from any block in your workflow
{% endstep %}

{% step %}

#### Maintain workflow state

Keep track of important values as your workflow runs
{% endstep %}

{% step %}

#### Create dynamic workflows

Build more flexible systems that can adapt based on stored values
{% endstep %}
{% endstepper %}

## Creating Variables

You can create and manage variables from the Variables panel in the sidebar. Each variable has:

* **Name**: A unique identifier used to reference the variable
* **Value**: The data stored in the variable (supports various data types)
* **Description** (optional): A note explaining the variable's purpose

## Accessing Variables

Variables can be accessed from any block in your workflow using the variable dropdown. Simply:

1. Type `<` in any text field within a block
2. Browse the dropdown menu to select from available variables
3. Select the variable you want to use

{% hint style="info" %}
You can also drag the connection tag into a field to open the variable dropdown and access available variables.
{% endhint %}

## Variable Types

Variables in Agent Forge can store various types of data:

{% tabs %}
{% tab title="Text" %}

```
"Hello, World!"
```

Text variables store strings of characters. They're useful for storing messages, names, and other text data.
{% endtab %}

{% tab title="Numbers" %}

```
42
```

Number variables store numeric values that can be used in calculations or comparisons.
{% endtab %}

{% tab title="Boolean" %}

```
true
```

Boolean variables store true/false values, perfect for flags and condition checks.
{% endtab %}

{% tab title="Objects" %}

```json
{
  "name": "John",
  "age": 30,
  "city": "New York"
}
```

Object variables store structured data with properties and values.
{% endtab %}

{% tab title="Arrays" %}

```json
[1, 2, 3, "four", "five"]
```

Array variables store ordered collections of items.
{% endtab %}
{% endtabs %}

## Using Variables in Blocks

When you access a variable from a block, you can:

* **Read its value**: Use the variable's current value in your block's logic
* **Modify it**: Update the variable's value based on your block's processing
* **Use it in expressions**: Include variables in expressions and calculations

## Variable Scope

Variables in Agent Forge have global scope, meaning:

* They are accessible from any block in your workflow
* Any block can modify them
* Changes to variables persist throughout workflow execution
* Variables maintain their values between runs, unless explicitly reset

## Best Practices

* **Use Descriptive Names**: Choose variable names that clearly indicate what the variable represents. For example, use `userPreferences` instead of `up`.
* **Document Your Variables**: Add descriptions to your variables to help other team members understand their purpose and usage.
* **Consider Variable Scope**: Remember that variables are global and can be modified by any block. Design your workflow with this in mind to prevent unexpected behavior.
* **Initialize Variables Early**: Set up and initialize your variables at the beginning of your workflow to ensure they're available when needed.
* **Handle Missing Variables**: Always consider the case where a variable might not yet exist or might have an unexpected value. Add appropriate validation in your blocks.
* **Limit Variable Count**: Keep the number of variables manageable. Too many variables can make your workflow difficult to understand and maintain.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://whitepaper.aitech.io/agentforge/variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
