⚡ The main thing in 60 seconds (TL;DR)

⏱ ~ 15 мин чтения
  • Open hh.ru and look for vacancies with the word “AI agent”. As of October 28, 2026, there are 1,458 of them. LLM is mentioned in 1,261 vacancies, RAG in 520, MCP in 245. Now look...
  • Now look for “prompt caching”: 13 vacancies.
  • Tokens are mentioned in 19.hh.ru, search throughout Russia, 10/28/2026.

Open hh.ru and look for vacancies with the word “AI agent”. As of October 28, 2026, there are 1,458 of them. LLM is mentioned in 1,261 vacancies, RAG in 520, MCP in 245. Now look for “prompt caching”: 13 vacancies. Tokens are mentioned in 19.

AI engineering for those who roll in: agents, MCP, tokens and cache with numbers

hh.ru, search throughout Russia, 10.28.2026.

Strange picture. Agents are being asked to build en masse. And almost no one asks about how much an agent costs and why he works. Let's look at these words one by one: what it is, why and what it looks like inside. Then we will count tokens and money on one agent task. With a cache, the same task is 6.6 times cheaper, and you'll see why. There will be a checklist at the end.

This is the first part of the series. In the second, I’ll look at reliability: durable execution, transactions and idempotency. In the third, I will show how a chain differs from an agent, and I will collect everything into one application using the example of a support agent.

TL;DR

  • AI engineer does not train his model. He builds a system around a ready-made one: he supplies it with the necessary data, gives it tools, checks the result and monitors the price.

  • The model doesn't remember anything and doesn't do anything on its own. At each step, the harness re-sends everything to it: the tools, the rules, and the entire history.

  • Therefore, in 30 steps the agent read 1.63 million tokens, although he was never given more than 100 thousand at a time.

  • The cache reads the repeating start of a request for 5–10% of the price. But only if it matched the previous request up to the symbol. Therefore put the unchangeable at the beginning, and the new at the end.

  • Russian text in Claude tokens is approximately 1.27 times more expensive than English.

What is AI engineering and why does it concern every developer?

How this differs from machine learning is well explained by Chip Huyen in the book “AI Engineering”. The ML engineer teaches the model himself: collects and labels data, trains, and checks. The AI ​​engineer takes a ready-made model that was trained by someone else, for example Claude or GPT. His job is to ask the right question, give the model the necessary data, and sometimes train it a little. For him, the model is simply an external service, like a database or a payment gateway. There is only one difference: she answers with text and sometimes makes mistakes.

For the average developer, this is no longer exotic. In a 2026 Stack Overflow survey, 73% of respondents said they code with assistants and agents every day. Among the agents most often mentioned are Claude Code (66%) and GitHub Copilot (59%). And in the 2025 survey, the main complaint was “AI answers are almost correct, but not quite.” 66% answered this way.

The difference between “almost” and “right” is rarely hidden in the prompt. In order for an agent to solve a problem and not eat up the budget, you need to understand four things. What the model receives at each step. Who actually performs the actions. Where the agent usually gets it wrong. And how much does each step cost?

Dictionary

Term

Briefly

Token

piece of text; the model reads in tokens, and money is counted in them

Context window

how many tokens the model will read in one request

System prompt

rules for the model, go into every request

Tool use

the model asks to call a function, your code executes it

Chain and agent

the steps are written in the code or the model chooses them itself

Agent cycle

query → tool call → result → query again until the problem is solved

Harness

all code around the model: Claude Code, Cursor, your service

MCP

standard to connect tools and data to any AI application

Skill

instructions folder that the agent reads only when needed

Subagent

helper with its own context, returns only the total

Hook

your script for the binding event: prohibit, ask the person, add context, check

RAG

find the necessary documents and put them in the request before responding

Eval

set of tasks used to check that the agent is not broken

Prompt cache

restart the request for 5–10% of the price

Model and context

Token. The model reads the text not letter by letter or word by word, but in chunks. These pieces are called tokens. Everything is counted in tokens: how much will fit into the request, what are the limits and how much will you pay. More details about them in the section about tokens.

