cd /news/artificial-intelligence/how-llm-tool-calling-actually-works-… · home topics artificial-intelligence article
[ARTICLE · art-53739] src=pub.towardsai.net ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

How LLM Tool Calling Actually Works: Build an Agent From Scratch in 160 Lines of Python

A developer explains that AI agents are fundamentally simple while loops that call an LLM, check for tool requests, execute them, and feed results back until the LLM can answer. The article demonstrates building a functional agent from scratch in 160 lines of Python using only the OpenAI SDK, stripping away the complexity of frameworks like LangChain and CrewAI.

read1 min views1 publishedJul 10, 2026
How LLM Tool Calling Actually Works: Build an Agent From Scratch in 160 Lines of Python
Image: Pub (auto-discovered)

Member-only story

No LangChain. No CrewAI. Just the loop that every agent framework is hiding from you. #

I used to think AI agents were complicated. The frameworks certainly make them look complicated chains, executors, graphs, memory modules, callback managers. I spent a weekend inside one framework’s source code trying to figure out why my agent was calling the wrong tool, and by the end I had learned something I didn’t expect:

An agent is a while loop.

That’s it. That’s the whole secret. A loop that calls an LLM, checks whether the LLM asked to run a function, runs it, feeds the result back, and repeats until the LLM has enough information to answer.

Everything else, the chains, the graphs, the abstractions is packaging around that loop. Useful packaging sometimes. But if you’ve never seen the bare loop, you’re using agents the way most people use cars: fine until something breaks, and then you’re helpless.

So let’s build one. Around 160 lines of Python, one dependency (the OpenAI SDK, which is just an API client, not a framework), and by the end you’ll understand exactly what happens when any agent “decides” to use a tool.

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @openai 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/how-llm-tool-calling…] indexed:0 read:1min 2026-07-10 ·