Building your first AI agent: frameworks vs writing the loop yourself
There are many agent frameworks, but a basic agent is surprisingly small. Choosing between a framework and your own code depends on what you need.
The core loop is simple
- Send the model the goal, instructions and tool definitions
- If it requests a tool, run it and send back the result
- Repeat until the model produces a final answer or hits a step limit
Many developers write this in under a hundred lines using a model provider's SDK.
Reasons to write it yourself
- Full understanding and control of every prompt and step
- Easier debugging with fewer abstraction layers
- No dependency on a fast-moving framework's API changes
Reasons to use a framework
- Built-in support for memory, retries, streaming and tracing
- Prebuilt integrations with tools and data sources
- Patterns for multi-agent orchestration and human-in-the-loop approval
- Helpful when you need durable, long-running workflows
Practical advice
- Start with the raw loop to learn how agents behave
- Add logging of every model call and tool result from day one
- Set step limits and timeouts to avoid runaway costs
- Adopt a framework once you hit problems it actually solves
Did you start with a framework or roll your own? What feature made you switch one way or the other?
Comments · 3
Starting without a framework makes sense for learning. Once you know the loop, you can judge which framework earns its keep.
Frameworks add dependencies, and the field changes quickly. Owning the loop reduces the risk of rewrites when libraries shift.
At what point does writing your own loop get painful? Is it tool calling, memory or something else?