Chapter 24 of 32 · ~16 min read & lab+65 XP
Chapter 24 · Agentic AI

AI Agent Frameworks Compared: LangGraph vs. CrewAI vs. AutoGen vs. ADK vs. Pure Python

Cut through the framework hype with an engineering decision matrix comparing state graphs, role-based crews, conversational agents, ADK, and zero-dependency Python loops

What Is It?

An AI agent framework provides pre-built primitives for state management, tool dispatch, human-in-the-loop checkpoints, and multi-agent routing—trading low-level control for faster scaffolding.

Why Is It Required?

Picking the wrong framework either traps a production team inside leaky abstractions that are impossible to debug, or forces them to reinvent durable checkpointing and streaming from scratch.

Everyday Analogy: Choosing an agent framework is like choosing between building a kitchen cabinet from raw lumber (Pure Python), using modular IKEA frames (LangGraph / ADK), or buying a pre-assembled kitchenette (CrewAI).
Why ML Engineers & Data Scientists Actually Need This

'Would you use LangGraph, CrewAI, AutoGen, Google ADK, or pure Python for this system—and why?' is asked in almost every Senior Agentic AI interview.

ML / AI Engineer

You evaluate frameworks on production criteria—checkpoint durability, exact prompt visibility, streaming/HITL pause-resume, OpenTelemetry tracing, and upgrade stability—not GitHub stars.

Data Scientist

You ensure the orchestration layer emits clean, framework-agnostic trajectory logs so evals don't break if you swap frameworks later.

Interview & Debug Edge

Strong engineers never worship a framework. Explaining when Pure Python beats every framework (simple 1-agent loops) and when a durable state graph earns its keep (long-running HITL workflows) shows real production scar tissue.

Step 0 · Test Your Gut Before Any Math!

You need a single-agent support bot with 6 tools, strict JSON logging, and sub-second latency. Which stack gives the cleanest debugging and lowest overhead?

What You Will Master in This Chapter
  • Stateful Agent Graphs & Durable Execution
  • Multi-Agent Orchestration: Supervisor, Handoff & Swarm Patterns
Story-First Intuition, Visual Diagrams & Interactive Walkthroughs

Every agent framework is ultimately a wrapper around an LLM API call + a state object + a control loop. Before adopting any framework, ask: Which hard distributed-systems problem (checkpointing, HITL resume, multi-agent routing, streaming) is this framework actually solving for me?

1. Production Comparison Matrix (2026 Landscape)

StackCore AbstractionBest StrengthWatch-Out / Tradeoff
Pure Python / TSDirect SDK + while loop100% prompt control, zero magic, trivial debuggingYou build your own state persistence & HITL pause/resume
LangGraphExplicit cyclic state machine (Nodes + Edges)Fine-grained control, Postgres checkpointing, time-travel replaySteeper learning curve; verbose boilerplate for simple bots
Google ADK / OpenAI Agents SDKLightweight typed agents + handoffsClean Pythonic API, native MCP/A2A & realtime/streaming supportNewer ecosystems; verify multi-provider parity if required
CrewAIRole-playing agents + tasks + crewsFast prototyping for sequential content/research pipelinesHidden system prompts can make strict production tuning harder
AutoGen / AG2Event-driven & conversational multi-agentGreat for code-execution sandboxes & research debatesUnbounded multi-agent chatter can burn tokens if uncapped

2. The 4-Question Framework Selection Checklist

Ask these four questions before writing pip install:

  1. Can I inspect the exact raw prompt sent to the LLM? If a framework hides prompt templates behind magic strings, debugging hallucinations becomes painful.
  2. Does it support durable pause/resume? Essential if an agent waits hours for human approval or webhook callbacks.
  3. Are tools & evals decoupled from the framework? Keep your tool functions and business logic in plain Python modules so you can swap orchestrators in an afternoon.
  4. Is a single agent enough? 80% of production use cases work better as one well-tooled agent than a brittle 4-agent roleplay crew.
“Wait, I'm Confused...” · Teacher Office Hours Q&A

The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.

Always build a raw Python ReAct loop first (under 60 lines). Once you understand tool JSON parsing, message history, and loop termination from scratch, every framework becomes transparent instead of mysterious.

Interactive Visual Lab
Lab Challenge: Observe how explicit state graphs make branching, retries, and checkpointing deterministic.
Interactive Animation • 4.2 Deep Lab

Stateful Cyclic Graph & Durable Checkpoint Timeline

Every super-step merges partial updates via typed reducers and commits an immutable checkpoint snapshot.

cp_1
cp_1 → Agent Node
messages: [User, ToolCall(sql)] · step=1
cp_2 → Tool Node
messages: [..., ToolObs(42 rows)] · step=2
cp_3 → Agent Node
messages: [..., FinalAnswer] · step=3
cp_4 → END ✓
Persisted to Postgres Checkpointer (Replayable!)
0%
cp_1 · Agent Node
Intuition Takeaway: Start with Pure Python for simple single-agent loops; adopt an explicit state-graph or typed SDK (LangGraph, ADK, OpenAI Agents SDK) when you genuinely need durable checkpointing, HITL resume, or multi-agent protocols.
Production NumPy & PyTorch Code Patterns
# Architecture Decision Helper: Recommending the Right Agent Stack
def recommend_agent_stack(needs_durable_hitl: bool, num_specialists: int, needs_a2a_interop: bool, rapid_prototype: bool) -> str:
    if needs_a2a_interop:
        return "Google ADK / A2A-compatible SDK (native cross-agent protocol + typed tools)"
    if needs_durable_hitl:
        return "LangGraph or Temporal + Pure Python (durable state checkpoints & pause/resume)"
    if num_specialists == 1 and not rapid_prototype:
        return "Pure Python + Direct LLM SDK (maximum prompt control, lowest latency & maintenance)"
    if rapid_prototype and num_specialists > 1:
        return "CrewAI or OpenAI Agents SDK (fast multi-role scaffolding; harden before scale)"
    return "LangGraph (explicit cyclic state graph for deterministic multi-agent routing)"

print("Single support bot:", recommend_agent_stack(False, 1, False, False))
print("24h approval workflow:", recommend_agent_stack(True, 2, False, False))
print("Cross-org agents:", recommend_agent_stack(False, 3, True, False))
Common ML Interview Traps & Numerical Pitfalls
Trap #1: Defaulting to a multi-agent roleplay framework for a simple single-agent task
Best Practice: interviewers see this as unnecessary complexity and latency.
Trap #2: Coupling business logic and tool implementations tightly to framework-specific classes, making unit tests slow and migrations painful.
Best Practice: Design deterministic guardrails and verify with offline trajectory evals.
Chapter Mastery Check (+65 XP)
Score: 0 / 1
1When does a stateful graph framework like LangGraph clearly justify its added complexity over a 60-line pure Python agent loop?

Apply What You Learned — Solve Matching Coding Problems