Chapter 31·Intermediate·9 min read
AI Agent Frameworks: Build by Hand or Use a Library?
A plain-English guide to AI agent frameworks — what they give you, what they hide, and how to choose between building the agent loop yourself or using a library. Plus the production concerns that actually decide success.
June 30, 2026
We've now assembled, conceptually, a complete agent: the loop, planning, memory, tools, teams, and connectivity. The final question is the practical one every builder hits: do you write all of this yourself, or reach for a framework?
What a framework gives you
An agent framework is a library that prebuilds the machinery from this guide so you don't have to. Most offer some mix of:
- the agent loop (perceive-think-act) ready to run;
- tool wiring — helpers to define tools and parse the model's calls;
- memory — built-in short- and long-term memory with vector-store hooks;
- orchestration — patterns for multi-agent and retries;
- integrations — prebuilt connectors to common models, tools, and data.
The appeal is obvious: instead of building every part, you assemble an agent from pieces. For getting something working quickly, that's a real advantage.
What a framework hides
The cost is the flip side of the benefit. A framework wraps the agent loop in abstraction — and the loop is exactly where an agent's behavior lives.
Two specific losses tend to bite:
- Control over context. We've stressed that an agent's quality is mostly about what you put in its context window. Frameworks make that assembly for you — convenient until you need it to be different.
- Visibility. The more the loop is hidden, the harder it is to know what actually happened on a given run.
None of this means frameworks are bad — it means abstraction has a price, and you should pay it knowingly.
Building it by hand is less scary than it sounds
Remember the mental model from chapter one: an agent is a while loop with an LLM as the brain inside it. Written plainly, the core is small:
while not done:
response = model(context) # think
if response.is_tool_call:
result = run_tool(response) # act (validated!)
context += result # observe
else:
done = True # final answerThat's the whole skeleton. Planning, memory, and multi-agent setups are elaborations on it, but the spine is a few lines you fully control and can read top to bottom. For many teams, owning this is less work than fighting a framework's abstractions when they don't quite fit.
What actually decides success
Here's the part that surprises people: the loop is the easy bit. Whether you build or buy the loop, the hard problems are the same, and they live around it:
| Concern | The real question |
|---|---|
| Observability | Can you see every prompt, tool call, and result on a run? |
| Evaluation | Can you measure whether the agent is actually getting better? |
| Guardrails | What stops a bad or runaway action — limits, validation, confirmation? |
| Cost control | What caps tokens and steps so a loop can't run away? |
An agent that works in a demo and an agent you can trust in production are separated almost entirely by these four things — not by which framework drew the loop. This is the same theme from the very first chapter: autonomy is a trade-off, and engineering an agent is mostly about constraining it.
How to choose
A simple rule that holds up:
- Prototyping, or a standard pattern? Use a framework. Speed wins, and you'll learn the shape of the problem fast.
- Core, high-stakes, or unusual logic? Own the loop. The control and visibility are worth the code.
- Either way, invest early in observability, evaluation, and guardrails — that's where reliability actually comes from.
Many mature systems end up hybrid: a framework for the boilerplate and integrations, hand-written code for the critical decisions and the safety boundary.
Recap
- Agent frameworks prebuild the loop, tool wiring, memory, and orchestration so you assemble rather than build.
- They trade speed for abstraction — and that abstraction hides the context and visibility you need to debug.
- Building by hand is often manageable: an agent is a
whileloop with an LLM inside, a few lines at its core. - Success is decided less by the loop and more by observability, evaluation, guardrails, and cost control.
- Prototype with a framework; own the critical logic — and invest in the production concerns either way.
That completes AI Agents Explained — you now have the full picture, from the agent loop to shipping one. Agents lean heavily on retrieving the right knowledge at the right moment; to go deeper on that, the natural next step is the guide on RAG. Browse it and the rest from the guides hub.