AI Agent Tutorial#

A series on building a minimal AI Agent from scratch. Using the Anthropic Claude SDK + Python, we start from a minimal agent loop and progressively add real tools, MCP, multi-turn conversation, persistence, context management, and RAG long-term memory. No LangChain.

Full source code: github.com/codereindeer-dev/minimal-agent

Chapters#

What you will learn#

  • The core architecture of an AI Agent — Executor + Message + Memory + Loop, derived from first principles so you can see why every piece has to exist.
  • The truth about tool calling — not magic; just a JSON tool definition for the Model to read plus a Python function for the Executor to run.
  • MCP (Model Context Protocol) — the “USB standard” for tools; community MCP servers are plug-and-play and reusable across clients.
  • Multi-turn REPL — an Agent class that keeps a messages list across turns, plus asyncio for the interactive UI.
  • Context window management — Rolling Summary that compresses old turns into a summary message while keeping tool_use / tool_result pairs intact; /compact for manual compression.
  • Conversation persistence/save writes the messages list to a JSON file, /load reads it back, --resume continues a conversation across sessions.
  • RAG long-term memoryremember / recall tools accumulate facts across sessions: Voyage AI embedding + cosine similarity + JSONL append-only store.

Who this is for#

  • You already know Python basics (if not, start with the Python Tutorial).
  • You want to understand what’s actually happening under LangChain / LlamaIndex / AutoGen.
  • You want to write your own agent without memorizing a pile of framework APIs.
  • You want to understand the common core architecture behind Claude Code, Cursor, and ChatGPT plugins.