Examples
These complete programs show how Flow handles interactive tasks, branching, validation, reusable context, and agent work. Each listing is loaded directly from the repository's examples folder, so the documentation always reflects the current program.
| Example | What it demonstrates |
|---|---|
| Strict execution order | Pausing for answers, choosing one branch, and stopping at RETURN |
| Treasure Island | Nested decisions and state that changes as a workflow progresses |
| Bug report intake | Validation, severity triage, reusable context, and structured agent output |
| Launch planner | Defaults, conditional agent work, risk review, and an approval gate |
Strict execution order
This small diagnostic workflow makes the execution sequence visible. It pauses at each ASK, runs only the reached branch, and finishes with RETURN.
# A small interactive test for strict execution order.
PRINT "ORDER 1: The flow started."
ASK "ORDER 2: What is your name?" AS name
PRINT "ORDER 3: The first answer was received. Your name is:"
PRINT @name
ASK "ORDER 4: Choose tea or coffee. Type exactly: tea or coffee" AS drink
PRINT "ORDER 5: The drink answer was received. The branch runs next."
IF @drink == "tea"
PRINT "ORDER 6A: The tea branch ran. The coffee branches must not appear."
ELSE
IF @drink == "coffee"
PRINT "ORDER 6B: The coffee branch ran. The tea branch must not appear."
ELSE
PRINT "ORDER 6C: The fallback branch ran because the answer was neither tea nor coffee."
PRINT "ORDER 7: The drink branch finished."
ASK "ORDER 8: Should the flow finish successfully? Type exactly: yes or no" AS finish
IF @finish == "yes"
PRINT "ORDER 9A: Yes branch selected."
ELSE
PRINT "ORDER 9B: No branch selected."
PRINT "ORDER 10: All questions and branches are complete."
RETURN "ORDER 11: The flow returned and must execute nothing else."Treasure Island
Flow can also express interactive experiences. This game combines nested choices with a score that changes as the player explores a path.
# A simple interactive Flow game.
PRINT "Welcome to Treasure Island!"
ASK "What is your name?" AS name
PRINT "Hello, adventurer:"
PRINT @name
SET score = 0
ASK "You reach a fork in the road. Choose exactly: forest or cave" AS path
IF @path == "forest"
PRINT "You enter the forest and find a locked wooden chest."
SET score = @score + 1
ASK "Choose exactly: open or leave" AS forest_action
IF @forest_action == "open"
PRINT "A friendly owl gives you the key. You found the treasure!"
SET score = @score + 4
ELSE
PRINT "You leave safely, but the treasure remains hidden."
ELSE
IF @path == "cave"
PRINT "You enter the cave and hear a sleeping dragon."
SET score = @score + 1
ASK "Choose exactly: sneak or run" AS cave_action
IF @cave_action == "sneak"
PRINT "You quietly pass the dragon and find a bag of gold!"
SET score = @score + 3
ELSE
PRINT "You escape safely before the dragon wakes up."
ELSE
PRINT "You chose an unknown path and returned home safely."
PRINT "Game over. Your final score is:"
PRINT @score
IF @score >= 4
PRINT "You are a master treasure hunter!"
ELSE
PRINT "Try again and choose a different path."
RETURN "Thanks for playing Treasure Island!"Bug report intake
This practical workflow collects required details in order, rejects invalid answers, calculates severity, and gives an agent explicit context for producing a consistent Markdown report.
# Real-world example: collect and triage a software bug consistently.
CONTEXT
Produce a concise Markdown bug report with these sections in this order:
Title, Severity, Environment, Steps to reproduce, Expected behavior,
Actual behavior. Use only the supplied information and do not invent facts.
AS report_format
PRINT "Bug intake started. I will collect the required details in order."
ASK "Enter a short bug title." AS title
IF @title == ""
RETURN "Bug intake stopped: a title is required."
ASK "Where does the bug happen? Type exactly: production, staging, or local" AS environment
IF @environment is anything other than production, staging, or local
RETURN "Bug intake stopped: the environment was invalid."
ASK "Does the bug prevent the user from completing the task? Type exactly: yes or no" AS blocked
IF @blocked is anything other than yes or no
RETURN "Bug intake stopped: the blocked answer was invalid."
ASK "List the steps needed to reproduce the bug." AS steps
ASK "What should have happened?" AS expected
ASK "What actually happened?" AS actual
SET severity = "low"
IF @environment == "production"
IF @blocked == "yes"
SET severity = "critical"
ELSE
SET severity = "high"
ELSE
IF @blocked == "yes"
SET severity = "medium"
PRINT "All required information was collected. Generating the report now."
DO Create the Markdown bug report using @title, @severity, @environment,
@steps, @expected, and @actual. Follow @report_format exactly and return
only the completed report as a string. AS bug_report
PRINT @bug_report
RETURN "Bug intake completed."Launch planner
This larger example combines exact input validation with open-ended agent work. It selects a schedule, optionally reviews risk, prepares a brief, and waits for approval before producing the final checklist.
# Interactive feature launch planner
PRINT "Let us create a launch plan."
ASK "What feature or product are you planning to launch?" AS feature
IF @feature == ""
RETURN "A feature or product name is required."
ASK "Who is the main audience? Leave this empty to use general users." AS audience
IF @audience == ""
SET audience = "General users"
ELSE
PRINT "The audience has been recorded."
ASK "Choose the launch pace. Type exactly urgent or normal." AS pace
IF @pace != "urgent" AND @pace != "normal"
RETURN "The launch pace must be urgent or normal."
DO Define a focused launch scope for @feature and @audience.
Return an object with summary, included, and excluded fields. AS scope
PRINT @scope
IF @pace == "urgent"
DO Create an accelerated launch schedule from @scope.
Return an object with phases, deadlines, and warnings fields. AS schedule
ELSE
DO Create a standard launch schedule from @scope.
Return an object with phases, deadlines, and warnings fields. AS schedule
ASK "Should the plan include a risk review? Type exactly yes or no." AS risk_choice
IF @risk_choice != "yes" AND @risk_choice != "no"
RETURN "The risk-review answer must be yes or no."
IF @risk_choice == "yes"
DO Assess the launch risks using @scope and @schedule.
Return an object with status, risks, and mitigations fields. AS risk_review
ELSE
SET risk_review = {"status": "skipped", "risks": [], "mitigations": []}
DO Create a concise launch brief using @feature, @audience, @scope,
@schedule, and @risk_review. Return an object with overview,
action_items, and recommendation fields. AS launch_brief
PRINT @launch_brief
ASK "Do you approve this launch brief? Type exactly yes or no." AS approval
IF @approval != "yes" AND @approval != "no"
RETURN "The approval answer must be yes or no."
IF @approval == "yes"
DO Convert @launch_brief into an ordered launch checklist.
Return an array of short checklist items. AS next_steps
PRINT @next_steps
RETURN "The launch plan is approved."
ELSE
DO Identify three specific questions that would improve @launch_brief.
Return an array of questions. AS revision_questions
PRINT @revision_questions
RETURN "The launch plan needs revision."Ready to write one? Continue with the quick start or keep the command reference nearby.