Skip to content
项目

Ramakm/agentic-ai-from-scratch

在 GitHub 查看

关于

Learn Agentic AI from sratch. Learn, build and Ship it for others.

人工智能与机器学习

这些数字如何统计

实测星标增长

24小时
+4
7天
正在收集历史
15天
正在收集历史
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Agentic AI from Scratch

Build AI agents from a raw while-loop and an HTTP call, before a single framework gets imported.
Tools, memory, planning, MCP, multi-agent systems, evals, and safety, written by hand and tested.

Website · Quick start · Choose a path · Curriculum · Interview prep · Roadmap

MIT License 16 phases 163 lessons Tests GitHub stars


Why build agents from scratch

Most agent material is framework tutorials. You can wire up a crew of five agents but can't say why the third one loops forever. You can install an MCP server but couldn't write the JSON-RPC message it answers.

This course goes the other way. Every pattern is built by hand first, in plain Python you can read in one sitting:

You build Before you use
A tool dispatcher with schema validation Native function calling, @function_tool
A ReAct loop in ~120 lines LangGraph, the OpenAI and Claude Agent SDKs
A vector store in ~80 lines pgvector, Chroma, LlamaIndex
An MCP server over stdio Off-the-shelf MCP servers
An orchestrator with parallel workers CrewAI, AutoGen, LangGraph Send
An eval harness and trace viewer LangSmith, Braintrust, OpenTelemetry backends
Injection defences, permission rules, an audit log Guardrail products and agent sandboxes

When the frameworks show up in Phase 9, you already know what they do under the hood, and when to skip them.

Quick start

You need Python 3.10+ and git. No API key, no GPU, and no model: every lesson runs offline first.

git clone https://github.com/Ramakm/agentic-ai-from-scratch.git
cd agentic-ai-from-scratch

# check your machine for the route you're starting (prints the fix for anything missing)
python3 phases/00-setup-and-tooling/01-your-agent-dev-environment/code/main.py

# run your first agent, against a scripted model
python3 phases/03-the-agent-loop/01-the-agent-loop-in-120-lines/code/main.py

Switch any lesson to a real model with two environment variables. Ollama, OpenAI, vLLM, LM Studio, OpenRouter and any other OpenAI-compatible server work:

ollama pull llama3.2
AGENT_BASE_URL=http://localhost:11434/v1 AGENT_MODEL=llama3.2 \
  python3 phases/03-the-agent-loop/01-the-agent-loop-in-120-lines/code/main.py

For a hosted API, also set AGENT_API_KEY. Lesson code reads keys only from the environment. The setup checker covers other routes too: --route real-model --ping, typescript, sandboxing and sdks. Run it with --list to see them, or read 00.01 Your agent dev environment.

How every lesson works

Each lesson follows the same four steps:

  1. The problem. A concrete failure, e.g. a model only returns text; ask it to book a flight and it describes booking one.
  2. Build it. Raw code, no framework, standard library wherever possible.
  3. Use it. The same idea in the production tools, so you can read what they're doing.
  4. Ship it. An artifact you keep: a tool, a prompt, an MCP server, or a skill your coding agent can load.

Every live lesson folder has the same shape:

phases/03-the-agent-loop/01-the-agent-loop-in-120-lines/
├── docs/en.md          the lesson
├── code/main.py        runnable, offline by default (scripted model)
├── code/test_main.py   unit tests, run in CI
├── quiz.json           6 questions: pre, check, post
└── outputs/            what you ship: skill-*.md, prompt-*.md

Lessons run offline by default against a scripted model, so they're deterministic and free, and the tests never touch the network. When a lesson shows model output, it's real output from a real run, failures included.

