Skip to main content

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​

  1. Click "Variables" in the left sidebar
  2. Click "+ Add New"
  3. 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")

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"
}
}
}
warning

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 TypeHow It WorksBest For
Buffer MemoryRemembers ALL messagesShort conversations
Buffer Window MemoryRemembers the last N messagesMost use cases (recommended)
Conversation Summary MemorySummarizes old messagesLong 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:

  1. Click on an Agent or LLM node
  2. Find the Memory toggle and enable it
  3. 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:

KeyValue
customerName(empty)
orderTotal0
approvedfalse

Step 2: Update state in any node

Most nodes have an "Update Flow State" option. For example, in an LLM node:

KeyValue
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.

  1. Variable: apiEndpoint = "https://api.mystore.com" (stored as a Variable)
  2. Flow State: orderId and orderStatus (declared in Start node)
  3. 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​

  1. Use Variables for anything that might change β€” API URLs, company names, feature flags
  2. Choose the right memory type β€” Buffer Window (last 10 messages) works for 90% of cases
  3. Keep Flow State minimal β€” only declare variables you actually need
  4. Name things clearly β€” customerEmail is better than email or e
  5. 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