Skip to main content

Cheatsheet

A quick reference for Graflow syntax and APIs.

Tasks

SyntaxPurposeLearn More
@taskConvert function to taskYour First Task
@task(task_id="id")Set explicit task identifierYour First Task
@task(inject_context=True)Access channels/workflow controlChannels and Context
@task(inject_llm_client=True)Direct LLM API callsChannels and Context
@task(inject_llm_agent="name")Inject SuperAgent with toolsChannels and Context
task.run(param=value)Test task directlyYour First Task
task(task_id="id", param=value)Create task instance with bound parametersTask Instances

Workflows

SyntaxPurposeLearn More
with workflow("name") as wf:Define workflow contextYour First Workflow
task_a >> task_bSequential executionTask Composition
task_a | task_bParallel executionTask Composition
chain(task_a, task_b, task_c)Create sequential chainTask Composition
parallel(task_a, task_b, task_c)Create parallel groupTask Composition
group.set_group_name("name")Rename parallel groupTask Composition
group.with_execution(policy=...)Set error handling policyTask Composition

Execution

SyntaxPurposeLearn More
wf.execute()Execute workflow (auto-detect start)Execution Patterns
wf.execute(start_node="task_id")Start from specific taskExecution Patterns
wf.execute(initial_channel={...})Set initial parametersPassing Parameters
wf.execute(ret_context=True)Return (result, context) tupleExecution Patterns

Channels

SyntaxPurposeLearn More
ctx.get_channel()Access key-value channelChannels and Context
channel.set(key, value)Store a valueChannels and Context
channel.set(key, value, ttl=300)Store with expiration (seconds)Channels and Context
channel.get(key)Retrieve a valueChannels and Context
channel.get(key, default=val)Retrieve with fallbackChannels and Context
channel.append(key, value)Add to end of listChannels and Context
channel.prepend(key, value)Add to beginning of listChannels and Context
ctx.get_typed_channel(Schema)Type-safe channel accessChannels and Context
ctx.get_result(task_id)Retrieve specific task resultExecution Patterns

Dynamic Control Flow

SyntaxPurposeLearn More
ctx.next_task(task)Enqueue task, continue normallyDynamic Tasks
ctx.next_task(task, goto=True)Jump to task, skip successorsDynamic Tasks
ctx.graph.get_node("task_id")Get existing task from graphDynamic Tasks
ctx.next_iteration()Self-loop (retry/convergence)Dynamic Tasks
ctx.terminate_workflow()Exit successfullyDynamic Tasks
ctx.cancel_workflow(reason)Exit with errorDynamic Tasks

Human-in-the-Loop

SyntaxPurpose
ctx.request_feedback(feedback_type="approval", ...)Yes/No decision
ctx.request_feedback(feedback_type="text", ...)Free-form text input
ctx.request_feedback(feedback_type="selection", options=[...])Single selection
ctx.request_feedback(feedback_type="multi_selection", options=[...])Multiple selection

Prompt Management

SyntaxPurposeLearn More
PromptManagerFactory.create("yaml", prompts_dir=...)Create YAML prompt managerChannels and Context
ctx.prompt_managerAccess prompt managerChannels and Context
pm.get_text_prompt("name")Get text prompt templateChannels and Context
pm.get_chat_prompt("name")Get chat prompt templateChannels and Context
prompt.render(var=value)Substitute template variablesChannels and Context

Parallel Group Policies

PolicyBehaviorLearn More
"strict" (default)All tasks must succeedTask Composition
"best_effort"Continue even if tasks failTask Composition
AtLeastNGroupPolicy(min_success=N)At least N tasks must succeedTask Composition
CriticalGroupPolicy(critical_task_ids=[...])Only specified tasks must succeedTask Composition

LLM Integration

SyntaxPurpose
llm.completion_text(messages, model="...")Simple LLM completion
ctx.llm_clientAccess LLM client via context
ctx.register_llm_agent("name", agent)Register SuperAgent
ctx.get_llm_agent("name")Get registered agent
agent.run(query)Execute agent

Checkpoints

SyntaxPurpose
ctx.checkpoint(path="/path")Save checkpoint
ctx.checkpoint(path="s3://bucket/path")Save to S3
CheckpointManager.resume_from_checkpoint(path)Resume from checkpoint

Distributed Execution

SyntaxPurpose
group.with_execution(backend=CoordinationBackend.REDIS, ...)Enable Redis coordination
python -m graflow.worker.main --worker-id X --redis-host YStart worker

Tracing

SyntaxPurpose
LangFuseTracer(enable_runtime_graph=True)Create LangFuse tracer
workflow("name", tracer=tracer)Enable tracing for workflow