<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Saoussen Mannai on Medium]]></title>
        <description><![CDATA[Stories by Saoussen Mannai on Medium]]></description>
        <link>https://medium.com/@saoussenmannai?source=rss-4053b29bfedd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZX6sc6m1kQUcv_N18hYirg.jpeg</url>
            <title>Stories by Saoussen Mannai on Medium</title>
            <link>https://medium.com/@saoussenmannai?source=rss-4053b29bfedd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 21:55:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saoussenmannai/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Agents Aren’t Just LLMs With Tools: What It Really Takes to Build One]]></title>
            <link>https://medium.com/@saoussenmannai/agents-arent-just-llms-with-tools-what-it-really-takes-to-build-one-95d992733f02?source=rss-4053b29bfedd------2</link>
            <guid isPermaLink="false">https://medium.com/p/95d992733f02</guid>
            <category><![CDATA[ia-agents]]></category>
            <category><![CDATA[fintech]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Saoussen Mannai]]></dc:creator>
            <pubDate>Mon, 02 Nov 2026 20:48:59 GMT</pubDate>
            <atom:updated>2026-11-02T21:50:23.394Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Planning, tools, memory, evaluation, and the guardrails that matter more than any of them.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*XMU-NHUEOvjhfK1WZTlk2w.gif" /></figure><p>Ask an LLM how to process a supplier invoice and you’ll get a clean, accurate list of steps. Ask it to actually do it (read the PDF, pull out the amounts, check the supplier against your records, flag the mismatch, prepare the accounting entry) and you hit a wall. Knowing the steps is not the same as carrying them out.</p><p>That gap is where AI agents live. Closing that gap is mostly an engineering problem, not a prompting problem.</p><p>This article covers what an agent actually is, the parts it needs, when multiple agents are worth it, and why reliability, not intelligence, is the hard part.</p><h3>An LLM answers. An agent pursues a goal.</h3><p>A basic LLM interaction takes an input and produces an output. That’s powerful, but it doesn’t inherently give the model a way to act in an external environment. It can’t open your database, retry a failed API call, or notice that an invoice total doesn’t match its line items.</p><p>An agent is the system built around the model to make those things possible. It takes a goal, chooses an action, executes it through a tool, observes what happened, and decides what to do next. The LLM is usually the reasoning engine inside. It is not the whole machine.</p><p>Seeing it this way changes where the effort goes. A stronger model helps, but most of an agent’s quality comes from the structure around it: how clearly the task is defined, how good the tools are, and how strictly the results are checked.</p><h3>The five building blocks</h3><p>Whatever framework you use, most agents are built from the same five parts [3].</p><h4>1. A well-defined goal</h4><p>“Review incoming invoices and flag inconsistencies” sounds clear until the agent has to act on it. What counts as an inconsistency? Which data sources are trusted? When is the job done? A capable model working from a vague goal will confidently do the wrong thing. So the first design task is turning the instruction into explicit inputs, outputs, constraints and a completion condition.</p><h4>2. Planning</h4><p>Instead of attempting everything at once, the agent breaks the goal into steps: retrieve the invoice, extract the fields, validate them, compare them against accounting rules, report the issues. The plan can be fixed in code, generated by the LLM, or a mix of both. Patterns like ReAct [1], where the model alternates between reasoning and acting, are a common starting point. But a generated plan is a hypothesis, not a guarantee. It has to be checked against what actually happens.</p><h4>3. Tools</h4><p>Tools are how an agent touches the world: APIs, databases, OCR services, code execution, business applications. Most models now support structured tool calling, and protocols like MCP [5] are standardizing how tools are exposed. The key point: the model only <em>proposes</em> a tool call, and your system executes it. Validating arguments, controlling permissions and handling failures are your job, not the model’s.</p><h4>4. Memory</h4><p>Short-term memory holds the current task: observations and intermediate results. Long-term memory keeps what’s useful across tasks, such as past decisions or preferences. External knowledge, often through retrieval-augmented generation (RAG) [2], gives access to documents and records. Keep one distinction in mind: storing past interactions is not the same as learning from them. An agent with perfect memory can repeat the same mistake forever.</p><h4>5. Evaluation</h4><p>An agent should never assume an action worked. Did the extraction return every required field? Does the total match the line items? Did the API call succeed? Checks can be deterministic rules, a second model, external validation or a human. This is the part that matters most, because LLMs fail quietly: they produce outputs that look right and aren’t.</p><h3>The agentic loop</h3><p>Put those parts together and you get a loop, not a pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*3sX46aRXUemmWVLxxw9gdw.gif" /><figcaption><em>The agentic loop: act, check, adjust, repeat until the goal is reached.</em></figcaption></figure><p>After each action, the agent observes the result, evaluates it, and either moves on or updates its plan. Say the extraction step returns an invoice with no supplier ID. Instead of failing or guessing, the agent can look the supplier up and then continue.</p><p>That flexibility is the whole point of an agent, and also its main risk. An unbounded loop can burn through tokens, hammer an API, or drift away from the goal. Every loop needs hard limits: a maximum number of steps, time and cost budgets, and a clear list of allowed actions.</p><h3>One agent or many?</h3><p>Multi-agent systems are popular right now, and it’s tempting to split everything into specialists. One of the most common patterns is supervisor + workers [4]. Applied to the invoice workflow from the opening, it could look like this:</p><ul><li>A <strong>document processing agent</strong> extracts the invoice information.</li><li>A <strong>validation agent</strong> checks fields, totals and supplier records.</li><li>An <strong>accounting agent</strong> prepares the accounting entry.</li><li>A <strong>supervisor agent</strong> coordinates the workflow and handles exceptions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LlVFphQyuE0hFMvGeNs9xA.gif" /><figcaption>A supervisor coordinates specialized agents and handles exceptions, like a total that doesn’t match.</figcaption></figure><p>Splitting responsibilities makes each agent easier to prompt, test and replace. But every extra agent adds handoffs, latency and cost, plus new ways to fail: agents misreading each other’s outputs, conflicting decisions, and bugs that only appear in the interaction. Debugging one agent is hard. Debugging four that talk to each other is much harder.</p><p>A good rule of thumb: start with one agent and good tools. Split only when a responsibility clearly needs its own context, tools or permissions.</p><h3>Autonomy is not the same as learning</h3><p>“Autonomous” gets used loosely, so it helps to treat it as a scale rather than a yes-or-no property:</p><ul><li><strong>Assisted:</strong> the agent proposes actions, and a human approves or executes them.</li><li><strong>Supervised:</strong> the agent executes permitted actions on its own, while humans monitor and step in when needed.</li><li><strong>Highly autonomous:</strong> the agent plans, executes, evaluates and adapts with minimal human involvement, inside defined constraints.</li></ul><p>These levels are a simplification, not a standard, but they make the design conversation much clearer.</p><p>People often assume an autonomous agent is one that learns. It isn’t. An agent can act entirely on its own with a fixed model, fixed tools and fixed rules. And an agent that does learn from feedback might still need human approval for every payment it makes.</p><p><strong>Autonomy is about acting independently. Learning is about changing behavior based on experience.</strong> When you design an agent, you decide each one separately.</p><h3>Self-improving agents need a process, not a prompt</h3><p>An agent that gets better with experience is an appealing idea. In practice, “learning” often gets reduced to one of two shortcuts: storing past outputs, or asking the model to reflect on its mistakes. Neither reliably improves anything.</p><p>Real improvement needs a loop of its own:</p><ol><li>Collect outcomes and feedback from real runs.</li><li>Find a recurring failure.</li><li>Diagnose its cause: the model, a tool, the workflow, or missing information.</li><li>Change the right component: memory, retrieval, a prompt, a rule, or occasionally the model itself through fine-tuning.</li><li>Evaluate the new version against a fixed test set.</li><li>Deploy it only if it beats the old one, and keep the old one for rollback.</li></ol><p>For business-critical systems, an agent that rewrites its own behavior without evaluation and versioning is a liability. The goal isn’t continuous learning. It’s improvement you can measure and control.</p><h3>Reliability is the real engineering work</h3><p>Getting an agent to work in a demo is quick. Getting it to work on the hundredth messy, real-world input is the real work.</p><p>Real inputs are incomplete. APIs return unexpected formats. Instructions are ambiguous. The model sometimes reasons its way to a confident wrong answer. So reliability has to be designed in from the start:</p><ul><li><strong>Validation:</strong> check every output against rules and schemas.</li><li><strong>Observability:</strong> log every step, tool call, intermediate result and error, so you can trace why the agent did what it did.</li><li><strong>Guardrails:</strong> limit which actions the agent can take at all.</li><li><strong>Human-in-the-loop:</strong> require approval for anything sensitive or irreversible.</li><li><strong>Evaluation:</strong> test against representative scenarios before every release.</li><li><strong>Recovery:</strong> retry, re-plan, or escalate to a human when something fails.</li></ul><p>In financial operations, a sensible boundary is simple: let the agent extract and validate invoice data on its own, but require a human to approve any payment. Automation handles the volume, and people stay accountable for the decisions that matter.</p><h3>Agents are an engineering problem</h3><p>An agent is not a smarter LLM. It’s a system: a model wrapped in planning, tools, memory, evaluation and limits. How well it performs depends as much on that system as on the model inside it.</p><p>So the question I care about isn’t “How many tasks can an agent do?” It’s <strong>“How reliably and safely can it reach its goal?”</strong> That’s where the interesting engineering starts.</p><p><em>What do you think? Does an agent need to learn from its own experience to count as truly autonomous, or is independent, goal-directed execution enough? I’d love to hear where you draw the line.</em></p><h3>References</h3><ol><li>Yao, S. et al. (2022). <a href="https://arxiv.org/abs/2210.03629">ReAct: Synergizing Reasoning and Acting in Language Models</a>. ICLR 2023.</li><li>Lewis, P. et al. (2020). <a href="https://arxiv.org/abs/2005.11401">Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks</a>. NeurIPS 2020.</li><li>Weng, L. (2023). <a href="https://lilianweng.github.io/posts/2023-06-23-agent/">LLM Powered Autonomous Agents</a>. Lil’Log.</li><li>Anthropic (2024). <a href="https://www.anthropic.com/research/building-effective-agents">Building Effective Agents</a>.</li><li><a href="https://modelcontextprotocol.io/introduction">Model Context Protocol documentation</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95d992733f02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your LLM Is Lying About Its Confidence — Here’s How I Fixed It]]></title>
            <link>https://medium.com/@saoussenmannai/your-llm-is-lying-about-its-confidence-heres-how-i-fixed-it-f7fb67b25f53?source=rss-4053b29bfedd------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7fb67b25f53</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Saoussen Mannai]]></dc:creator>
            <pubDate>Thu, 11 Jun 2026 17:21:38 GMT</pubDate>
            <atom:updated>2026-06-11T17:40:32.890Z</atom:updated>
            <content:encoded><![CDATA[<h3>Your LLM Is Lying About Its Confidence — Here’s How I Fixed It</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*zci6qDk4u-0ZUrbjzXtqXw.png" /></figure><p>I spent three weeks trusting a number that meant nothing.</p><p>My final year project is an AI agent that processes supplier invoices automatically — reads the PDF, figures out which accounting account it belongs to, writes the journal entry, done. No human in the loop. That was the idea anyway.</p><p>Every time it classified an invoice, it attached a confidence score. 0.91. 0.87. 0.93. Looked reasonable. I built my automation logic around those numbers — above 0.85, process automatically; below that, kick it to human review. Made sense at the time.</p><p>Then around week three I had this paranoid moment. I thought: wait, have I actually checked if this number means anything? Not “does the feature work” — I knew it worked. But does 0.90 actually mean the agent is right 90% of the time?</p><p>So I did the boring manual check. Took 200 invoices where the model had said around 90% confidence and went through them one by one against ground truth.</p><p>Correct on 150.</p><p>That’s 75%. Not 90.</p><p>I laughed when I saw it. The nervous kind. My automation threshold was 0.85. If 0.90 only means 75% real accuracy, then 0.85 is worse than that, and I’d been confidently automating wrong decisions for weeks without knowing it.</p><p>So why does this happen?</p><p>Took me a while to find a clean explanation. The root cause is that cross-entropy loss — the standard training objective — optimizes for getting the right answer, not for producing accurate probability estimates. Calibration is never directly rewarded. On top of that, RLHF may amplify the problem by reinforcing confident-sounding outputs, since human raters tend to prefer definitive answers over hedged ones. The result is a model that was never explicitly taught to match its stated confidence to its actual accuracy rate.</p><p>There’s a 2017 paper by Guo et al. that measured this directly. When a neural network says 95% confident, real-world accuracy in that bucket tends to land somewhere in the low-to-mid 80s. The gap gets worse at the high end, which is exactly the range where you’re making your most automated decisions.</p><p>For a lot of tasks, fine, whatever. But I was writing to accounting records. Wrong account code → wrong journal entry → wrong books. And these mistakes don’t surface immediately. They sit there quietly until someone runs an audit and has to reconstruct six months of transactions.</p><p>I couldn’t just leave a 15% gap and hope.</p><p>My setup uses two classifiers for each invoice.</p><p>First, a rules engine — deterministic keyword matching. “Orange Tunisie” in the supplier name plus “monthly subscription” in the description → almost certainly telecom, account 626. Fast, transparent, no LLM involved.</p><p>Second, Llama-3.3–70b through Groq. It reads the full invoice and returns a classification and its own confidence score.</p><p>Both had confidence problems, but different ones.</p><p>The LLM was doing the overconfidence thing I described. The rules engine had the opposite issue — it returned flat scores. Match one keyword? 0.85. Match eight? Also 0.85. Match one vague keyword out of twenty? Still 0.85. The score had no relationship to how much evidence it had actually accumulated. Strong match, weak match — didn’t matter, same number.</p><p>Neither was usable as-is.</p><p>Fixing the LLM score.</p><p>I borrowed the intuition from calibration methods such as Platt scaling and applied a lightweight calibration layer tuned on my invoice dataset. The math didn’t feel intuitive to me at first but the idea is simple: it’s a linear transformation that compresses raw scores toward 0.5. When the model says 0.95, it gets pulled down. When it says 0.60, barely moves. You’re essentially telling it: I know you think you’re very sure, but statistically you’re not this sure.</p><pre>LLM_PLATT_A = 0.78<br>LLM_PLATT_B = 0.11<br><br>def calibrate_llm_confidence(llm_raw: float) -&gt; float:<br>    compressed = LLM_PLATT_A * (llm_raw - 0.5) + 0.5 + LLM_PLATT_B<br>    return round(min(0.97, max(0.10, compressed)), 3)</pre><p>A=0.78 is the compression factor — below 1, so scores far from center get pulled inward. B=0.11 nudges the midpoint up slightly. I tuned these on my 200-invoice dataset, comparing confidence buckets to actual accuracy until they tracked. Different model, different numbers — you need to measure first.</p><p>Fixing the rules engine.</p><p>Matching 1 keyword out of 15 should feel different from matching 9 out of 10. So I replaced the flat score with something coverage-weighted.</p><p>I also noticed account codes aren’t equally informative. Account 626 (telecom) is specific — confident mapping there means something. Account 601 (generic purchases) is basically “nothing else fit.” Those shouldn’t produce the same confidence.</p><pre>def calibrate_rules_confidence(<br>    account_code: str,<br>    matched_keywords: list[str],<br>    checked_keywords: list[str],<br>    supplier: str,<br>) -&gt; float:<br>    base = ACCOUNT_SPECIFICITY.get(account_code, 0.60)<br>    if checked_keywords:<br>        coverage = len(matched_keywords) / len(checked_keywords)<br>        coverage_adjusted = 0.10 + (base - 0.10) * math.sqrt(coverage)<br>        return round(min(0.97, coverage_adjusted), 3)<br>    return base</pre><p>Square root on coverage so partial matches aren’t completely crushed — matching 2 out of 20 is weak signal, but it’s still signal.</p><p>The part that actually surprised me: agreement matters more than averaging.</p><p>My first instinct was to take both calibrated scores and average them. That would have been wrong.</p><p>When the rules engine lands on account 626 and the LLM independently also lands on account 626, that agreement is itself evidence. They got there through completely different methods. Neither knew what the other was doing. Two signals converging on the same answer without coordinating — that’s meaningful.</p><p>But when they disagree — rules says 626, LLM says 622 — something about that invoice is genuinely ambiguous. Averaging the scores would just spit out a medium number and nobody would know there was disagreement underneath. The right behavior is to reduce confidence, so a human sees it.</p><pre>AGREEMENT_BONUS = 0.08<br>DISAGREEMENT_PENALTY = 0.12<br><br>blended = 0.40 * calibrated_rules + 0.60 * calibrated_llm<br>if llm_code == rules_code:<br>    final = min(0.97, blended + AGREEMENT_BONUS)<br>else:<br>    final = max(0.10, blended - DISAGREEMENT_PENALTY)</pre><p>LLM gets 60% weight because it’s reading the whole invoice. The rules engine only sees what it was explicitly written to look for.</p><p>Every time I went back and reviewed invoices flagged by disagreement, they were genuinely hard ones. An invoice that said “IT services” from a supplier that could plausibly be either a software vendor or hardware. The kind where even I had to think twice.</p><p>Using past corrections.</p><p>My platform routes low-confidence invoices to human reviewers. They approve or fix. After enough time you have per-supplier history — the agent is reliable on Orange Tunisie, keeps getting confused by SARL Dupont Conseil.</p><p>That history should affect future confidence. Not dramatically, but it should move.</p><pre>HITL_CORRECTION_WEIGHT = 0.04<br><br>total_reviewed = corrections + approvals<br>if total_reviewed &gt; 0:<br>    approval_rate = approvals / total_reviewed<br>    hitl_adjustment = (approval_rate - 0.5) * 2 * HITL_CORRECTION_WEIGHT * min(total_reviewed, 20)<br>    final = min(0.97, max(0.10, final + hitl_adjustment))</pre><p>I cap influence at 20 reviews so it doesn’t snowball. Even 200 clean approvals shouldn’t push a score to 1.0. Something can always change.</p><p>Did it actually help?</p><p>I measured with Expected Calibration Error (ECE). The idea: bucket predictions by confidence level, then check whether accuracy in each bucket actually matches. A bucket of “80% confident” predictions should be right 80% of the time. ECE measures how far off that relationship is.</p><p>Before any calibration: ECE = 0.4579. To put that in plain terms — when the rules engine said 0.90 confidence, it was right about 7.5% of the time in that bucket. The scores weren’t just slightly off. They were almost meaningless.</p><p>After Platt scaling alone: ECE dropped to 0.0215. That’s a 95% reduction. The research community considers anything below 0.05 well-calibrated. The agreement/disagreement logic and HITL history weighting pushed it further still. But honestly what I noticed more day-to-day was the uncertainty bands.</p><p>Each invoice now comes with a range alongside the point estimate. A band of (0.45, 0.85) tells a reviewer: the two signals were far apart, be careful here. A band of (0.79, 0.83) says: both agreed, this is probably fine.</p><p>Reviewers got faster. They stopped treating every escalation the same way and started concentrating effort on the genuinely uncertain ones. Which is what you want.</p><p>Anyway.</p><p>When I started building this I thought calibration was an academic concern. Something you see in ML papers, not something you actually implement. That’s not how it turned out.</p><p>If your agent makes autonomous decisions based on confidence — whether to act, whether to escalate, whether to skip review — then uncalibrated scores silently break the whole thing. Your 0.85 threshold is meaningless if 0.85 doesn’t actually correspond to 85% accuracy.</p><p>Two days to build. Not complicated. But it turned confidence scores from decoration into something I could reason about.</p><p>That ended up mattering a lot more than I expected.</p><p>Building an autonomous multi-agent finance platform for my final year project — LangGraph, FastAPI, Groq. This is one piece of it. Next I want to write about the self-reflection loop in the audit agent, which is a different problem with a similar shape. If you’re working on anything like this, I’d genuinely like to hear about it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7fb67b25f53" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>