MESHFLOW_MOCK=1 python3 hands_on/09_conditional_routing.pyThis lesson teaches three ideas that make AI workflows reliable:
If you understand these three, you can read most agentic workflow diagrams.
An artifact is a named output from a workflow step.
Without artifacts, a workflow depends on vague memory:
The model did some research earlier. Now ask it to write the final answer.
With artifacts, the workflow has explicit state:
research_notes -> draft_answer -> review_score -> final_answer
Artifacts help because they are:
Good artifact names are specific and stable.
Weak names:
outputresulttextdatathingBetter names:
user_goalresearch_questionssource_notesdraft_answerquality_checkapproval_recordfinal_answerBeginner rule: if a downstream node depends on it, give it a real name.
An artifact contract says what a node promises to produce.
Example:
node: draft_answer
consumes: research_summary
produces: draft_answer
For structured systems, the contract can be more detailed:
draft_answer:
type: markdown
required_sections:
- summary
- evidence
- recommendation
Contracts reduce ambiguity. They also make quality checks easier.
DAG means Directed Acyclic Graph.
Directed means arrows have direction:
A -> B -> C
Acyclic means no loops that trap execution:
Bad:
A -> B -> A
Graphs matter because many workflows are not simple straight lines.
capture_goal
-> technical_research
-> market_research
-> synthesize
-> draft
-> review
The two research steps can run independently, then merge.
When you see a workflow graph, ask:
Do not start by reading every implementation detail. First understand the shape.
A gate is a hard stop. It prevents the workflow from continuing until a condition is satisfied.
Examples:
human_approval must be true before final output.quality_score must be at least 80.citations_present must be true.estimated_cost must be below budget.risk_tier must be low enough for automatic execution.Gates turn vague instructions into enforceable control points.
| Gate Type | Example | Use When |
|---|---|---|
| Human approval | "Manager approves final email" | Judgment or accountability matters |
| Quality threshold | score >= 0.8 | Output must meet a measurable standard |
| Policy gate | "No private data in answer" | Compliance matters |
| Budget gate | "Cost under $1.00" | Tool/model costs need limits |
| Safety gate | "No destructive tool call" | Actions can cause harm |
Beginners often see a blocked gate and think the workflow failed. Sometimes it did exactly what it should do.
draft created
review completed
approval required
workflow blocked
That is a safe pause, not a crash.
Run:
python3 -m src.mini_meshflow run examples/03_agent_with_gate.json
Find:
Then open the workflow file:
examples/03_agent_with_gate.json
Change the gate approval value from false to true, then run again. Observe how the final node becomes reachable.
Workflows can branch when different steps do not depend on each other.
Example:
capture_goal
-> research_technical
-> research_business
-> research_risks
-> synthesize_all
Parallel branches are useful, but they create merge questions:
Good orchestration answers these questions explicitly.
Some gates should trigger revision instead of stopping forever.
draft_answer
-> quality_check
-> if pass: approval_gate
-> if fail: revise_answer
-> quality_check
Always add a retry limit:
maximum revisions: 2
Without a limit, the system can loop indefinitely.
Mistake 1: Using generic artifact names.
Correction: Name outputs based on their purpose.
Mistake 2: Creating circular dependencies.
Correction: Draw the graph and check that arrows move toward completion.
Mistake 3: Treating approval as a prompt instruction.
Correction: Use a real gate.
Mistake 4: Forgetting what happens after failure.
Correction: Decide whether the workflow stops, retries, routes to review, or returns a partial result.
Mistake 5: Letting parallel branches overwrite each other.
Correction: Give each branch distinct artifacts and define merge behavior.
Before running a workflow, check:
Artifacts make outputs explicit. DAGs make execution order safe. Gates make risk and judgment enforceable. Together, they turn agentic behavior into a workflow that people can inspect, debug, and trust.
python3 -m src.mini_meshflow run examples/03_agent_with_gate.json
Find the blocked node and explain why it stopped.
Open ../../examples/03_agent_with_gate.json and change:
"approved": false
to:
"approved": true
Run the workflow again and observe the final node.