CoachDiscoverMapCompareSavedAI LearningAI WeeklyAbout
← Back to Library
01 · Foundations

How an Agent Actually Runs

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

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

"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

DimensionCodeAgent (default)ToolCallingAgent
Action formatPython code snippetJSON / structured tool call
StrengthComposable: loops, conditionals, nesting in one stepPredictable, deterministic, easy to govern
Executes viaSandbox (Docker / E2B / Modal)Model's native tool-calling API
Best forMulti-step, computational, dynamic logicProduction 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

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

Suggested small modifications (to prove you get it)

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.

FrameworkWhat it's known forNote
LangChainThe broadest ecosystem of chains, tools, integrationsPowerful but heavy; lots of abstraction to see through
CrewAIRole-based multi-agent "crews" that collaborateGood for team-of-agents patterns
AutoGenMulti-agent conversations & orchestration (Microsoft)Strong on agent-to-agent messaging
"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?
Question 2 of 10
What is the core flow of ReAct?
Question 3 of 10
Why does smolagents' CodeAgent write its actions as Python code rather than JSON?
Question 4 of 10
What is "context compaction" in the context of a long-running agent?
Question 5 of 10
What is the difference between memory and context in an agent?
Question 6 of 10
What problem does the Model Context Protocol (MCP) solve?
Question 7 of 10
What should happen when a tool execution fails in a well-designed agent?
Question 8 of 10
Why is mini-swe-agent a good first agent to study?
Question 9 of 10
What is a Session Note in Mini-Agent?
Question 10 of 10
Why does a coding agent need a sandbox?
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.
← tap to flip back