Habr AI→ original

Как устроен AI-агент: слои-обёртки вокруг LLM и где искать источник бага

AI-агенты собирают из фреймворков, MCP-серверов и облачных «агентов из коробки», но в центре любой схемы — одна LLM: она читает контекст и формулирует следующий шаг. Вокруг модели нарастает «луковица» обёрток, и, как показывает разбор на Habr, поломки чаще случаются в этих слоях, а не в самой модели. Разбор идёт от модели наружу — так проще искать источник бага.

AI-processed from Habr AI; edited by Hamidun News
Как устроен AI-агент: слои-обёртки вокруг LLM и где искать источник бага
Source: Habr AI. Collage: Hamidun News.
◐ Listen to article

A developer with an ML background published a breakdown on Habr in July 2026 of how AI agents work under the hood: at the center of any agentic setup there remains a single LLM, while around it an "onion" of wrapper layers keeps growing — and most failures happen precisely in these layers, not in the model itself.

What hides behind the word "agent"

An AI agent is not the neural network itself, but several layers of code wrapped around it. Frameworks change, MCP servers appear, cloud platforms promise an "agent out of the box," but the core is the same everywhere: a large language model (LLM) that reads context and proposes the next step. Everything on the outside is scaffolding that prepares the input and processes the model's output.

The author lists the typical levels used to assemble an agent on top of a model:

  • LLM — the core, predicts the probabilities of the next token
  • Prompt and context layer — exactly what goes into the model as input
  • Orchestration and tool calling — how the model's response turns into an action
  • MCP servers — standardized agent access to external data and functions
  • Frameworks and cloud wrappers — an "agent out of the box" on top of all of this

Each level adds its own logic: one assembles the context, another decides which tool to call, a third connects external data. The model itself performs none of these steps — it only predicts text.

Why the bug is usually not in the model

The source of a breakdown in an agent usually lies not in the LLM, but in one of the outer layers: in how the prompt was assembled, how the context was passed, how the tool call was handled. The model itself, in the author's words, does exactly one thing — predicts the next token; everything else is added by the wrappers around it.

"The model itself only predicts the probabilities of the next token; outside it, an onion of wrappers keeps growing," — the author of the

Habr article.

This is precisely why, the author notes, it's important to understand the whole construction when debugging: if an agent isn't assembled from a ready-made kit, knowing the layers helps localize the problem faster. Checking the model first is a common mistake: if the agent's response looks wrong, the reason is more often that the wrong context reached the model, or that a neighboring layer parsed its response incorrectly. The model, meanwhile, performed exactly as expected.

Why look outward from the model

The breakdown is built from the core to the periphery — from the LLM to the outer wrappers — because the author came into agents from ML, where every new layer sits on top of something already familiar. This order, in his words, makes the picture clearer: first what the model does, then what each wrapper on top of it does. The reverse path — from a ready-made "agent out of the box" inward — hides exactly where the boundary of responsibility for each layer lies.

The occasion for the article was mundane: the notes were born after yet another joint bug hunt with the technical team. The author compiled them into a single overview so that next time it would be easier to explain to colleagues what's located where in the agentic scheme and where to look during a failure. In essence, it's a map of levels that's handy to reference during debugging.

What this means

Behind the trendy word "agent" stands a stack of several layers, and understanding this structure is a practical debugging skill: when an agent misbehaves, the analysis should start not with the LLM, but with the wrappers around it, where most of the errors are hiding.

ZK
Hamidun News
AI news without noise. Daily editorial selection from 50+ sources. A product by Zhemal Khamidun, Head of AI at Alpina Digital.

Need AI working inside your business — not just in your newsfeed?

I build production AI for companies — custom CRM, internal tools, autonomous agents, workflow automation. Owned by you, shaped to your process, no per-seat tax. Built by Zhemal Khamidun, CPO of AlpinaGPT (AI platform, 6,000+ users).

What do you think?
Loading comments…