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
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.
- Dec 2, 2026Ai2 Releases MolmoWeb2 Web Agents: 27B Model Solves 75.3% of Tasks
- Dec 2, 202650 AI Models Beat 62 Teams at 'Zakovat': 48.3% Correct Answers vs 39.8%
- Dec 2, 2026Claude Fable 5.2 ran 1,000 agents for eight days and built an operating system
- Dec 2, 2026Amazon Releases Ergo Open Weights for Coding: 1.1 Trillion Parameters and 2,200 Tokens per Second
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.
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.
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.
Free 2-Day Vibecoding & AI Agents Intensive
Day 1: the autonomous Hermes + DeepSeek AI agent — vibecoding and development on par with Claude Code / Codex / Gemini. Led by Jemal Hamidun, Head of AI at Alpina Digital and academic supervisor at MIPT. Right after you register with our bot Nika: the recording + 11 materials from the previous intensive.
Daily 60-sec AI Voice Brief + Weekly Production AI Agent Playbook
Listen to a 60-second AI news brief every morning and get a weekly hands-on playbook for shipping AI agents to production — tools, MCP servers and patterns that work. Curated by Jemal Hamidun, Head of AI at Alpina Digital.
