I Built an AI Agent with Claude's Tool-Use Loop (Web Search, SQL, and More) A developer built an AI agent using Claude's tool-use loop, enabling it to perform web searches, SQL queries, and calculations autonomously. The agent iteratively selects and executes tools until it has an answer, with a maximum step limit to prevent infinite loops. The project is open-sourced on GitHub as claude-research-agent. "AI agent" gets thrown around so much I figured I should just build one instead of reading more threads about it. The core idea turned out to be small: you put Claude in a loop and hand it some tools. It picks a tool, you run it, you hand back the result, and it keeps going until it has an answer. Code is here if you want to skip ahead: claude-research-agent https://github.com/venkatarahul27/claude-research-agent . Give it a task and it works out the steps on its own. Mine can: eval Honestly this is most of it: messages = {"role": "user", "content": user message} for in range MAX STEPS : response = client.messages.create model="claude-sonnet-5", max tokens=2048, tools=TOOL SCHEMAS, messages=messages, messages.append {"role": "assistant", "content": response.content} if response.stop reason = "tool use": return final text response tool results = for block in response.content: if block.type == "tool use": result = run tool block.name, block.input tool results.append { "type": "tool result", "tool use id": block.id, "content": result, } messages.append {"role": "user", "content": tool results} The thing to watch is stop reason . If Claude says tool use , it wants you to run something. You run it, drop the result back into the conversation as a tool result , and loop. When it stops asking for tools, you're done. The MAX STEPS cap is just there so a confused agent can't spin forever. Each tool is a Python function plus a little JSON schema telling Claude when to reach for it. Want a new capability? Write a function, add its schema. The loop never changes, which was the part I liked most. The second your agent can run code or touch a database, you have to be careful: import "os" ... gets rejected instead of run ../../etc/passwd Skip this and you've basically built a foot-gun with a chat interface. Here's a real run. I asked it to look up the latest Claude model and do some math, and it chained five tool calls by itself: you Search for the latest Claude model, then calculate 15% of 2340. web search {"query": "latest Claude model"} calculator {"expression": "2340 0.15"} fetch url {"url": "https://www.anthropic.com/news"} save note {...} agent 15% of 2340 = 351, plus a short rundown of the current models. Watching it decide the order on its own is the part that finally made "agent" click for me. My web search kept coming back empty even though the results were clearly in the HTML. Drove me a little crazy. Turns out DuckDuckGo wraps the matched words in