Title: Lab 7 — Two Agents, Two Mental Models
Course: AIINFRA 300: Agentic AI & the Model Context Protocol (MCP) > Section: Week 07 — Code-First Agent Frameworks I: LangGraph and Pydantic AI

🛠️ Lab 7 — Two Agents, Two Mental Models (50 pts)

Goal: Build a small Pydantic AI agent and a small LangGraph agent, both powered by free/local tooling, so you can directly compare how each framework handles structured output, tool calls, and control flow. Steps:

1. Install a local model runtime. Install Ollama locally and pull a small model (e.g. ollama pull llama3.1 or another model that fits your machine). Confirm it runs with ollama run <model> before writing any Python.
2. Set up your Python environment. Create a virtual environment and install pydantic-ai and langgraph (pip install -U pydantic-ai langgraph). Confirm Python 3.10+ with python --version.
3. Build the Pydantic AI agent. Define a Pydantic BaseModel as your structured result type (e.g. a MovieReview or TaskSummary with a couple of typed fields). Create an Agent pointed at your local Ollama model, and register one custom tool function (e.g. a simple lookup or calculation) using the agent's tool decorator.
4. Break it on purpose, then watch validation catch it. Temporarily loosen a field type or feed the agent a prompt likely to produce malformed output, run it, and capture the validation error Pydantic AI raises. Then fix it and confirm a clean run produces a valid, typed result.
5. Build the LangGraph agent. In a notebook (local Jupyter or Google Colab, using the free Gemini tier or local Ollama as the model), define a minimal TypedDict state, a model node, and a tool node. Wire them together with StateGraph, add the edges (including at least one conditional edge that routes back to the model node after a tool call), and compile the graph with an in-memory checkpointer.
6. Trace the control flow. Run the LangGraph agent on 2–3 inputs and print or log the state after each node executes. Note in your own words where state updates happen and how that differs from the Pydantic AI agent's single call to agent.run().
7. Write up the comparison. In 200–300 words, describe what surprised you about each framework, and state which one you'd reach for first for your own capstone workflow and why.

Deliverables: Submit your Pydantic AI script, your LangGraph notebook/script, a screenshot or pasted log showing the caught validation error, and your written comparison — either as an upload (zip or linked repo) or pasted directly into the text entry box.