Article 2/4 in the AI Agents series — What is an AI agent? · AI agents on the team · Who answers when the agent gets it wrong?
You know what an AI agent is. Now let's build one. Not in theory — in production, with a concrete case and the mistakes I wish I had avoided.
The week I put my first agent into production, it cost me 40 dollars in tokens in a single night. Not because it worked badly — because it worked too well. A poorly bounded automatic retry loop on a temporarily unavailable API: the agent was going round in circles, the token counter kept climbing, and nobody was watching.
That's the lesson I learned fastest: building an AI agent is not a data science project. It's an architecture project. The most expensive mistakes aren't technical — they're structural.
In the first article of this series, I laid the foundations: the ReAct loop, the four building blocks (memory, planning, tools, action), the difference between a chatbot and an agent. Here, we get practical. How I built three agents that run in production on my personal stack, which frameworks I use, and above all: the pitfalls nobody mentions in the tutorials.
Choosing your framework — or not
The natural reflex when you want to build an agent is to compare frameworks. LangGraph, CrewAI, Claude Agent SDK, OpenAI Agents SDK — the market offers a dozen of them, each with its own promises.
But here's what nobody says in the tutorials: you don't need a framework to build your first agent.
An agent, in its simplest form, is an LLM (large language model) + a well-built system prompt + a tool (such as web search). Mistral Le Chat, ChatGPT or Claude let you create that in a few clicks — without writing a single line of code. It's the best starting point.
The landscape in 2026
Frameworks become useful when the needs get more complex:
| Need | Tool | In a nutshell |
|---|---|---|
| First agent, zero code | Mistral Le Chat, ChatGPT, Claude | Prompt + web search, ready in 10 minutes |
| Quick prototype in code | CrewAI or OpenAI Agents SDK | A few dozen lines are enough |
| Production with complex states | LangGraph | Error recovery, persistence, state graph |
| Turnkey enterprise deployment | Claude Agent SDK | Pre-built plugins, business connectors |
| Code generation | Mistral Vibe | Coding agent powered by Devstral 2, open source, sovereign |
The natural progression: you start without code to validate the use case, then you migrate to a framework when the limits show up — not before. Too many projects fail because they chose the infrastructure before validating the need.
Mistral Vibe: a case apart
Mistral Vibe is not an agent framework in the strict sense. It's a coding agent — a command-line tool, powered by the Devstral 2 model, that implements code from natural-language instructions. In practice, it's the hammer, not the carpenter: it executes the code, but it's another program (the orchestrator) that decides when to call it and checks the result. And it's the only credible European alternative in this space.
Five steps to build an agent that holds up in production
Step 1: Define the goal in terms of outcome, not technology
"Deploy an AI agent" is not a goal. "Cut the production time of a web page from 4 hours to 20 minutes" is one.
Every agent I have put into production answers a mission stated in one sentence:
- Figma → Code agent: "Turn a Figma frame into a working web component, visually verified, in under 10 minutes."
- PRD agent: "Produce a structured PRD (Product Requirements Document) from raw discovery notes, in under 15 minutes."
- Digital Audit agent: "Generate an audit report on a company's digital presence in under 10 minutes, from its URL."
If you can't state the mission in one sentence with a deliverable and a deadline, you don't have an agent use case yet — you have a craving for technology.
Step 2: Choose the tools the agent will drive
An agent without tools is a brain without arms. But an agent with too many tools becomes unpredictable — it picks the wrong tool at the wrong time, or chains useless calls that send the cost through the roof.
My rule: a maximum of 5 tools per agent. Beyond that, I split into specialized sub-agents.
For my three agents in production:
Figma → Code agent:
- Figma connector via MCP (Model Context Protocol — reading the mockup)
- Mistral Vibe (code generation)
- Headless browser (screenshot for verification)
- Visual comparison (pixel diff between mockup and rendering)
PRD agent:
- File reading (discovery notes, transcripts)
- Web search (competitive benchmark, market data)
- Structured generation (PRD template with mandatory sections)
Digital Audit agent:
- Technical analysis (stack, security headers, performance)
- SEO analysis (meta tags, structure, speed)
- Web search (social presence, reviews, job postings)
- Report generation (structured summary)
Between 3 and 4 tools per agent — enough to cover the mission, not enough for the agent to get lost. Each tool has a precise role, and the agent chains the steps with no human intervention between them.
Step 3: Design the system prompt and the guardrails
The system prompt is your agent's constitution. It's the document that defines what it can do, what it must never do, and how it should react when things go wrong.
Three non-negotiable blocks:
Identity and mission — Who the agent is, what its goal is, what the expected deliverable is. The more specific it is, the less the agent drifts.
Constraints and prohibitions — What the agent must never do. For my Figma → Code agent: never modify the source Figma file (now that MCP allows it, the mistake happens fast), never deploy to production, always submit the result for validation before delivery. It's prompt injection — the #1 vulnerability of agents — that makes these guardrails critical.
Degradation rules — What does the agent do when a tool doesn't respond? When the result is inconsistent? When it has consumed more than X tokens without making progress? Without these rules, you get the infinite loop at 40 dollars (minimum) a night.
Step 4: Test in a sandbox before any production release
An agent that works in a demo doesn't necessarily work in production. Conditions change: APIs have rate limits, input files aren't always clean, the network goes down.
My test protocol:
- Unit tests per tool — Each tool is tested in isolation with normal inputs and degraded inputs (corrupted file, API timeout, empty response).
- End-to-end tests — The complete agent is run on 10 representative cases, with variations (simple vs. complex mockup, valid vs. redirected URL, structured notes vs. rough draft).
- Cost tests — I measure the number of tokens consumed per typical mission. If an agent exceeds 100,000 tokens for a simple task, it's looping. I set a token ceiling per execution — a circuit breaker that kills the agent if it goes over budget.
- Adversarial tests — I inject malicious data into the inputs to check that the guardrails hold. Web content that attempts a prompt injection, a file that contains hidden instructions.
Step 5: Deploy with human-in-the-loop
None of my agents runs in full autonomy. Each one has a human validation point before the final action.
The Figma → Code agent generates the component, takes the screenshot, produces the visual diff — then shows me the result before creating the commit. The PRD agent produces the document — then waits for my review before sharing it. The Audit agent generates the report — then waits for my validation before sending.
This isn't excessive caution. It's architecture. An autonomous agent that sends an audit report containing a factual error destroys the credibility it was supposed to build. The human in the loop is not a brake — it's a safety net that lets you give the agent more autonomy on everything else.
Getting your hands dirty: a first agent in a weekend
You've read the five steps. You could read three more articles, compare five frameworks and watch ten YouTube tutorials. Or you could open Mistral Le Chat and build your first agent within the hour.
The best way to understand how an AI agent works isn't to read the documentation — it's to build one, test it, see where it breaks, and fix it. The prompt I'm sharing here is not a destination. It's a starting point. Take it, break it, change the filters, change the sector, see what changes. It's by twisting the prompt that you'll understand what makes an agent hold — or drift.
The case: building a regulatory watch agent with Mistral Le Chat
In the previous article, I mentioned regulatory watch as a typical agent use case: monitoring official publications, filtering what concerns your sector, producing a structured summary. Two hours of human work every morning, compressed into a few minutes.
Let's build it. Not with a framework, not with code — with Mistral Le Chat, which lets you create a custom agent in a few clicks. A single agent, one tool (native web search), one bounded goal. The full prompt is available on GitHub (agent-veille-reglementaire) — you can copy and paste it and adapt it to your sector.
Step 1 applied — The goal in one sentence
"Analyze the latest official publications and produce a summary of the texts that concern digital in the public sector, with for each one: the essentials in three lines, the impact level and the link to the source."
Not "monitor all French regulation". Not "produce a legal analysis". A tight scope — one sector, one type of source, one defined deliverable.
Step 2 applied — A single tool, used well
The agent uses Mistral Le Chat's native web search. No need for an API connector, no vector database. It consults the official sources (Légifrance, CNIL, ANSSI, DINUM, European Commission), extracts the content and produces the summary.
In the system prompt, you explicitly list the sources to consult. It's the minimalist version of step 2 — a single tool, but well framed.
Step 3 applied — The system prompt and the guardrails
This is where the quality of the agent is decided. The prompt defines three things.
The filtering criteria — the agent only keeps texts that relate to digital accessibility (RGAA), cybersecurity (NIS2), personal data (GDPR), artificial intelligence (AI Act), dematerialization or open data. Everything else is ignored, even if it's recent.
The impact grid:
| Level | Meaning | Typical example |
|---|---|---|
| Informational | No immediate action, good to know | Annual report, study |
| To anticipate | Likely impact within 6 to 12 months | New framework, draft decree |
| Action required | Short-term obligation | Implementing decree, compliance deadline |
The guardrails — and this is where the first test corrected me. During my trials, the agent was surfacing texts published months earlier, simply because they appeared in recent search results. I had to add an explicit rule: "Never rely on the indexing date — only the date displayed on the source page counts. If the date cannot be verified, do not include it."
Other guardrails: never give legal advice (summarize, don't rule), always cite the source with a verifiable link, and above all — produce an empty summary when there is nothing to report. An agent that always finds something, even when there is nothing, is an agent that hallucinates to justify its existence.
Step 4 applied — Test on five varied days
Don't test on a quiet day when nothing was published. Pick five varied days:
- A day with a directly relevant publication (detection test)
- A day packed with out-of-scope publications (filtering test — the agent must ignore them)
- A day with an ambiguous text, on the edge of the scope (judgment test)
- A day with no relevant publication at all (the agent must produce an empty summary, not make things up)
- A day with a long, complex text (synthesis test — does the summary fit in three lines?)
Case 4 is the most revealing. It's the same reflex as the consultant who pads out deliverables to fill the PowerPoint — except that the agent does it without a guilty conscience.
Step 5 applied — The human in the loop
The agent produces the summary. You read it with your coffee. You decide whether a text deserves to be passed on to the legal team, the CIO or the executive committee.
The day the filtering is reliable, you add a building block: automatic sending by email. Then another: archiving in a knowledge base. Then another: cross-referencing with your compliance register to identify the gaps.
That's the incremental logic. Santiago Fernández de Valderrama Aparicio, AI Product Manager, applied the same approach to automated job hunting: an agent that evaluates a job posting became a twelve-mode system that has processed more than 500 of them, generated 354 tailored CVs and sent 68 applications — not by building everything at once, but by stacking building blocks validated one by one.
Three agents in production: lessons from the field
Agent 1: Figma → Code → Visual verification
The mission: turn a Figma frame into a working web component, visually verified against the mockup.
The workflow:
- The agent reads the Figma frame via the Figma MCP server — it retrieves the structure, the design tokens, the referenced components.
- It passes the specification to Mistral Vibe, which generates the code (HTML, CSS, components).
- It opens the result in a headless browser and captures a screenshot.
- It compares the screenshot with the original Figma mockup — alignment, colors, spacing, typography.
- If the diff exceeds a tolerance threshold, it identifies the gaps and reruns Mistral Vibe with targeted corrections.
- It iterates (3 passes maximum) until convergence, then submits the result to me.
What works: on components of medium complexity (card, hero section, form), the agent reaches a publishable result in 2 to 3 iterations. The time saved is real — what used to take 2 to 4 hours by hand takes 10 to 20 minutes.
What breaks: complex layouts with many responsive variants. The agent converges on desktop but diverges on mobile. I learned to slice things up: one Figma frame = one component = one agent execution. No whole page in one go.
Average cost: 30,000 to 80,000 tokens per component, i.e. between €0.50 and €2 depending on the model and the number of iterations. On Devstral 2 via Mistral Vibe, the cost is at the low end of the range.
Agent 2: Express PRD
The mission: turn raw discovery notes (user verbatims, interview transcripts, support tickets) into a structured Product Requirements Document.
The workflow:
- The agent ingests the input files — loose notes, transcripts, annotated screenshots.
- It extracts the recurring themes, the user pain points, the opportunities mentioned.
- It searches for complementary market data (competitive benchmark, sector trends).
- It structures a complete PRD: context, problem, target persona, user stories with acceptance criteria, success metrics, risks and dependencies.
- It submits the draft for validation.
What works: the capacity for synthesis is impressive. The agent identifies patterns in the verbatims that I wouldn't have seen manually — correlations between user pain points and feature requests that aren't obvious when you read the notes one by one.
What breaks: prioritization. The agent generates exhaustive user stories but can't tell the must-have from the nice-to-have. That makes sense — prioritization is an act of strategic judgment that depends on the business context, not on the input data. This is exactly where the human in the loop comes into its own.
Average cost: 50,000 to 120,000 tokens depending on the volume of input notes. Between €1 and €3.
Agent 3: Express digital audit
The mission: generate a complete audit report on a company's digital presence from its URL, in under 10 minutes.
The workflow:
- The agent receives a URL and launches a technical analysis: technology stack, security headers, performance score, SSL certificate.
- It analyzes the SEO: meta tags, heading hierarchy, loading speed, schema.org.
- It scrutinizes the social presence: LinkedIn profiles, Twitter/X, latest posts, frequency.
- It looks for complementary signals: customer reviews (Google, Trustpilot), open job postings (a signal of growth or turnover), recent press mentions.
- It compiles everything into a structured report with a score per dimension and prioritized recommendations.
What works: the report is stunning as preparation for a sales meeting or in light due diligence. In 10 minutes, I have a more complete picture than what most consultants produce in half a day. The weak signals are often the most useful — the job postings that reveal a strategic pivot, the security headers that betray an aging infrastructure.
What breaks: sites that block bots. The agent handles the classic cases (Cloudflare, rate limiting) but some sites remain impenetrable. I added a degradation rule: if a domain resists, the agent flags it in the report instead of looping.
Average cost: 40,000 to 100,000 tokens. Between €0.80 and €2.50.
The pitfalls nobody mentions
The "it works in the demo" trap
An agent that succeeds in 8 demos out of 10 will fail 3 times out of 10 in production. The difference: in a demo, the inputs are clean. In production, the Figma mockups have badly named layers, the discovery notes are in franglais, the URLs redirect three times.
I learned to size my tests on the degraded cases, not the ideal ones. If the agent holds on dirty inputs, it will hold everywhere.
Chain hallucination
This is the most underestimated risk. A multi-step agent propagates errors: if step 2 hallucinates a fact, steps 3, 4 and 5 build on it without questioning it. The final result looks coherent — but it's wrong.
The countermeasure: verification checkpoints between the critical steps. My PRD agent, for example, checks every cited source before moving on to structuring. If a source isn't accessible, it removes it instead of keeping it.
The cost that explodes for lack of monitoring
An agent stuck in a retry loop on an unavailable API can burn hundreds of dollars in a few hours. I've been there: 40 dollars of API cost in one night, because an agent was looping on a temporarily unavailable service and nobody (me) had put a circuit breaker in place. When you deploy several agents in parallel, cost overruns multiply fast.
Three non-negotiable protections:
- Token ceiling per execution — The agent stops automatically beyond a threshold.
- Timeout per step — If a tool call doesn't respond within 30 seconds, the agent abandons that action and moves to a plan B.
- Daily budget — Beyond 10 euros per day, all execution is suspended and an alert is sent.
Shadow agentic
This is the last pitfall — and the most organizational one. Employees deploy their own AI agents via no-code tools, without IT oversight. Agents connected to the CRM (customer relationship management tool), to the mailbox, to the databases — without guardrails, without monitoring, without a usage policy.
It's the 2026 version of shadow IT. Except that classic shadow IT couldn't send emails to your customers, modify your data or exfiltrate your contact database. A badly configured agent can.
If you're a CDO (Chief Digital Officer) and you don't have an AI agent usage policy yet, you already have one — your teams'.
What this article doesn't cover — and why
I deliberately left out two topics that each deserve their own article.
The first is deploying agents in teams — not on a personal stack, but in an organization with non-technical users, existing processes and resistance to change. That's the subject of article 3.
The second is governance: who validates what an agent is allowed to do? Who is responsible when an agent gets it wrong? How do you audit an agent? That's article 4.
The complete series:
- Article 1 — What is an AI agent? Definition, architecture, examples
- Article 2 (this one) — How to build an AI agent? Frameworks, steps and pitfalls to avoid
- Article 3 — AI Agents on the Team: What Changes When Execution Costs Zero
- Article 4 — Who Answers When the Agent Gets It Wrong? Governing AI Agents
Building an agent is, in the end, fairly simple. Running it in production without it costing you a fortune, hallucinating into the void or sending an embarrassing email to a customer — that's the real craft.
To get the next installment as soon as it's published, subscribe to the RSS feed or follow me on my LinkedIn profile.
Sources
- Mistral Le Chat — chat.mistral.ai
- available on GitHub (agent-veille-reglementaire) — github.com
- automated job hunting — santifer.io
- my LinkedIn profile — linkedin.com
Take this article to an AI
Pick a request, then the assistant. The article is passed along with the question.



