Hybrid AI agent cuts conversation cost to 3.8 rubles
A free-form LLM can hold a conversation, but it is expensive and easily drifts off course. The author split the responsibilities: a finite-state machine selects the permitted next step, a classifier interprets the message, and a larger model formulates the response. In the pilot, the average conversation cost 3.8 rubles, compared with an estimated 16 rubles for a powerful LLM without this framework.
AI-processed from Habr AI; edited by Hamidun News
A free-form chat with an LLM feels natural, but it has two troublesome habits in a product flow: it consumes a lot of tokens and can forget where it was supposed to be taking the user. A scripted bot is cheaper and more predictable, but it breaks as soon as someone types, instead of pressing a button: “The intern can serve coffee!” The article's author built a hybrid: ordinary code controls the route, while the models handle message interpretation and natural-sounding responses.
In a pilot involving 88 users, all model calls cost 169 rubles. The average cost per conversation was 3.8 rubles. According to the author's calculations, the same conversation on a powerful LLM without a deterministic framework would have cost about 16 rubles.
The state machine decides, the LLM explains
The conversation is divided into states: introduction, training, finale, offer, refusal, and stop. Only code can move the user between them. It knows which transitions are allowed, checks quiz answers, and decides when to display the commercial offer.
When the user presses a button, the model receives prepared context and writes a response. When free-form text arrives, a low-cost classifier is called first. It selects one of the permitted actions: continue the topic, explain it more simply, move to another part of the program, or simply keep the conversation going. The state machine validates the selection, and the narrator model formulates the reply.
For example, a user asked for a simpler explanation of neural networks and then made a joke about an intern and coffee. In the first case, the state machine knew the exact topic and called only the narrator. In the second, the classifier identified the joke as a conversational aside, the code retained the current state, and the narrator responded before steering the conversation back to the lesson. This required two model calls instead of handing the model full control.
Where the savings come from
The main expense comes not from the length of the conversation itself, but from the architecture of each turn. In the author's implementation, a button press cost about 35 kopecks and a text message 36 kopecks. An average conversation totaled 3.8 rubles. A small model served as the classifier, while a more capable one acted as the narrator.
An accidental swap of the models during the pilot clearly demonstrated the cost of incorrect routing. The more expensive model, assigned to classification, handled 31% of calls but accounted for 44% of spending. In the standard configuration, the classifier represented roughly 1% of the cost. The practical conclusion is straightforward: use the inexpensive model where there is a short list of options, and the expensive one where text quality genuinely matters.
Reliability does not depend on prompts alone. Transitions and quizzes are checked offline without a model, difficult user messages are added to an eval test set, and the state machine validates the classifier's selected action again. For emergencies, a spending limit of 40 rubles per session is set; once it is reached, templated responses take over.
What the pilot showed
Of the 88 visitors, 86 started a conversation, 69 completed the questionnaire and entered the learning program, but only seven reached the end of the personalized route. During a group session, the agent served 71 people simultaneously without failures. The commercial offer was shown to 33 participants, and ten clicked the “Interested” button.
This is an important limitation of the result: the pilot was small, the figures were reported by the author, there was no control group, and the article does not show actual purchases. It is therefore too early to claim a proven increase in revenue. The engineering hypothesis, however, was confirmed quite clearly: a finite-state machine can keep the journey on track while an LLM makes the interaction feel less wooden.
For developers, this provides a concrete template. Keep state and business rules in code, restrict the classifier to permitted transitions, assign models according to task complexity, and measure the cost of a completed user journey rather than the price of a single token. Once that is done, the main bottleneck is no longer model pricing but engagement: how to move someone from the first joke to a useful outcome and a purchase.
- Nov 8, 2026Amp Spaces delegates tasks to agents and runs up to 16 parallel threads
- Nov 8, 2026Agent Desktop gained 2,243 stars in a day and reached GitHub’s top rankings
- Nov 8, 2026Anthropic cuts Claude latency in long conversations by roughly 35%
- Nov 8, 2026Mago Studio brings five stages of AI video production together on a local computer
Key Questions Answered
What are the key details on The state machine decides, the LLM explains?
The conversation is divided into states: introduction, training, finale, offer, refusal, and stop. Only code can move the user between them. It knows which transitions are allowed, checks quiz answers, and decides when to display the commercial offer. When the user presses a button, the model receives prepared context and writes a response. When free-form text arrives, a low-cost classifier is called first.
Where the savings come from?
The main expense comes not from the length of the conversation itself, but from the architecture of each turn. In the author's implementation, a button press cost about 35 kopecks and a text message 36 kopecks. An average conversation totaled 3.8 rubles. A small model served as the classifier, while a more capable one acted as the narrator. An accidental swap of the models during the pilot clearly demonstrated the cost of incorrect routing.
What the pilot showed?
Of the 88 visitors, 86 started a conversation, 69 completed the questionnaire and entered the learning program, but only seven reached the end of the personalized route. During a group session, the agent served 71 people simultaneously without failures. The commercial offer was shown to 33 participants, and ten clicked the “Interested” button.
Ship AI Faster with Founders, Engineers & Weekly Architecture Reviews
Inside Vibe Club (hamidun.com/club) — weekly live masterminds with Zhemal Khamidun, Tech Radar, full LMS access, and 370+ production Claude Code skills.
The AI world, distilled — once a week
Seven stories that actually mattered, hand-picked. No noise, no reposts, no press releases.
Done! Check your inbox for a confirmation.