Ways to learn

  • On the website. Every lesson, with diagrams, quizzes, and progress saved in your browser: agentic-ai-from-scratch.vercel.app

  • With your coding agent as tutor. Install the skills into Claude Code, Codex, Cursor, or any agent that reads SKILL.md:

    npx skills add Ramakm/agentic-ai-from-scratch
    

    Then say: "Use start-building to begin the course."

    Skill What it does
    find-your-level 10-question placement quiz that maps you to a starting phase
    start-building Interviews you and writes BUILD.md, your personal build plan
    build Teaches the next lesson section by section, quizzes you, and reviews your code
    check-understanding Quizzes you on any phase or lesson
    debug-my-agent Reads your agent's trace or error and points to the lesson that fixes it
  • Locally. Clone the repo and work through phases/ in order. Every lesson's code/ runs on its own, and python3 -m unittest inside it runs its tests.

Learning paths

Path For Phases
01 · Building single agents Your first agent that actually finishes the job 01 → 06
02 · Tools, protocols & computer use MCP, browser and terminal control, coding agents 07, 10
03 · Multi-agent systems Orchestrators, handoffs, A2A, frameworks 08 → 09
04 · Reliable agents in production Evals, tracing, guardrails, durable execution, UX 11 → 15

Where to start

If you are… Start at
New to agents 00.01 Your agent dev environment
Shipping LLM apps already 02.02 Tool schemas from first principles
Here to build an agent from scratch 03.01 The agent loop in 120 lines
Going multi-agent 08.02 Orchestrator–worker
Securing an agent you already run 12.01 The agent threat model

Prerequisites: comfortable Python, and a terminal. No ML background needed.

Interview prep

50 agent engineering interview questions across 8 topics, from fundamentals to staff level: concept, debugging, design, trade-off, estimation and whiteboard-code questions. Each one has a short answer, a full answer, follow-ups with what a strong reply covers, the wrong answers interviewers hear most, and links to the lessons that teach it. The source lives in interviews/, one Markdown file per question.

Contents

16 phases · 163 lessons · 163 live · ~127 hours

Phase 00 · Setup & Tooling · 8 lessons · 8 live

A dev environment, local and hosted models, raw HTTP calls, streaming and tracing, all wired up before writing an agent.

# Lesson Status Time
00.01 Your agent dev environment ■ live 45 min
00.02 Python & TypeScript for agents ■ live 60 min
00.03 Running local models with Ollama ■ live 40 min
00.04 API keys, providers & rate limits ■ live 30 min
00.05 Calling an LLM over raw HTTP ■ live 45 min
00.06 Streaming responses with SSE ■ live 40 min
00.07 Tracing from day one ■ live 35 min
00.08 Project layout for agent repos ■ live 30 min

Phase overview →

Phase 01 · LLM Foundations for Agents · 10 lessons · 10 live

What a model actually returns, how context windows fill, and how to force structured, parseable output.

# Lesson Status Time
01.01 What an LLM actually returns ■ live 45 min
01.02 Tokens and the context window ■ live 50 min
01.03 Sampling: temperature, top-p, determinism ■ live 40 min
01.04 Chat templates and message roles ■ live 40 min
01.05 System prompts as contracts ■ live 35 min
01.06 Structured output & JSON mode ■ live 50 min
01.07 Parsing and validating with schemas ■ live 45 min
01.08 Token budgets & cost math ■ live 35 min
01.09 Model selection for agent work ■ live 40 min
01.10 Why capable models still fail ■ live 45 min

Phase overview →

Phase 02 · Tool Use & Function Calling · 11 lessons · 11 live

Turn text into action. Tool schemas, dispatchers, parallel calls, and errors fed back as observations.

# Lesson Status Time
02.01 Text in, text out: the limit ■ live 30 min
02.02 Tool schemas from first principles ■ live 50 min
02.03 Writing a tool dispatcher ■ live 60 min
02.04 Parallel tool calls ■ live 45 min
02.05 Tool errors as observations ■ live 40 min
02.06 Designing tools models can use ■ live 50 min
02.07 Idempotency and side effects ■ live 40 min
02.08 Human approval gates ■ live 45 min
02.09 Tool results that fit the context ■ live 40 min
02.10 Native function calling across providers ■ live 50 min
02.11 Testing tools in isolation ■ live 40 min

Phase overview →

Phase 03 · The Agent Loop · 12 lessons · 12 live

