Lesson 22 ยท Intermediate

Agents and Agentic Workflows

Learn what makes an agent different from a simple chatbot and how multi-step workflows are coordinated.

Read the explanation carefully, then review the examples and coding section. The goal is to understand both the concept and how it appears inside a real application workflow.

Explanation

An agent can plan, use tools, inspect results, and continue until it reaches a goal or stopping condition.

Many so-called agents are really structured workflows with model calls inside them.

The most reliable agentic systems are constrained, observable, and designed around clear tasks.

Why this topic matters in practice

In generative AI products, the model is only one part of the system. The surrounding workflow determines whether the output is useful, safe, and maintainable. This lesson matters because it helps you connect the idea to tasks such as tutoring, search, copilots, business assistants, and production automation.

Examples

Research assistant

Search documents, extract facts, draft a summary, and cite the source passages.

Support triage

Classify the issue, retrieve policy, draft a response, and open a case if escalation is needed.

Course builder

Generate a lesson outline, check for missing sections, then produce a final draft.

A simple step-based agent loop

The code below is intentionally concise so the underlying pattern stays clear. It focuses on the application logic you can reuse, even if you later switch model providers or deployment environments.

steps = ["search", "extract", "draft"]

for step in steps:
    print("Running step:", step)
    # In a real agent, each step may call a model or tool.

print("Workflow complete.")

How the coding section works

  • This simple loop shows that many agent systems are orchestrated sequences, not magic autonomy.
  • Breaking an agent into steps improves control and debugging.
  • The more freedom an agent has, the more guardrails and observability it needs.

Implementation advice

When turning this lesson into a real feature, think beyond the code snippet itself. Decide what inputs should be allowed, how you will validate outputs, how you will recover from errors, and how you will measure whether the feature is actually helping users. Those surrounding choices often determine whether an AI feature feels polished or unreliable.

Summary / key takeaways

  • Agents are best understood as controlled workflows with reasoning and tools.
  • Clear step boundaries improve reliability.
  • Start with structured flows before adding more autonomy.

Exercises

  1. Design a three-step agent for a school FAQ assistant.
  2. Why might a fixed workflow be safer than a fully open-ended agent?
  3. What stopping conditions could you add to an agent loop?