MESHFLOW_MOCK=1 python3 hands_on/03_policy_and_budget.pyThis lesson explains what an AI agent is, what a workflow is, and why strong systems often use both. By the end, you should be able to look at an AI idea and decide whether it should be built as:
Not every AI feature needs an agent.
Use a single LLM call when:
Example:
Summarize this paragraph in three bullets.
Use more structure when the task requires state, tools, decisions, or review.
An AI agent is a system that uses a model to pursue a goal by choosing actions, observing results, and continuing until it stops.
The agent loop:
observe -> decide -> act -> observe result -> decide again -> stop
An agent usually has:
Goal:
Find the best source in the course for explaining memory.
Possible loop:
The important part is that the agent chooses the next action instead of following one fixed prompt.
A workflow is an explicit process made of steps and dependencies.
Example:
capture goal
-> gather context
-> draft answer
-> check quality
-> request approval
-> publish final answer
Each step has a known job. The workflow controls order, inputs, outputs, and stopping points.
A workflow usually has:
| Question | Agent | Workflow |
|---|---|---|
| Who chooses the next action? | The agent loop | The workflow graph |
| Is the path predictable? | Less predictable | More predictable |
| Best for | Open-ended tasks | Repeatable processes |
| Main risk | Drift, loops, unsafe action | Rigid design, missed edge cases |
| Needs | Stopping rules and tool controls | Clear artifacts and dependencies |
Use an agent when the path is uncertain. Use a workflow when the process must be repeatable, auditable, or governed.
Production systems often place agents inside workflow boundaries.
workflow controls:
step order
artifacts
gates
budgets
trace
agent controls:
local reasoning
tool selection
drafting
exploration
Example:
capture_goal
-> researcher_agent
-> reviewer_tool
-> writer_agent
-> approval_gate
-> final_output
The agents do intelligent work, but the workflow still defines the production process.
Every agent needs a stopping rule. Without one, an agent can repeat itself, call tools too many times, or keep searching forever.
Common stopping rules:
Beginner rule: define the stop condition before you define the tools.
Agents are only as safe as their permissions. Give agents the smallest useful tool set.
Poor design:
research_agent can search, email customers, update database, deploy code
Better design:
research_agent can search read-only sources
writer_agent can draft text
reviewer_agent can score text
publisher_action requires human approval before sending
Separate roles reduce risk.
Artifacts make agent work visible. Instead of letting an agent think in a hidden conversation, require named outputs.
Examples:
research_questionssource_notesrisk_assessmentdraft_answerreview_scoreapproval_recordfinal_answerIf the artifact is named, downstream steps can depend on it and humans can inspect it.
Run a simple LLM workflow:
python3 -m src.mini_meshflow run examples/01_basic_llm.json
Run a tool and memory workflow:
python3 -m src.mini_meshflow run examples/02_tools_and_memory.json
Run an agent with a gate:
python3 -m src.mini_meshflow run examples/03_agent_with_gate.json
Ask:
Turn this vague request into a workflow:
Help me prepare a beginner training lesson on AI agents.
One possible workflow:
capture_goal
-> outline_lesson
-> collect_examples
-> draft_lesson
-> beginner_review
-> revise_lesson
-> approval_gate
-> publish
Now decide which steps should be agents:
outline_lesson: agent, because it designs structure.collect_examples: agent with search/read tools.beginner_review: tool or reviewer agent.approval_gate: not an agent; it is a hard workflow stop.Mistake 1: Calling every LLM feature an agent.
Correction: An agent chooses actions across a loop. A single prompt is not an agent.
Mistake 2: Giving agents too many tools.
Correction: Use role-specific tools and gates for risky actions.
Mistake 3: Hiding the process in one giant prompt.
Correction: Use workflow nodes and artifacts for important steps.
Mistake 4: Forgetting stopping rules.
Correction: Define limits, completion criteria, and failure behavior.
Mistake 5: Treating workflows as too rigid.
Correction: Put flexible agents inside controlled workflow steps.
An LLM generates text. An agent uses an LLM inside a goal-directed loop. A workflow defines a repeatable process. The strongest production pattern is often a workflow that contains agents, tools, memory, artifacts, gates, and traces.
For each item, decide whether it is a plain LLM call, an agent, a workflow, or a workflow containing an agent. Write a one-sentence justification for each.
and archive the result.
Check your answers in answers.md.
Write a three-step workflow for planning a study session. Use this format:
node_id -> node_id -> node_id
Then add artifact names:
node_id → produces: artifact_name
node_id (depends on: artifact_name) → produces: artifact_name
node_id (depends on: artifact_name) → produces: artifact_name
Expected output: a small table with three rows — one per node — listing id, dependency, and artifact.
Run the gated workflow:
python3 -m src.mini_meshflow run examples/03_agent_with_gate.json
Find the node that performs the most open-ended reasoning. Answer:
Take the workflow you designed in Exercise 2 and add a stopping condition:
Example format:
Done when: final_answer artifact is produced and quality_score > 0.8
Stopped when: research_step fails OR budget_exceeded gate blocks
Without using code, describe in five steps what the agent loop does inside the research_agent node in the gate example:
Step 1: receive ___
Step 2: reason about ___
Step 3: call tool ___ with input ___
Step 4: observe ___
Step 5: produce ___ and stop because ___
This exercise builds the habit of reasoning about what an agent is actually doing before you wire it into a workflow.