Output Variables
Pass values between tasks with output_variable
An output_variable names a task’s result so later tasks can read it.
graph LR
A[🔍 Task A] -->|output_variable=research| S[📦 variables]
S -->|{{research}}| B[✍️ Task B]
classDef task fill:#8B0000,stroke:#7C90A0,color:#fff
classDef store fill:#6366F1,stroke:#7C90A0,color:#fff
class A,B task
class S storeQuick Start
- Store one task's output
Name the result with
output_variable.python from praisonaiagents import Agent, Task researcher = Agent(name="Researcher", instructions="Research the topic and list key facts.") research = Task( name="research", action="Research renewable energy trends", agent=researcher, output_variable="research_data", ) - Read it in the next task
Reference the stored value with
{{research_data}}in a later task’saction.python from praisonaiagents import Agent, Task, PraisonAIAgents writer = Agent(name="Writer", instructions="Write a short report.") report = Task( action="Write a report using {{research_data}}", agent=writer, context=[research], ) PraisonAIAgents( agents=[researcher, writer], tasks=[research, report], ).start()
How It Works
After any task completes — agent or handler — its raw output is stored under the given name in the team’s shared variables.
Reading Variables
Substitute a stored value directly in action or description with {{name}}.
from praisonaiagents import Agent, Task
writer = Agent(name="Writer", instructions="Write a report.")
Task(action="Summarise {{research_data}} in three bullets", agent=writer)Read the same value inside a handler or should_run with ctx.variables["name"].
from praisonaiagents import Task
def summarise(ctx):
return {"summary": ctx.variables["research_data"][:200]}
Task(name="summarise", handler=summarise)Inside parallel blocks
An output_variable set inside a parallel([...]) branch is visible to every step after the block, keyed by that exact name.
from praisonaiagents import AgentFlow, Task, WorkflowContext, StepResult, parallel
def score_a(ctx: WorkflowContext) -> StepResult:
return StepResult(output="9")
def score_b(ctx: WorkflowContext) -> StepResult:
return StepResult(output="7")
compare = Task(action="Compare {{branch_a_score}} and {{branch_b_score}}")
workflow = AgentFlow(steps=[
parallel([
Task(name="branch_a", handler=score_a, output_variable="branch_a_score"),
Task(name="branch_b", handler=score_b, output_variable="branch_b_score"),
]),
compare,
])
workflow.start("go")If two branches use the same output_variable, the later-declared branch wins and a warning is logged — give them distinct names. See Named outputs from branches for the full merge rule.
Best Practices
Name variables for what they hold
Use clear names like research_data or score so downstream {{name}} references read naturally.
Set output_variable on the producing task
Attach output_variable to the task that creates the value, not the one that reads it.
Order dependent tasks with context
Pass context=[producer_task] on the consumer so the team runs them in the right order.