Variable Store system
The Variable Store is the mechanism for passing data between activities within a workflow and persisting state. Think of it as a key-value store scoped to each workflow execution, where every activity can read from and write to shared data. Understanding the variable store is crucial for building effective workflows. It’s how context flows through your workflow, how agents share information, and how decisions are made based on accumulated data.How the variable store works
The variable store provides a shared data layer for workflow execution.Workflow starts
A new variable store is created for the workflow execution. It starts empty except for the trigger input data.
Activities execute and write
As each activity completes, its output is automatically stored in the variable store under the activity’s name:
Data accumulates
As the workflow progresses, more data accumulates in the variable store, creating rich context for later activities.
Each workflow execution has its own isolated variable store. Multiple concurrent executions of the same workflow don’t share data — each has its own independent context.
Setting variables
Variables are written to the store automatically by activity outputs, but you can also set them explicitly.Automatic activity outputs
By default, each activity’s output is stored under the activity’s name: Activity name:document_extractor
Activity output:
Custom variable names via output mapping
Customize how activity outputs are stored: Output mapping:Manual variable setting within prompts
Agent prompts can explicitly set variables: Agent instruction:Getting variables
Access data from the variable store using the{{variable_path}} syntax.
Basic variable references
Syntax:{{key.nested.field}}
Examples:
Accessing arrays
Array element by index:Accessing objects
Object field:Default values
Provide default values if a variable doesn’t exist:Type checking
Check if a variable exists before using it:Variable scope
Variables exist at different scopes within a workflow.Workflow-level scope
Available throughout the entire workflow execution. Variables at workflow scope:- Trigger input:
{{trigger.input.*}} - All activity outputs:
{{activity_name.output.*}} - Custom variables set via output mapping
Branch scope (Condition and Parallel nodes)
Variables within branches have special considerations. Condition branches: Variables set within a branch are available downstream:Loop scope (ForEach nodes)
Special variables available only within ForEach loops. Loop-specific variables:Sub Use Case scope
Child workflows have their own isolated variable stores. Parent workflow variable store:Variable store structure
Understanding the structure helps you access data efficiently.Complete variable store example
Accessing nested data
Use cases
Understanding when and how to use the variable store effectively.Passing context between distant nodes
Scenario: A node late in the workflow needs data from an early node.Accumulating results from parallel branches
Scenario: Multiple agents analyze the same document; combine their insights.Building up a final report
Scenario: Accumulate findings throughout the workflow for a final report.Conditional routing based on accumulated data
Scenario: Route based on multiple factors from different activities.Cross-execution persistence
The variable store is normally scoped to a single workflow execution, but you can persist data across multiple runs.Workflow-level state
For state that needs to persist across workflow runs, use external storage: Pattern:Use cases for persistent state
Running totals
Accumulate totals across multiple workflow runs.Example: Track total processed invoices, cumulative amounts
State machines
Maintain state across workflow executions.Example: Customer onboarding progress (stage 1 → stage 2 → stage 3)
Historical context
Access results from previous executions.Example: Compare current analysis to previous runs for trend detection
Caching
Store computed results for reuse in future executions.Example: Cache customer research that doesn’t change frequently
Implementation with HashiCorp Vault
MagOneAI integrates with HashiCorp Vault for secure persistent storage: Store data:Best practices
Use descriptive variable names
Use descriptive variable names
Choose variable names that indicate source and content.Good:
compliance_agent.risk_assessmentdocument_extractor.extracted_textfinancial_analysis.total_amount
result1outputdata
Structure activity outputs consistently
Structure activity outputs consistently
Use consistent output structures across similar activities. This makes workflows easier to understand and maintain.Standard structure:
Check variable existence before use
Check variable existence before use
Always verify variables exist before using them in conditions or expressions:
Use output mapping for cleaner variable names
Use output mapping for cleaner variable names
Instead of deeply nested paths, map to cleaner top-level variables:Then use:
{{customer_email}} instead of {{agent.output.customer.contact.primary_email}}Document variable contracts
Document variable contracts
For reusable workflows (Sub Use Cases), document the expected input variables and guaranteed output variables. This is the workflow’s “contract.”Example:
Minimize data stored in variables
Minimize data stored in variables
Don’t store large documents or images directly in variables. Store URLs or references instead.Good:
{{document_url}}
Poor: {{base64_encoded_document}} (can be megabytes)Use semantic keys for parallel branches
Use semantic keys for parallel branches
Name parallel branches semantically so their outputs are self-documenting:
Debugging with the variable store
The variable store is your primary debugging tool for workflows.Viewing variable store in execution history
For any completed or running workflow execution:- Open execution details in MagOneAI Studio
- Navigate to “Variable Store” tab
- See the complete variable store state at each activity
- Initial state (trigger input)
- State after each activity
- Final state
- Variables that were read vs written at each step
Common debugging patterns
Problem: Activity not receiving expected input → Check variable store before the activity. Does the variable exist? Is the path correct? Problem: Condition routing incorrectly → Check variable store at the Condition node. What values is it comparing? Problem: Missing data in final output → Trace backward through the variable store. Which activity should have set this variable? Did it run? Did it produce output? Problem: Parallel branches not working as expected → Check variable store after parallel completion. Did all branches complete? Are outputs structured correctly?Conversational memory (Mem0)
In addition to the per-execution variable store, MagOneAI supports conversational memory powered by Mem0. This enables agents to remember facts, preferences, and context across multiple workflow executions.How Mem0 memory works
When an agent hasuse_memory: true in its capabilities config:
- Memory retrieval — Before the agent executes, relevant memories are retrieved based on the user ID, organization, and project
- Context injection — Retrieved memories are added to the agent’s prompt, giving it awareness of past interactions
- Memory extraction — After the agent completes, new facts and preferences are extracted from the conversation and stored
Memory scope
Memories are scoped by:- User ID — Memories are associated with the user who triggered the workflow
- Organization ID — Memories are isolated to the organization
- Project ID — Memories are scoped to the project
- Agent ID (optional) — Memories can be further scoped to a specific agent
When to use conversational memory
- Customer support agents — Remember customer preferences and past issues
- Personal assistants — Retain user preferences across sessions
- Onboarding flows — Remember progress and context from previous interactions
Conversational memory (Mem0) is different from the variable store. The variable store is scoped to a single execution and holds workflow data. Mem0 memory persists across executions and holds user-level facts and preferences.
Next steps
Agent node
Learn how agents read from and write to the variable store
Condition node
Use variable store data in conditional routing
Parallel node
Understand how parallel outputs merge into the variable store
ForEach node
Access special loop variables in the variable store