Variables, Memory & State
This chapter covers three features that make your agents significantly smarter: Variables (reusable values), Memory (conversation history), and Flow State (shared data between nodes).
Variablesβ
Variables are reusable values that you define once and use across all your flows. Think of them as sticky notes with important information that any agent can read.
When to Use Variablesβ
- Store API endpoints that might change
- Keep configuration values separate from your flow logic
- Store values that differ between environments (development vs production)
Creating a Variableβ
- Click "Variables" in the left sidebar
- Click "+ Add New"
- Fill in:
- Name: A short, descriptive name (e.g.,
companyName) - Type: Static (you type the value) or Runtime (reads from environment variables)
- Value: The actual value (e.g., "Sweet Dreams Bakery")
- Name: A short, descriptive name (e.g.,
Using Variables in Your Flowsβ
In text fields (prompts, messages, descriptions):
Welcome to {{$vars.companyName}}! How can I help you?
In JavaScript code (Custom Tools, Custom Functions):
const company = $vars.companyName;
return `The company name is ${company}`;
Overriding Variables via APIβ
You can change variable values at runtime through the API:
{
"question": "Hello",
"overrideConfig": {
"vars": {
"companyName": "New Company Name"
}
}
}
Variable override must be enabled in Settings β Configuration β Security before it works via API.
Memoryβ
Memory is how your chatbot remembers previous messages in a conversation. Without memory, every message would be treated as a brand new conversation.
Types of Memoryβ
| Memory Type | How It Works | Best For |
|---|---|---|
| Buffer Memory | Remembers ALL messages | Short conversations |
| Buffer Window Memory | Remembers the last N messages | Most use cases (recommended) |
| Conversation Summary Memory | Summarizes old messages | Long conversations |
How Memory Works in Practiceβ
Without memory:
User: My name is Alex
Bot: Nice to meet you, Alex!
User: What's my name?
Bot: I don't know your name. Could you tell me? β Forgot!
With memory:
User: My name is Alex
Bot: Nice to meet you, Alex!
User: What's my name?
Bot: Your name is Alex! β Remembers!
Configuring Memory in Agentflowβ
In Agentflow, memory is built into the Agent and LLM nodes:
- Click on an Agent or LLM node
- Find the Memory toggle and enable it
- Choose the memory type:
- Buffer Window Memory: Set the window size (e.g., 10 messages)
- Conversation Summary Buffer: Set the max token limit
Ephemeral Memoryβ
The Start node has an "Ephemeral Memory" option. When enabled, the flow starts fresh every time β no memory of previous conversations. This is useful for:
- One-off tasks (like generating a report)
- Flows where context from previous runs would be confusing
Flow Stateβ
Flow State is the most powerful data-sharing mechanism in Agentflow. It's a shared notebook that all nodes in a single execution can read from and write to.
When to Use Flow Stateβ
- Pass data between nodes that aren't directly connected
- Store intermediate results (like a generated SQL query)
- Track progress through a multi-step workflow
- Share data across different branches of a conditional flow
How Flow State Worksβ
Step 1: Declare variables in the Start node
In the Start node, add your state variables with initial values:
| Key | Value |
|---|---|
customerName | (empty) |
orderTotal | 0 |
approved | false |
Step 2: Update state in any node
Most nodes have an "Update Flow State" option. For example, in an LLM node:
| Key | Value |
|---|---|
customerName | {{ output }} |
Step 3: Read state anywhere
In any node's text field, reference state variables:
Hello {{ $flow.state.customerName }}! Your order total is {{ $flow.state.orderTotal }}.
Important Rulesβ
- All state keys must be declared in the Start node
- You can only update existing keys β you can't create new ones mid-flow
- State only exists for the duration of one execution β it resets for each new conversation
- Each concurrent execution has its own independent state
Persist Stateβ
If you enable "Persist State" in the Start node, the state values carry over between messages in the same session. This is useful for multi-turn workflows where you build up information over several messages.
Putting It All Togetherβ
Here's an example that uses all three concepts:
Scenario: A customer support agent that collects information, checks an order, and responds.
- Variable:
apiEndpoint= "https://api.mystore.com" (stored as a Variable) - Flow State:
orderIdandorderStatus(declared in Start node) - Memory: Buffer Window Memory with 10 messages (on the Agent node)
Start (Flow State: orderId="", orderStatus="")
β
Agent (Memory enabled, uses $vars.apiEndpoint)
β Updates Flow State: orderId={{ output }}
β
HTTP Node (GET {{ $vars.apiEndpoint }}/orders/{{ $flow.state.orderId }})
β Updates Flow State: orderStatus={{ output.status }}
β
LLM (Responds using {{ $flow.state.orderStatus }})
The agent remembers the conversation (Memory), uses a configurable API URL (Variable), and passes the order ID between steps (Flow State).
Tipsβ
- Use Variables for anything that might change β API URLs, company names, feature flags
- Choose the right memory type β Buffer Window (last 10 messages) works for 90% of cases
- Keep Flow State minimal β only declare variables you actually need
- Name things clearly β
customerEmailis better thanemailore - Test state updates β use the Execution traces to verify state is being updated correctly
Congratulations! πβ
You've completed the Getting Started Guide! You now know how to:
- β Install and run CiniterFlow
- β Build AI Assistants, Chatflows, and Agentflows
- β Add knowledge from your documents
- β Connect tools and APIs
- β Embed chatbots on websites
- β Use the API from any application
- β Manage variables, memory, and state
Ready to build something real? Check out our Practical Projects section for step-by-step guides on building specific AI solutions!
π Build Projects