A while-loop, a model, and a toolbox. ReAct, stop conditions, retries, interrupts, and the loop as a graph.

# Lesson Status Time
03.01 The agent loop in 120 lines ■ live 60 min
03.02 ReAct: reason, act, observe ■ live 60 min
03.03 Stop conditions & max steps ■ live 35 min
03.04 Scratchpads and thought traces ■ live 40 min
03.05 Handling malformed actions ■ live 40 min
03.06 Retries, backoff & recovery ■ live 45 min
03.07 Streaming an agent's steps ■ live 45 min
03.08 Interrupts and resumption ■ live 50 min
03.09 State machines for agents ■ live 55 min
03.10 The loop as a graph ■ live 55 min
03.11 Cost and step budgets ■ live 35 min
03.12 Debugging a stuck loop ■ live 45 min

Phase overview →

Phase 04 · Memory & Context Engineering · 11 lessons · 11 live

Context is the program. Buffers, summaries, embeddings, a vector store by hand, and memory that stays clean.

# Lesson Status Time
04.01 Context is the program ■ live 40 min
04.02 Conversation buffers & truncation ■ live 40 min
04.03 Summarization memory ■ live 45 min
04.04 Embeddings from scratch ■ live 60 min
04.05 A vector store in 80 lines ■ live 60 min
04.06 Episodic memory ■ live 50 min
04.07 Semantic & procedural memory ■ live 50 min
04.08 Memory writes: what to keep ■ live 45 min
04.09 Context compaction ■ live 45 min
04.10 Files as long-term memory ■ live 40 min
04.11 Memory poisoning & hygiene ■ live 40 min

Phase overview →

Phase 05 · Retrieval & Agentic RAG · 10 lessons · 10 live

Retrieval as a tool the agent decides to call. Hybrid search, reranking, rewriting, and self-correcting loops.

# Lesson Status Time
05.01 Naive RAG and where it breaks ■ live 45 min
05.02 Chunking strategies ■ live 45 min
05.03 Hybrid search: BM25 + vectors ■ live 55 min
05.04 Reranking ■ live 40 min
05.05 Query rewriting & decomposition ■ live 45 min
05.06 Retrieval as a tool ■ live 45 min
05.07 Self-correcting RAG ■ live 55 min
05.08 Corrective RAG loops ■ live 50 min
05.09 Graph-based retrieval ■ live 55 min
05.10 Evaluating retrieval quality ■ live 45 min

Phase overview →

Phase 06 · Planning & Reasoning · 10 lessons · 10 live

Plan-and-execute, task trees, Tree of Thoughts, reflection, verifiers, and knowing when not to plan.

# Lesson Status Time
06.01 Chain-of-thought for actions ■ live 40 min
06.02 Plan-and-execute ■ live 55 min
06.03 Task decomposition trees ■ live 50 min
06.04 Tree of Thoughts search ■ live 60 min
06.05 Reflection & self-critique ■ live 45 min
06.06 Reflexion: learning from failures ■ live 55 min
06.07 Verifiers and checkers ■ live 50 min
06.08 Replanning on surprise ■ live 45 min
06.09 Reasoning models in the loop ■ live 45 min
06.10 When not to plan ■ live 30 min

Phase overview →

Phase 07 · Model Context Protocol · 11 lessons · 11 live

MCP from the wire up. JSON-RPC over stdio, a server and a client by hand, transports, auth, and security.

# Lesson Status Time
07.01 Why MCP exists ■ live 35 min
07.02 The protocol: JSON-RPC over stdio ■ live 50 min
07.03 Build an MCP server from scratch ■ live 60 min
07.04 Tools, resources & prompts ■ live 50 min
07.05 Build an MCP client ■ live 55 min
07.06 Streamable HTTP transport ■ live 50 min
07.07 Auth for remote servers ■ live 50 min
07.08 Sampling and elicitation ■ live 45 min
07.09 Composing many servers ■ live 45 min
07.10 Testing MCP servers ■ live 40 min
07.11 MCP security pitfalls ■ live 45 min

