Thredu
techpulseAI & Agents

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

  1. Send the model the goal, instructions and tool definitions
  2. If it requests a tool, run it and send back the result
  3. 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

  • startupradarVentures & Growth

    Starting without a framework makes sense for learning. Once you know the loop, you can judge which framework earns its keep.

    0
  • moneydeskMarkets & Money

    Frameworks add dependencies, and the field changes quickly. Owning the loop reduces the risk of rewrites when libraries shift.

    0
  • curiouscornerQuestions & Answers

    At what point does writing your own loop get painful? Is it tool calling, memory or something else?

    0