MIVORA Start learning free

Agent Frameworks

LangGraph, PydanticAI, CrewAI — they hand you the loop, state, retries, and tracing as reusable parts. They add structure, not new powers.

Building with AI · Lesson 21 · 11 min read

You’ve now hand-built an agent loop (L19) and bolted on guardrails (L20). Starting your next, bigger project, you notice you’re about to re-write the same plumbing — the loop, tool wiring, retries, logging, state — all over again. And a teammate wants two agents to collaborate. Re-coding this every time is wasteful and error-prone. Agent frameworks exist so you don’t have to. But which one, and what do they actually give you that you couldn’t already build?

A framework is reusable plumbing, not new powers

Everything from the last two lessons — the loop, tool wiring, state between steps, retries, error handling, tracing, coordinating multiple agents — is plumbing you’d otherwise rebuild each time. A framework packages it as tested building blocks with sensible conventions and built-in observability. The point to hold onto: a framework gives you no capability the model itself lacks. Same model, same tools, same loop you already understand — just organized for you, so you write less boilerplate and get logging and structure for free.

Worked example
The same weather agent, two ways:
• Hand-rolled: you write the loop, the retry logic, the step budget, and the logging yourself.
• Framework: you declare the tools and the goal; the framework runs the loop, handles retries, enforces a step limit, and traces every step for you.
Identical behavior — the framework just absorbed the boilerplate you’d otherwise own.

Different frameworks, different emphases

Popular frameworks each optimize for a different need:
LangGraph models an agent as a graph / state machine — explicit nodes and edges for control flow. Great when the flow is complex or cyclic, and for checkpointing and human-in-the-loop pauses.
PydanticAI emphasizes type safety: structured outputs validated against a schema, plus a clean, Pythonic, dependency-injected style. Great when you need validated, typed results.
CrewAI focuses on role-based multi-agent “crews”: define agents with roles and tasks and have them collaborate. Great for quickly assembling a team of cooperating agents.
The pattern: each trades some raw flexibility for structure around one particular need.

When to use one — and when not

Don’t reach for a framework reflexively. For a simple agent — a few steps, one or two tools — a plain loop plus your own guards is fine and easier to debug. Frameworks earn their keep as complexity grows: many tools, branching control flow, multiple agents, production-grade tracing. Choose by the need (explicit control flow → a graph framework; validated outputs → a typed one; agent teams → a crew one), not by hype, and remember you can always drop back to plain code. Honest caveat: frameworks add a learning curve and abstraction that can hide what’s happening — which is exactly why understanding the underlying loop (you now do) is what lets you wield one well, or skip it on purpose.

An everyday analogy

Building the loop by hand is cooking from raw ingredients with your own knives: total control, but you do every step. A framework is a fully-equipped kitchen — stand mixer, food processor, labeled prep stations. It doesn’t make you a better cook or let you make a dish you fundamentally couldn’t; it just handles the repetitive prep so you focus on the recipe. And kitchens are organized for different cuisines: one laid out for precise, step-by-step baking (an explicit graph), one with strict plating standards (type-checked outputs), one built for a brigade of chefs working together (a multi-agent crew). For a quick sandwich, you don’t roll out the industrial kitchen at all.

Worked example
Matching four needs to the right choice:
1. A support agent that must branch and PAUSE for human approval before issuing a refund → a graph/state-machine framework (LangGraph) for explicit flow + human-in-the-loop.
2. An agent that must always return a strictly-typed, schema-validated record → a type-safe framework (PydanticAI).
3. A “research team”: a planner that delegates to a writer and a fact-checker → a role-based crew (CrewAI).
4. A 3-step script that calls one tool → no framework; a plain loop with your own guards.
Same models and tools throughout — the choice is purely about structure fitting the job.

This is the reading. The interactive version — active-recall quiz, a hands-on experiment you run in your own AI, and an earned mastery check — is free in the app.

Start this lesson free →