Context window. How many tokens the model will read at one time, along with its response. For most new Claude models, this is 1 million. It’s not worth hammering the window to capacity. Each token costs money, and the longer the context, the worse the answers. Anthropic calls this “context rot.”

System prompt. Rules for the model that come before the user's messages: who she is, what she can do, and in what form she can respond. In Claude Code, the CLAUDE.md file from the repository also ends up here. The system prompt goes into the model with each request. Therefore, for each extra line in it you pay many times.

How the model works

Tool use. This is how the model gets hands. You describe the function: what it is called, what it does, what its parameters are. For example, get_weather with parameter location. The model itself does not launch the function. She replies: “call get_weather for Moscow.” The function is called by your code and returns the result to the model. Anthropic calls this a contract: you decide what the model can do, and she decides when.

Chain (workflow, agents chain) and agent (AgentsLLM). In the chain, the order of steps is written in the code. For example: understand what the request is about and send it to the right thread. The agent chooses the order himself: what steps to take and what tools to call. The chain is more predictable and cheaper, the agent is more flexible. Anthropic advises starting with the simplest things. Often one well-written query to the model is enough.

Agent cycle. The same thing is repeated: request, calling a tool, result, request again. This continues until the model responds with text. This cycle is what makes the tooled model an agent. The pseudocode and diagram are below, in the section about the system design.

Harness. All the code is around the model. It collects the request, spins the loop, calls tools, stores history and checks actions. Claude Code, Cursor, Agent SDK and your Python service are all bindings. The same model works differently in different harnesses. Therefore, the AI ​​engineer most often builds the harness. Its parts are discussed in detail in the article “What is Harness?”.

How does an agent expand?

MCP (Model Context Protocol). An open standard for connecting external systems to AI applications. It has been compared to USB-C. An application, such as Claude Code, connects to MCP servers. The server gives him tools, data and ready-made prompt templates. Integration with GitHub, database or Jira is written once, and it works in any application that supports MCP. The standard is changing quickly. I am relying on the July 28, 2026 version.

Agent Skill. Folder with the file SKILL.md, sometimes with scripts and reference books. At first, the model sees only a short description of the skill, about 100 tokens. She reads the entire text, up to 5 thousand tokens, when the task matches the description. The remaining files are worthless until they are opened. And if there is a script inside, only what it outputs gets into the context.

AI engineering for those who roll in: agents, MCP, tokens and cache with numbers

How the skill falls into context. Figures from Anthropic's documentation on Agent Skills.

Subagent. An assistant with his own context and his own tools. The main agent gives him a task and gets back only the result. Why is this necessary: ​​noisy work, such as searching through code or reading logs, does not clog the main context. You can give the subagent a cheap model. But his requests are counted within the same limits.

Hook. Your script that the harness runs itself when something happens. The model has nothing to do with it. There are many reasons: the beginning of a session, a new user request, the moment before and after calling the tool, the end of the response, context compression, launching a subagent.

The script receives JSON as input with details: for example, which tool is called and with what parameters. In response, he can prohibit the action: exit with code 2 or return deny with a reason, and the model will see it. Can give the question to a person (ask) or resolve it without asking too much (allow). Can add text to the context of the model. Or it can just do its job: run the linter after editing the file, record the action in the log, send a notification.

The project hooks are in .claude/settings.json. Mandatory for the entire company are placed in managed settings: the developer will not disable them. There are also hooks that themselves ask the model when a judgment is needed. But a regular hook works without a model and the same way every time. This is how it differs from the line in the prompt: the model can skip the instruction, but the hook will always work. Hence the rule: a skill advises, a hook guarantees.

Quality and data

RAG (retrieval-augmented generation). Before calling the model, the system searches for the necessary pieces of documents and puts them in the request. The model answers based on what it finds, not from memory. Increasingly, agents are simply given a search tool and they do the searching themselves.

