How an AI Agent Works Under the Hood: Seven Tools That Turn an LLM Into a Doer

What happens when a language model gets access to a terminal, a file system and the internet? That is essentially how Claude Code and Codex work: the agent reads code, edits files and runs commands on its own. The second part of the tutorial covers seven basic tools and the selection mechanism: how the model decides, in each situation, exactly what to call.

AI-processed from Habr AI; edited by Hamidun News
How an AI Agent Works Under the Hood: Seven Tools That Turn an LLM Into a Doer
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1Reading files from the file system
Key metric #2Writing and editing files
Key metric #3Running terminal commands

Give a language model a terminal, a file system and internet access, and it stops being a chatty assistant and becomes an agent. That is how Claude Code, Codex and other developer tools work under the hood. The second part of the tutorial explains how to add seven basic tools to a model and teach it to choose the right one for each task.

What agent tools are

On its own, a language model can do only one thing: generate text from the context it receives. To become an agent, it needs tools: specific functions that the agent framework executes on the model's command and whose results it returns to the context.

The principle is simple. The model receives a prompt describing the available tools: name, parameters and what each does. As it works, it assesses the task and decides for itself whether to call anything and, if so, which tool and with what arguments. The developer defines the set of available functions; choosing a specific tool for a specific situation is up to the model.

The tutorial gives the agent seven basic tools:

  • Reading files from the file system
  • Writing and editing files
  • Running terminal commands
  • Navigating directories and listing their contents
  • Running Python scripts on the fly
  • Searching the internet
  • Getting information about the system and environment

This set already lets the agent read someone else's code, make edits, run tests and check the results, without a human involved at every step.

How the model chooses a tool

The key is not the set of tools but the selection mechanism. It is called tool calling or function calling, and it is where modern LLMs differ fundamentally from the previous generation of chatbots.

When the model decides a task requires a tool, it returns not just text but structured JSON: a function name and arguments. The agent framework intercepts this JSON, performs the real operation (running a command, reading a file, making an HTTP request) and returns the result to the context. The model looks at the result, thinks again, and either calls the next tool or finishes.

This loop of think, call a tool, get a result, think again turns a static language model into a dynamic system. The model does not follow a rigid script: each time it re-analyzes the situation using all the accumulated context, including previous steps, intermediate results and the original task. That is what makes the agent flexible: it can adjust its plan on the fly if an intermediate result turns out to be unexpected.

The loop and the stopping problem

The agent works in a cycle: it generates a response, calls a tool if one is needed, gets the result, and generates again. The cycle continues until the task is done or until the agent decides that further calls are unnecessary.

This is where the main engineering difficulty lies: how does the model know when to end the loop? Simple implementations use one of two approaches. The first is an iteration limit: if the task is not done after N steps, the agent is forcibly stopped. The second is a special completion signal: the model returns a "done" marker and the framework exits the loop.

Claude Code and Codex handle this in a considerably more sophisticated way, taking into account the task context, the cost of each call and an analysis of intermediate results. But the fundamental principle is the same: a loop with an explicit exit condition. That condition determines whether the agent is a useful tool or hangs in an infinite loop.

What this means

The tutorial shows clearly that the difference between a simple chatbot and a powerful tool like Claude Code lies not in model size or in magic, but in architecture. Add a loop, a few functions and a stopping rule, and you get a system that can work with the real world: it reads code, edits files, runs tests and searches the web. That is what makes modern AI agents practically useful to developers rather than merely impressive in a demo.

Story

Key Questions Answered

What agent tools are?

On its own, a language model can do only one thing: generate text from the context it receives. To become an agent, it needs tools: specific functions that the agent framework executes on the model's command and whose results it returns to the context. The principle is simple. The model receives a prompt describing the available tools: name, parameters and what each does. As it works, it assesses the task and decides for itself whether to call anything and, if so, which tool and with what arguments. The developer defines the set of available functions; choosing a specific t

How the model chooses a tool?

The key is not the set of tools but the selection mechanism. It is called tool calling or function calling, and it is where modern LLMs differ fundamentally from the previous generation of chatbots. When the model decides a task requires a tool, it returns not just text but structured JSON: a function name and arguments. The agent framework intercepts this JSON, performs the real operation (running a command, reading a file, making an HTTP request) and returns the result to the context. The model looks at the result, thinks again, and either calls the next tool or finishes.

What are the key details on The loop and the stopping problem?

The agent works in a cycle: it generates a response, calls a tool if one is needed, gets the result, and generates again. The cycle continues until the task is done or until the agent decides that further calls are unnecessary. This is where the main engineering difficulty lies: how does the model know when to end the loop? Simple implementations use one of two approaches. The first is an iteration limit: if the task is not done after N steps, the agent is forcibly stopped. The second is a special completion signal: the model returns a "done" marker and the framework exits

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Hands-On AI Engineering · Hamidun Academy

Build & Ship Production AI Agents Without Boilerplate Code

Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.

Start 72h Free Trial →Vibe-Coding Intensive
What do you think?
Loading comments…