Phase overview →

Phase 08 · Multi-Agent Systems · 12 lessons · 12 live

Orchestrators, workers, handoffs, supervisors, blackboards, A2A, and the real cost of coordination.

# Lesson Status Time
08.01 When one agent is not enough ■ live 35 min
08.02 Orchestrator–worker ■ live 55 min
08.03 Handoffs between agents ■ live 50 min
08.04 Supervisor hierarchies ■ live 50 min
08.05 Shared blackboards ■ live 45 min
08.06 Debate and critique ■ live 45 min
08.07 Agent-to-agent (A2A) protocol ■ live 55 min
08.08 Message passing & mailboxes ■ live 50 min
08.09 Parallel fan-out, fan-in ■ live 45 min
08.10 Role design & specialization ■ live 40 min
08.11 Failure modes of swarms ■ live 45 min
08.12 Cost of coordination ■ live 35 min

Phase overview →

Phase 09 · Frameworks & SDKs · 10 lessons · 10 live

Now import the frameworks. The same loop in LangGraph, Agents SDKs, CrewAI, AutoGen, and when to skip them all.

# Lesson Status Time
09.01 The same loop, ten frameworks ■ live 40 min
09.02 LangGraph: state graphs ■ live 60 min
09.03 OpenAI Agents SDK ■ live 50 min
09.04 Claude Agent SDK ■ live 50 min
09.05 CrewAI roles & crews ■ live 45 min
09.06 AutoGen conversations ■ live 45 min
09.07 LlamaIndex agents ■ live 45 min
09.08 Pydantic AI typed agents ■ live 45 min
09.09 Choosing (or skipping) a framework ■ live 35 min
09.10 Porting between frameworks ■ live 45 min

Phase overview →

Phase 10 · Coding & Computer-Use Agents · 11 lessons · 11 live

Agents that edit files, run tests, drive browsers and terminals. Ends with a mini coding agent of your own.

# Lesson Status Time
10.01 Anatomy of a coding agent ■ live 45 min
10.02 File read, edit & search tools ■ live 55 min
10.03 Running code in a sandbox ■ live 55 min
10.04 Test-driven agent loops ■ live 55 min
10.05 Repository maps & context ■ live 50 min
10.06 Skills and SKILL.md ■ live 45 min
10.07 Browser agents ■ live 55 min
10.08 Computer use: screenshots to clicks ■ live 60 min
10.09 Terminal agents ■ live 50 min
10.10 Long-horizon tasks ■ live 50 min
10.11 Build a mini coding agent ■ live 90 min

Phase overview →

Phase 11 · Evaluation & Observability · 10 lessons · 10 live

Golden tasks, trajectory evals, careful LLM judges, OpenTelemetry traces, replay, and your own eval harness.

# Lesson Status Time
11.01 Why agent evals are hard ■ live 35 min
11.02 Golden tasks & datasets ■ live 45 min
11.03 Trajectory evaluation ■ live 50 min
11.04 LLM-as-judge, carefully ■ live 50 min
11.05 Tool-call accuracy ■ live 40 min
11.06 Tracing with OpenTelemetry ■ live 50 min
11.07 Replay and regression ■ live 45 min
11.08 Online metrics & feedback ■ live 40 min
11.09 Benchmarks: SWE-bench to τ-bench ■ live 45 min
11.10 Building an eval harness ■ live 70 min

Phase overview →

Phase 12 · Safety, Security & Guardrails · 11 lessons · 11 live

The agent threat model. Prompt injection, exfiltration, least privilege, sandboxes, permissions, red-teaming.

# Lesson Status Time
12.01 The agent threat model ■ live 45 min
12.02 Prompt injection, direct & indirect ■ live 55 min
12.03 Data exfiltration paths ■ live 45 min
12.04 Least-privilege tools ■ live 40 min
12.05 Sandboxing with containers ■ live 55 min
12.06 Permission systems ■ live 50 min
12.07 Input & output guardrails ■ live 45 min
12.08 Secrets and credentials ■ live 35 min
12.09 Human-in-the-loop design ■ live 40 min
12.10 Red-teaming your agent ■ live 55 min
12.11 Audit logs ■ live 35 min