Eval. These are tests for the agent. You collect problems for which you know the correct answer, and run them after each change of model, prompt, or tools. A regular test expects an exact result, but the model responds slightly differently each time. Therefore, it is more difficult to check the agent. Huyen sees estimation as the biggest challenge in AI engineering.

The cache in the dictionary got one row in the table. Judging by the vacancies, it is asked about least often, so it has a separate section.

How the system works

The model does not remember anything between requests. Everything that the agent “knows” about the task is reassembled and sent by the harness at each step. The request is always structured the same way: first, descriptions of the tools, then the system prompt, then the entire conversation history.

AI engineering for those who roll in: agents, MCP, tokens and cache with numbers

What does the LLM system consist of? The model receives the collected request and returns text or a request to call the tool.

The agent cycle itself in the Anthropic documentation is the usual while. Here it is in pseudocode:

# Псевдокод агентного цикла
история = [задача_пользователя]
while True:
    ответ = модель(инструменты, системный_промпт, история)
    история.append(ответ)
    if ответ.stop_reason != "tool_use":
        break                                  
        # модель ответила текстом: готово
    результаты = [выполнить(вызов) for вызов in ответ.вызовы]
    история.append(результаты) # блоки tool_result

The stop_reason field explains why the model stopped. If tool_use is there, the model wants to call the tool, and the loop continues. Any other value, for example end_turn or max_tokens, means: the model has finished or hit the limit. Then the cycle ends.

AI engineering for those who roll in: agents, MCP, tokens and cache with numbers

Step 3 executes the application code. This is where a hook can prevent an action.

The cycle itself is short. Almost all the work goes around it:

  • tools: your own, connected via MCP, and server ones, which are performed by the vendor himself, for example, searching the Internet or running code;

  • subagents: take part of the work and return a short report;

  • hooks: check actions before and after;

  • memory: is not stored in the model, but in files and in git.

Anthropic explains why memory is needed in an article about long-term agents. Each new session starts with a clean slate. Therefore, the agent leaves a progress file, a list of tasks with statuses, and a commit history to the next session.

How this looks in practice can be seen in the usual Claude Code setup. In my personal repository, the hook logs risky actions before each call to Bash, Write, and Edit. Another hook tells each request which model is suitable for the task. There are three subagents: cheap read-only, medium and strong. And more than a dozen skills that are loaded only when needed. These are all simple configuration files. But they are the ones who decide what gets to the model and what the agent can do.

A common pitfall: the agent confidently says “done”, but half the job is done. In the same article, Anthropic describes two common failures. The agent tries to do everything in one go. Or announces he's finished too early. Persuasion in the prompt helps little here. The binding helps: a list of requirements with statuses and a way to check the result. For example, run tests or open the application in the browser.

How are tokens counted?

LLM is paid for in tokens, and the tokens at the entrance and at the exit cost differently. As of October 28, 2026, Claude Sonnet has 5.5 million input tokens worth $2, а миллион выходных $10. The output is 5 times more expensive. Descriptions of the tools are also included in the input. In the example from the documentation, one tool with a short scheme and a user question together take up 403 tokens.

The model doesn't remember anything, so at every step the whole story is sent to it again. Let's calculate using a conditional example:

  • at the beginning of each request 12 thousand tokens: descriptions of tools and system prompt;

  • user's first message costs 200 tokens;

  • at each step the model responds with 400 tokens, and the tool returns another 2,500;

  • only 30 steps on Sonnet 5.5.

AI engineering for those who roll in: agents, MCP, tokens and cache with numbers

Conditional scenario. Sonnet 5.5 prices as of 10/28/2026.

At the last step, the request weighs 96,300 tokens. This is less than a tenth of the window. But in all 30 steps, the model read 1.63 million tokens, 17 times more. Each step pays anew for everything that came before it, and the amount grows faster than it seems. Without cache, such a task would cost $3.38. The model’s responses for all steps together take only 12 thousand tokens. Almost all the money goes towards entry.

A separate question is how many tokens the Russian text takes up. Different languages ​​are cut into tokens in different ways. In a study by Petrov et al (NeurIPS 2023), the same text in different languages ​​took up to 15 times more tokens. For Russian and English, I made my own little measurements. I took three pairs of identical texts: documentation, prose and code with comments. About 1,000 characters per language, Claude tokens.

