All posts
Building an agent with tool loops — end to end
Tutorials 14 min read· 4 Aug 2026· By Tutorials

Building an agent with tool loops — end to end

A 200-line agent that browses the web, writes code, and reports back. Complete source.

Agents are just a while loop with tool calls. The interesting part is what tools you provide and how you constrain the loop.

The scaffold#

python
TOOLS = [
    {"type": "function", "function": {"name": "search_web", "parameters": {...}}},
    {"type": "function", "function": {"name": "read_page", "parameters": {...}}},
    {"type": "function", "function": {"name": "write_report", "parameters": {...}}},
]

The loop#

See the full function calling patterns post for the canonical shape.

Cap iterations. Log everything. Ship the trace to your dashboard for every run — you'll thank yourself in a month.

Ready to build?

Grab a key, keep your OpenAI SDK, and pay in INR.

Start free