Skip to content

Lab: M19: build the same agent in many frameworks

You'll need: your venv (Python 3.10-3.12: several frameworks don't support newer yet), your .env key, and a pip install per framework you run. Live runs cost a few tokens. Time: ~55 minutes • Work in your breakout pair.

Heads up: the agent is the same every time: one tool multiply(a, b), asked "What is 23 times 17?", and the answer is always 391. What changes is only how you spell it in each framework. You'll run the two verified anchors and read the rest (running all nine would just spend tokens to print "391" eight more times). Read 01_from_scratch.py first.

This lab has three parts: - Part A: run the two anchors (from-scratch + LangGraph) and confirm they agree. - Part B: read three more frameworks side-by-side; find what's identical. - Part C: wire the no-code n8n agent, or add a framework of your own.

flowchart TB
  T["task: 23 × 17?"] --> L{{"the SAME loop:<br/>ask → tool? → feed back → repeat"}}
  L --> A["from scratch"]
  L --> B["LangGraph"]
  L --> C["CrewAI"]
  L --> D["AutoGen"]
  L --> E["Claude Agent SDK"]
  L --> F["smolagents"]
  L --> G["LlamaIndex"]
  L --> H["OpenAI Agents SDK"]
  L --> I["n8n (no-code)"]
  A & B & C & D & E & F & G & H & I --> ANS["391"]

Part A: run the two anchors

Step 1: Set up

Copy the solution/ files and starters/.env.example into a folder. Activate a Python 3.10-3.12 venv. Copy .env.example to .env and paste your key.

python --version            # expect 3.10, 3.11, or 3.12
pip install anthropic python-dotenv
cp .env.example .env        # then edit .env and paste your key
You should now see: a Python 3.10-3.12 version, the installs succeed, and a .env (never commit it).

Step 2: Run the from-scratch agent (the loop itself)

python 01_from_scratch.py
You should now see: an answer containing 391. Open the file: the while loop is the agent, ask the model, run multiply when it asks (stop_reason == "tool_use"), feed the result back, repeat. This is what every framework below does for you.

Step 3: Run the same agent in LangGraph

pip install langgraph langchain-anthropic
python 02_langgraph.py
You should now see: an answer containing 391 again, but the file is ~10 lines: @tool on multiply, create_react_agent(ChatAnthropic(...), [multiply]), agent.invoke(...). LangGraph wrote Step 2's loop for you. Same agent, same answer, less code.

What just happened: two totally different files produced the identical agent. The loop in Step 2 is hidden inside create_react_agent in Step 3. Hold that thought through Part B.


Part B: read three more, spot the sameness

You won't run these (tokens + installs); you'll read them. Open 03_crewai.py, 04_autogen.py, and 06_smolagents.py next to 01_from_scratch.py.

Step 4: Find the three steps in each

In every file, find the three lines that (1) define the tool, (2) make the agent, (3) run it. Use the table in ../notes.md §2 to check yourself.

You should now see: despite different class names, each file does the same three things in the same order. CrewAI dresses it as a "crew" doing a "task"; AutoGen as an async "assistant"; smolagents as a tiny ToolCallingAgent, but it's one multiply tool, one model, one run, every time.

Step 5: Spot the model-string gotcha

Compare the model string in 02_langgraph.py vs. 03_crewai.py and 06_smolagents.py.

You should now see: LangGraph uses bare claude-opus-4-8; CrewAI and smolagents use anthropic/claude-opus-4-8. Why? The second group routes through LiteLLM, which needs the provider/ prefix. Same model, different label. (Getting this wrong is the #1 "it won't connect" bug.)

Optional, pilot one live. If you want to prove a third framework works, pick one, install it (pip install crewai, or pip install "smolagents[litellm]"), and run it. Expect a few tokens spent and another 391. The solution README lists installs + verification status.


Part C: no-code, or your own

Step 6: Wire the same agent with NO code (n8n)

Open n8n (cloud or npx n8n locally). Workflows → Import from File → choose solution/n8n_workflow.json. Click the Anthropic Chat Model node and add your Anthropic credential (n8n stores the key in its credential vault, never paste it into the JSON). Click Execute Workflow.

You should now see: the canvas shows Trigger → AI Agent, with an Anthropic Chat Model and a multiply (Code Tool) feeding the agent, and running it returns 391. You just built the same agent with zero Python. (If a node name differs in your n8n version, drag in the equivalent AI Agent, Anthropic Chat Model, and Code Tool nodes and connect them the same way.)

Step 7: Show it

Pick one and post it in the chat: - the from-scratch loop's output next to LangGraph's (same 391, different code), or - your annotated find from Step 4 (the three steps circled in two frameworks), or - a screenshot of the n8n workflow returning 391, or - a framework you added yourself in starters/add_framework.py.


If you get stuck

  • python --version is 3.13/3.14 → make a 3.12 venv (python3.12 -m venv .venv); several frameworks lack newer wheels. See install-guides/python-venv.md.
  • "could not connect" / auth error in CrewAI or smolagents → you used the bare model id; LiteLLM needs anthropic/claude-opus-4-8 (Step 5).
  • ModuleNotFoundError → install that framework's package (see the solution table); each is a separate pip install.
  • An import path errors out → the framework's API moved between versions. Check its current docs; the pattern (model + tools + run) is unchanged.
  • ANTHROPIC_API_KEY not set → your .env isn't named exactly .env, or the key line is wrong (M3 / api-keys.md).

Check yourself

What do ALL these frameworks have in common? They all run the same loop: ask the model → if it requests a tool, run it and feed the result back → repeat → final answer. `01_from_scratch.py` is that loop unhidden; the rest write it for you.
Why does CrewAI need `anthropic/claude-opus-4-8` but LangGraph needs `claude-opus-4-8`? CrewAI routes through LiteLLM, which uses `provider/model` strings. LangGraph's ChatAnthropic is a native integration, so it takes the bare model id. Same model, different label.
When would you pick CrewAI/AutoGen over LangGraph or smolagents? When you need multiple agents working together (crews, conversations, hand-offs), the M18 orchestration shapes. For a single agent with tools, the simpler single-agent frameworks are plenty.
Why learn the from-scratch loop if frameworks exist? When an agent misbehaves (loops, ignores a tool, burns tokens), the abstraction hides the cause. Knowing the raw loop lets you debug *any* framework, because they're all doing the same thing underneath.