A bottom-up route to understanding agents — not by chasing big frameworks, but by reading three small open-source projects until the agent loop, tools, memory, context compaction, and MCP all click.
TAKEAWAY 01
An Agent = a loop
At heart it's "LLM decides → tool executes → result feeds back," repeated until the task is done. Not magic — a control loop around a model.
TAKEAWAY 02
Read small before big
Don't start with LangChain/CrewAI/AutoGen. Get one minimal agent running, then layer on tools, ReAct, then memory/skills/MCP.
TAKEAWAY 03
Three projects, three lenses
mini-swe-agent = the skeleton; smolagents = tools & ReAct; a full Mini-Agent = the engineering (memory, context, MCP).
The agent loop — the thing to see through
One line: An agent isn't a mysterious system — it's the cycle of LLM decision + tool execution + result feedback, running until the goal is met.
Imagine giving a smart assistant a task and a keyboard. It receives the task, the model proposes the next action (e.g. a command to run), that action is executed (via bash / a subprocess / a tool), and the observation (what came back) is pasted back into the conversation so the model can decide the next step. That's the whole engine. The five things worth tracing in any codebase: how the task comes in, how the model picks the next action, how the action executes, how the observation re-enters context, and how the loop knows when to stop.
The five questions to answer in any agent's code
How does the agent receive the task? (the initial prompt + system prompt)
How does the model generate the next action? (free-text command, JSON tool call, or Python code)
How does the action execute? (bash / subprocess / a registered tool function)
How does the observation get fed back? (appended to the message history)
Why is a linear history easier to debug? (every step just appends — you can replay exactly what the model saw)
A chatbot answers and waits. An agent takes actions in the world (runs commands, calls tools), reads the results, and loops — pursuing a goal across many steps rather than replying once.
mini-swe-agent — the minimal runnable skeleton
One line: ~100 lines of Python that solve real GitHub issues — the cleanest way to see an agent loop with zero scaffolding.
It's the "hello world" of coding agents. Built by the Princeton/Stanford team behind SWE-bench and SWE-agent, it deliberately strips everything away: no custom tools, no plugins, no vector DB — the agent's only action is to run a bash command, and each command runs independently via subprocess.run. Despite that, it scores >74% on SWE-bench Verified. The lesson: as models got better at agentic coding, most of the old scaffolding became unnecessary — so this is the perfect baseline to study because the model, not the framework, is doing the work.
What to trace here
The bare loop — prompt in, model emits a bash command, it runs, output appends to history, repeat.
Linear history — every step just appends to the message list; nothing hidden, trivially replayable (why it's easy to debug).
Stateless execution — subprocess.run per action, no persistent shell session to reason about.
The 3-way decoupling — model (which LLM), environment (where commands run: local / Docker), and agent (the loop) are cleanly separated.
No tool-calling interface needed — works with any model because actions are just text commands, not a special API.
"Just tell the model to figure it out" — minimal scaffold, maximum reliance on model capability. A clean baseline that puts the LM, not the harness, at the center.
smolagents — ReAct, tools & CodeAgent
One line: HuggingFace's ~1,000-line framework — more reusable than mini-swe-agent, and the best place to internalize ReAct and tool design.
If mini-swe-agent shows the skeleton, smolagents shows the reusable body. Every agent here is a MultiStepAgent — an implementation of ReAct, the loop of Think → Act → Observe. Its signature idea: the default CodeAgent writes its actions as Python code (run in a sandbox) instead of emitting JSON — which lets one step combine tools, loop, and use conditionals naturally, and research suggests models act more effectively in code than in JSON. The alternative ToolCallingAgent writes actions as JSON tool calls, the classic style.
What to focus on
The ReAct cycle in code — how Think / Act / Observe actually map to functions and the message log.
Defining a Tool — how a tool is declared and how the model is told it can call it.
Why CodeAgent writes Python — composability (nesting, loops, conditionals) and fewer round-trips than JSON calls.
Built-in & custom tools — e.g. a web-search tool; how to write your own and adapt different models.
CodeAgent vs ToolCallingAgent — code-as-action vs JSON-as-action (see the table below).
Dimension
CodeAgent (default)
ToolCallingAgent
Action format
Python code snippet
JSON / structured tool call
Strength
Composable: loops, conditionals, nesting in one step
Predictable, deterministic, easy to govern
Executes via
Sandbox (Docker / E2B / Modal)
Model's native tool-calling API
Best for
Multi-step, computational, dynamic logic
Production integrations, fixed APIs
CodeAgent writing actions as code is different from "an agent that helps you write code." Here the code IS the action language — the model's tool call literally is a Python snippet that gets executed.
Mini-Agent — the full engineering structure
One line: The first two teach principles; this one shows the engineering — what a real agent needs to run long tasks reliably.
A toy loop works for one quick task; a real agent has to survive a long one. That means solving the engineering problems around the loop: what to do when context gets too long (summarize/compact it), how to remember things across runs (a persistent "Session Note"), how to plug in reusable workflows (Skills) and external tools (MCP), and how to organize logs, config, and the CLI so it's debuggable and operable. The thing to truly internalize: a long-running agent isn't just "calls tools" — it must also handle context, memory, observability, and extensibility.
What to study
The complete agent execution loop — the full version, with all the production concerns wired in.
Filesystem & Shell tools — how real file/command tools are exposed safely.
Context compaction — when the conversation gets too long, how it summarizes/compresses to stay under the window.
Session Note (persistent memory) — how learnings survive across sessions, distinct from the in-context history.
Skills — how reusable workflows are plugged in.
MCP — how external tools are extended in via a standard protocol.
Logs / config / CLI — how the project is organized for operability.
Context = what's in the model's window right now (this conversation, recent tool output) — finite and wiped between sessions. Memory = what persists beyond the window (a Session Note, a store) and gets selectively loaded back in. Compaction manages context; memory manages persistence.
The learning method — one mainline per project
One line: Don't read the whole codebase. Per project, follow a single thread — and finish by changing something small yourself.
The reading thread
Run the demo first — get it working before reading anything.
Find the entry file — where execution starts.
Read down the agent loop — follow the loop, ignore the rest at first.
Draw the flow — sketch "model input → tool execution → result returned."
Then change one small thing — this is what turns reading into understanding.
Suggested small modifications (to prove you get it)
Add a simple constraint to mini-swe-agent (e.g. limit which commands it may run).
Write a custom Tool for smolagents.
Run a task on Mini-Agent with memory / context-compaction turned on.
mini-swe-agent for the skeleton → smolagents for tools & ReAct → Mini-Agent for memory, Skills, MCP. Small agent first; frameworks later.
The framework landscape — and why to delay it
One line: The big orchestration frameworks are powerful but heavy — learn the loop first so they're not a black box.
These are the "batteries-included" toolkits everyone reaches for. They're useful, but starting here hides the loop you actually need to understand. The advice: get a minimal agent running, learn tools and ReAct, then study memory/skills/MCP — then a framework is just a convenience layer you can reason about.
Framework
What it's known for
Note
LangChain
The broadest ecosystem of chains, tools, integrations
Powerful but heavy; lots of abstraction to see through
"Don't pile on LangChain / CrewAI / AutoGen on day one." Skeleton → tools & ReAct → memory/skills/MCP. Frameworks last, once the loop is second nature.
Quiz — How an Agent Actually Runs
Question 1 of 10
What is the fundamental difference between an Agent and a Chatbot?
The defining additions are tool use, a feedback loop, and multi-step autonomy. A chatbot replies once; an agent loops until a goal is met.
Question 2 of 10
What is the core flow of ReAct?
ReAct = Reasoning + Acting. The model writes a reasoning step (Think), chooses an action (Act), the action runs and returns a result (Observe), and that result feeds the next Think step.
Question 3 of 10
Why does smolagents' CodeAgent write its actions as Python code rather than JSON?
Code-as-action lets a single step combine tools, iterate with loops, and use conditionals naturally — reducing round-trips and giving the model more expressive power than a single JSON call.
Question 4 of 10
What is "context compaction" in the context of a long-running agent?
Compaction preserves the goal and key results while dropping or summarizing stale low-value turns — keeping the agent focused and within its context window.
Question 5 of 10
What is the difference between memory and context in an agent?
Think of it as: context = RAM (what the model sees right now), memory = disk (what survives between sessions and gets selectively reloaded).
Question 6 of 10
What problem does the Model Context Protocol (MCP) solve?
Instead of hardcoding each integration, MCP is an open standard — tools are discovered and called through one protocol, so capabilities are reusable across agents.
Question 7 of 10
What should happen when a tool execution fails in a well-designed agent?
The loop itself is the recovery mechanism — a failed step is just another observation. Add validation, retries with limits, and timeouts so one bad result doesn't derail the run.
Question 8 of 10
Why is mini-swe-agent a good first agent to study?
At ~100 lines with no custom tools or plugins, it's the ideal baseline — it shows what's truly essential in an agent loop while still scoring >74% on SWE-bench Verified.
Question 9 of 10
What is a Session Note in Mini-Agent?
The Session Note is one of the simplest forms of long-term memory — it's what lets an agent know what it learned in previous runs, not just the current conversation.
Question 10 of 10
Why does a coding agent need a sandbox?
An agent runs arbitrary commands/code, so you isolate execution to protect the host and contain mistakes. Logs serve the complementary need: observability for long autonomous runs.
Flashcards — How an Agent Actually Runs
Agent loop
tap to reveal →
LLM decides → tool executes → result feeds back, repeated until the goal is met. The core of every agent.
← tap to flip back
ReAct
tap to reveal →
Reasoning + Acting: the Think → Act → Observe cycle, with reasoning made explicit in text before each action.
← tap to flip back
Action
tap to reveal →
The step the model chooses to take — a bash command, a JSON tool call, or a Python snippet. Executed by the environment.
← tap to flip back
Observation
tap to reveal →
The result of executing an action, appended back into context so the model can reason from it on the next step.
← tap to flip back
Linear history
tap to reveal →
Every step just appends to the message list — nothing hidden, so runs are easy to replay and debug step by step.
← tap to flip back
Tool
tap to reveal →
A named, described function the model can invoke (web search, file read, API call) with typed inputs and outputs.
← tap to flip back
Function calling
tap to reveal →
Model emits a structured tool call directly; deterministic and predictable. Reasoning happens inside the model, invisible in the output.
← tap to flip back
CodeAgent
tap to reveal →
smolagents' default agent type: writes actions as executable Python run in a sandbox. Composable — loops, conditionals, and nesting in one step.
← tap to flip back
ToolCallingAgent
tap to reveal →
smolagents variant that writes actions as JSON tool calls — the classic function-calling style. Predictable and easy to govern.
← tap to flip back
MultiStepAgent
tap to reveal →
smolagents' base class implementing the ReAct loop. CodeAgent and ToolCallingAgent both extend it.
← tap to flip back
subprocess.run
tap to reveal →
How mini-swe-agent executes each bash action independently — stateless, no persistent shell session, simple to reason about.
← tap to flip back
SWE-bench
tap to reveal →
Benchmark of real GitHub issues; the agent must produce a patch that makes existing tests pass. mini-swe-agent scores >74% on the Verified split.
← tap to flip back
Context compaction
tap to reveal →
Summarizing or dropping older turns when the context window fills, to keep the goal and key results while shedding stale detail.
← tap to flip back
Memory vs. context
tap to reveal →
Context = live window (RAM) — finite, gone between sessions. Memory = persistence beyond the window (disk) — e.g. a Session Note loaded back in when relevant.
← tap to flip back
Session Note
tap to reveal →
A persisted record of a run's learnings, saved to disk and reloaded in future sessions — one of the simplest forms of long-term memory.
← tap to flip back
Skills
tap to reveal →
Reusable, pluggable workflows the agent can load when relevant — packaged as files with instructions and optional scripts.
← tap to flip back
MCP
tap to reveal →
Model Context Protocol — open standard to connect external tools and data without bespoke integration glue per service.
← tap to flip back
Sandbox
tap to reveal →
Isolated environment for running an agent's commands/code safely, away from the host — so mistakes can't do real damage.
← tap to flip back
Model / env / agent split
tap to reveal →
The clean 3-way separation: which LLM (model), where actions run (environment), and the loop logic (agent) — each replaceable independently.
← tap to flip back
LangChain / CrewAI / AutoGen
tap to reveal →
Heavyweight orchestration frameworks. Useful convenience layers once you understand the loop — but starting here hides the fundamentals.