AI engineering for those who roll in: agents, MCP, tokens and cache with numbers

Measuring 10/28/2026, script calc/claude_cli_ru_en.py. The sample is small, this is a guideline, not a study.

On older models (Sonnet 4.6, Haiku 4.5), Russian text took 1.6 times more tokens than English. On the new Sonnet 5.5 the difference is only 1.27 times.

I wonder why. Russian has hardly changed: there were 402 tokens, now 415. And English increased from 252 to 327, by 30%. This matches Anthropic's documentation: starting with Opus 4.7, models cut text in new ways and give about 30% more tokens for the same text.

The conclusion is simple: consider tokens the model that you will use. For this, Anthropic has a free endpoint count_tokens. True, it gives an estimate and does not take into account the cache.

How does the prompt cache work?

Let's go back to 1.63 million tokens. Almost everything that the model reads at step 30, it already read at step 29: the same tools, the same system prompt, the same history. Only the piece at the end is new. The cache allows you to avoid reprocessing a repeating start.

AI engineering for those who roll in: agents, MCP, tokens and cache with numbers

Block order and what flushes the cache, according to Anthropic documentation as of 10/28/2026.

How does this work. The request is always read in the same order: tools, system prompt, messages. You put a mark in the request to which location to cache. There can be up to four such marks. Everything up to the mark is saved. The next request will go into the cache only if its beginning coincides with the entire saved one, up to the symbol and up to the picture. The cache lives for 5 minutes, and each hit extends the period for free. For an additional fee you can store it for an hour. Short requests are not cached: new Claude models require at least 512 tokens. There will be no error, the cache simply will not turn on.

In our cache example, each step reads the old one for $0,10 за миллион и записывает в кэш только новый кусок. Итог $0.51 instead of $3.38, 6.6 times cheaper. The requests are the same, only how the server processes them changes. When a paid cache entry pays off, it is calculated in detail in the article “How much does a request to LLM actually cost”. Anthropic has a five-minute cache already from the second request with the same beginning.

Breaking the cache is easier than it seems. Any difference at the beginning of the request resets everything after it:

  • changed the description of the tool: the entire request will be reset;

  • enabled Internet search or inserted the current time into the system prompt: the system prompt and history will be reset;

  • changed tool_choice or added a picture: the history will be reset.

Hence one rule: put the unchanged at the beginning, the new at the end. There should be no dates, random IDs, or permutations of instruments at the beginning of the request.

Checklist: ten practices for the first agent

  1. Start with one query to the model. A chain is better than an agent as long as the task steps can be written in code.

  2. Put the unchanged one at the beginning of the request, the new one at the end. The system prompt should not contain time, random IDs or other changing data.

  3. Do not change the set and order of instruments mid-session.

  4. See usage of each answer. If cache_read_input_tokens is almost always zero, your cache is broken.

  5. Consider tokens the model you will use. Different models have different tokens, the difference reaches 30%.

  6. Keep the story short. Give noisy work like searching and logging to subagents, and store the status in files, not in correspondence.

  7. Put long instructions in skills, not in system prompts. Then each request will contain only their short description.

  8. Do what should always be executed with a hook, and not with a line in the prompt.

  9. Give the agent a way to test itself: tests, build, browser. Otherwise he will say "done" too early.

  10. Connect MCP servers and skills only from sources you trust, and give the agent only the necessary rights. The Anthropic documentation compares someone else's skill with someone else's program that you set for yourself.

Series “AI engineering for those who are rolling in”

This is a series of three articles. Links to the remaining parts will appear here when they are released.

  1. "AI engineering for those who roll in: agents, MCP, tokens and cache with numbers" (you are reading it now)

  2. “Reliability of AI agents for those who roll in: retries, idempotency, sagas and durable execution” (in progress)

  3. “Agent system for those who roll in: chain or agent and all together using the example of a support agent” (in progress)