# Build Your First AI Agent

> A twelve-notebook course that builds an AI agent from scratch — a hand-rolled ~35-line agent loop, then RAG, MCP, structured outputs, memory, multi-agent orchestration, and evals layered on top. Works with any OpenAI-compatible provider.

URL: https://harshith.in/projects/build-your-first-ai-agent/
Author: Harshith Sunku (Staff Engineer) — https://harshith.in/about/
Source: https://github.com/harshithsunku/build-your-first-ai-agent
Stack: Python, Jupyter, LLMs, MCP, RAG

The whole course fits in one sentence: **an agent is just a loop plus a capability
table.** Notebook 02 builds that loop by hand in ~35 lines as an explicit state machine —
the model requests a tool by name and JSON arguments, your code executes it and feeds
the result back, `max_iterations` acts as a TTL against runaway loops. Notebooks 04–06
then reuse the *identical* loop with three different read-only capability tables: one
explores a codebase with `ls`/`cat`/`grep`, one triages logs, one queries SQLite. The
repetition is the lesson.

The back half cashes it in: RAG with a hand-rolled numpy vector store (retrieval is
just another tool), serving the same tools over MCP from a separate process, structured
outputs with Pydantic validation and retry, session memory with context-budget
summarization, a supervisor agent whose tools are the earlier specialist agents, and
finally LLM-as-judge evals plus prompt-injection guardrails.

Core notebooks depend only on the `openai` client (any OpenAI-compatible provider
works); one notebook rebuilds the same agent in LangChain/LangGraph so you can see
exactly what a framework buys you. Every notebook ships a Gradio `*_with_ui` twin with
a live agent-trace panel for demos.