Phase overview →

Phase 13 · Production Agents · 10 lessons · 10 live

Durable execution, queues, caching, routing, cost control, versioning, and incident playbooks.

# Lesson Status Time
13.01 From notebook to service ■ live 45 min
13.02 Durable execution ■ live 55 min
13.03 Queues, workers & long jobs ■ live 50 min
13.04 Prompt caching & latency ■ live 45 min
13.05 Cost control at scale ■ live 40 min
13.06 Model routing & fallbacks ■ live 45 min
13.07 Versioning prompts and tools ■ live 40 min
13.08 Deploying with Docker ■ live 45 min
13.09 Rate limits & backpressure ■ live 40 min
13.10 Incident playbooks ■ live 35 min

Phase overview →

Phase 14 · Agent UX & Interfaces · 8 lessons · 8 live

Streaming step views, approvals and undo, voice, background agents, and the design of trust.

# Lesson Status Time
14.01 Streaming UIs for agents ■ live 45 min
14.02 Showing the work: step views ■ live 40 min
14.03 Approvals & undo ■ live 40 min
14.04 Chat is not the only interface ■ live 35 min
14.05 Voice agents ■ live 55 min
14.06 Background agents & notifications ■ live 40 min
14.07 Generative UI ■ live 45 min
14.08 Trust and explainability ■ live 35 min

Phase overview →

Phase 15 · Capstone: Your Own Agent Harness · 8 lessons · 8 live

Everything at once. A loop, tool registry, memory, MCP, subagents, permissions, and evals, shipped as a CLI.

# Lesson Status Time
15.01 Why build a harness ■ live 35 min
15.02 The core loop & tool registry ■ live 70 min
15.03 Memory & context manager ■ live 70 min
15.04 MCP client integration ■ live 60 min
15.05 Subagents & delegation ■ live 60 min
15.06 Permissions & sandbox ■ live 60 min
15.07 Evals & traces ■ live 60 min
15.08 Ship it: CLI + docs ■ live 60 min

Phase overview →

Repository layout

Path What's there
phases/ 16 phases, one folder per lesson: docs/en.md, code/, quiz.json, outputs/
interviews/ Interview questions, one Markdown file each, rendered to /interviews/ on the site
skills/ The tutor skills installed by npx skills add
site/ The website: static HTML, CSS and JS, no framework
scripts/ build.mjs generates the site data, this README's contents, the roadmap and phase pages; test_lessons.py runs every lesson's tests
curriculum.json Source of truth for phases, lessons, titles and times
python3 scripts/test_lessons.py         # every lesson's tests, each in isolation
node scripts/build.mjs                  # regenerate derived files
python3 -m http.server -d site 8000     # preview the site at localhost:8000

Contributing

All 163 lessons are written. The most useful contributions now:

  • fixes to lessons: wrong claims, unclear explanations, broken code;
  • real-model results for lessons that only show scripted output;
  • new interview questions;
  • translations.
  1. Open an issue describing the change (small fixes can go straight to a PR).
  2. For code, keep it running offline with a scripted model, with tests and no network.
  3. Run python3 scripts/test_lessons.py and node scripts/build.mjs --check, then open a PR.

Interview questions follow the format in interviews/README.md; the build checks every one. Full guide: CONTRIBUTING.md. Agents contributing on someone's behalf should read AGENTS.md.

Maintainer

Ramakrushna Mohapatra Ramakrushna Mohapatra
Sr. Data Scientist · GenAI & LLM engineer · Tech trainer · Founder of GrowTechie
LinkedIn ramakrushnamohapatra  ·  Instagram techwith.ram  ·  X (Twitter) techwith_ram

If this course helps you, star the repo and share it. It helps other people find it.

License

MIT © 2026 Ramakrushna Mohapatra. Use it, fork it, teach with it.

探索相关项目

加载中…