<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: firefrog</title>
    <description>The latest articles on DEV Community by firefrog (@minh-leduc).</description>
    <link>https://dev.to/minh-leduc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1249715%2F8f51264e-2307-4580-ac63-683a5dacc10c.png</url>
      <title>DEV Community: firefrog</title>
      <link>https://dev.to/minh-leduc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/minh-leduc"/>
    <language>en</language>
    <item>
      <title>Jev's Boring Use Cases Are the Ones That Actually Work</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Sun, 27 Sep 2026 07:31:04 +0000</pubDate>
      <link>https://dev.to/minh-leduc/jevs-boring-use-cases-are-the-ones-that-actually-work-538o</link>
      <guid>https://dev.to/minh-leduc/jevs-boring-use-cases-are-the-ones-that-actually-work-538o</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcjhwxch8p96a5ex1x35d.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcjhwxch8p96a5ex1x35d.webp" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 TL;DR &amp;amp; Key Takeaways:&lt;/p&gt;

&lt;p&gt;TL;DR: Jev is a lightweight model that runs far faster and cheaper than larger LLMs, delivering competitive accuracy for tasks such as reranking, judging, and real‑time routing, but it still lags on generation, multi‑step reasoning, and high‑stakes decisions. It is most valuable when paired with an LLM, acting as a fast, cost‑effective pre‑filter or safety check.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Speed &amp;amp; cost&lt;/strong&gt; – 777 judgments in under 0.7 s (~¼ ¢), 0.35 s per passage vs Fable’s 8.83 s, roughly 580× cheaper.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Accuracy trade‑off&lt;/strong&gt; – BM25+Jev raises top‑1 accuracy from 5 % to 18 % and top‑10 from 38 % to 62 %; catches 6/7 planted defects versus Fable’s 7/7.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Real‑time use cases&lt;/strong&gt; – agent routing 145–271 ms, model routing ~1 s vs 4–14 s for an LLM, browser automation ~7.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Every's Dan Shipper ran Jev against Fable 5.1 on the same writing-defect checks: Jev took 0.35 seconds per passage against Fable's 8.83 (about 580x cheaper), catching six of seven planted defects to Fable's seven. That trade-off — much faster and cheaper, slightly less accurate on judgment calls needing real reasoning — holds across every use case below, and every number traces to someone outside TypeSafe.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Reranking: 5% to 18% Top-1 Accuracy With One Call Per Candidate
&lt;/h2&gt;

&lt;p&gt;Web search returns ten results; usually two or three are actually relevant. TypeSafe's own &lt;a href="https://docs.typesafe.ai/cookbooks/rerank_typesafe" rel="noopener noreferrer"&gt;reranking cookbook&lt;/a&gt; runs a cheap BM25 keyword shortlist first, then one &lt;code&gt;Noul&lt;/code&gt; question per query-candidate pair to score relevance:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Before (BM25 alone)&lt;/th&gt;
&lt;th&gt;After (BM25 + Jev rerank)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Top-1 accuracy&lt;/td&gt;
&lt;td&gt;5%&lt;/td&gt;
&lt;td&gt;18%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Top-10 accuracy&lt;/td&gt;
&lt;td&gt;38%&lt;/td&gt;
&lt;td&gt;62%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost for 1,200 scoring calls&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;td&gt;$0.0645&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I'm citing this as a TypeSafe number, not an independent one — it's their cookbook, on their benchmark. But the mechanism is simple enough to verify against your own retrieval set. The same shape works on live web search: any search API returning page content can feed the shortlist-then-score pattern, Jev scoring instead of an LLM reading all ten pages end to end — the same latency-and-noise problem I dealt with building &lt;a href="https://ai.plainenglish.io/top-k-at-scale-a-real-time-ranking-system-walkthrough-5708fd20f6f2" rel="noopener noreferrer"&gt;a real-time Top-K ranking system&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Judging: 777 Judgments in Under 0.7 Seconds
&lt;/h2&gt;

&lt;p&gt;Every's head of evals, Mike Taylor, ran 37 documents through 21 questions each (777 total judgments) in under 0.7 seconds, for about a quarter of a cent. That's not a claim about accuracy — it's a claim about what becomes possible once judging is nearly free. A check too expensive to run on every document becomes a check you run on every document, every time.&lt;/p&gt;

&lt;p&gt;Dan Shipper's follow-up test, described above, is the more careful one: the same four writing-defect checks, twelve passages each. Jev at 0.35 seconds and roughly 1/580th the cost, catching six of seven planted defects; Fable caught all seven, slower and more expensively. Neither number makes the other wrong — they're different points on the same speed-cost-accuracy trade-off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-Time Decisions: Latency as the Product
&lt;/h2&gt;

&lt;p&gt;A few independently reported numbers, all outside TypeSafe's own benchmarking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Agent routing&lt;/strong&gt; (blackbarata, &lt;a href="https://www.reddit.com/r/LLMDevs/comments/1wihigc/tried_typesafes_new_decisiononly_model_jev_as_an" rel="noopener noreferrer"&gt;r/LLMDevs&lt;/a&gt;): 145–271ms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Model routing&lt;/strong&gt; (u/TigerOk4538, &lt;a href="https://www.reddit.com/r/AI_Agents/comments/1wl82fr/tried_typesafe_ais_jev_vs_a_regular_llm_for_model/" rel="noopener noreferrer"&gt;r/AI_Agents&lt;/a&gt;): ~1s for Jev vs. 4–14s for an LLM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Browser automation&lt;/strong&gt; (&lt;a href="https://github.com/browser-use/jev-ultrafast" rel="noopener noreferrer"&gt;browser-use/jev-ultrafast&lt;/a&gt;): a Google Flights demo finished in ~7.1s end to end.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bulk analysis&lt;/strong&gt; (Matthew Berman, &lt;a href="https://x.com/TheMattBerman/status/2100654891756589230" rel="noopener noreferrer"&gt;X&lt;/a&gt;): 724 ads across 37 brands in ~40s for ~$0.09.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these are controlled benchmarks — single developers reporting single runs. What they share: decisions cheap and fast enough for a request path or UI loop, not just an offline batch job, the same economics I've tracked on the LLM side in &lt;a href="https://medium.com/@minhle_0210/five-ways-to-invalidate-your-prompt-cache-94fd845ec546" rel="noopener noreferrer"&gt;five ways to invalidate your prompt cache&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where an LLM Still Wins
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Anything that needs generated text, code, or an explanation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multi-hop reasoning and tasks with real indirection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Arithmetic, counting, and date math.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Low-volume, high-stakes single decisions, where one wrong call costs more than speed saves.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Share your thoughts in the comments — I’d love to hear how this technology is impacting your industry.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;👉 Be sure to press the like button and follow me. It would be a great motivation for me.&lt;/p&gt;

&lt;p&gt;👉 Follow me: &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; | &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Pattern
&lt;/h2&gt;

&lt;p&gt;Nobody serious is using Jev &lt;em&gt;instead of&lt;/em&gt; an LLM. They're putting it &lt;em&gt;next to&lt;/em&gt; one: reranking what the LLM reads, judging what it produced, routing before it gets involved, or holding a destructive action an agent was about to take. That's a narrower story than "a new frontier model," and a more useful one to build against.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/jev-s-boring-use-cases-are-the-ones-that-actually-work-z8lqo?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>jev</category>
      <category>typesafeai</category>
    </item>
    <item>
      <title>I Reproduced RLCD to Find Out What Its "Calibrated RL" Actually Does</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Sat, 26 Sep 2026 15:05:04 +0000</pubDate>
      <link>https://dev.to/minh-leduc/i-reproduced-rlcd-to-find-out-what-its-calibrated-rl-actually-does-4jl3</link>
      <guid>https://dev.to/minh-leduc/i-reproduced-rlcd-to-find-out-what-its-calibrated-rl-actually-does-4jl3</guid>
      <description>&lt;p&gt;TypeSafe's Jev returns calibrated probabilities over a closed set of options and credits "Reinforcement Learning for Calibrated Decisions" for it. No paper, no reward function, no dataset, no calibration figure. Laya is the only open reproduction of the same interface, so I reproduced it, then took its training loop apart.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqob34r1q785kjlnii37w.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqob34r1q785kjlnii37w.webp" width="564" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Atomic answer:&lt;/strong&gt; Laya's RLCD RL term is an evolution-strategies estimate of the gradient of a &lt;em&gt;noise-smoothed&lt;/em&gt; proper scoring rule. As the noise vanishes it equals the cross-entropy gradient the model already computes. At real noise levels it makes inference over-confident, and across 30 runs it never beat plain cross-entropy on any accuracy or proper-score number. The only lever that raised accuracy was the input token budget.&lt;/p&gt;

&lt;p&gt;This is the short introduction to the paper. The full report, code, and result files are linked at the bottom.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 TL;DR &amp;amp; Key Takeaways:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Reproducing Laya’s RLCD shows that its “RL” term is just a noise‑smoothed estimate of the cross‑entropy gradient, which makes inference over‑confident, and that any accuracy gains come from increasing the option‑token budget rather than from the RL loss itself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key points&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The RL gradient converges to the cross‑entropy gradient as noise vanishes, so it adds no new information beyond CE.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logit‑noise smoothing causes the trained model to output sharper predictions than the target distribution, leading to over‑confidence at inference time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Across multiple ablations, the only factor that improves proper‑score metrics is the input token budget; the RL loss and its hyperparameters have negligible impact.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What the paper is about
&lt;/h2&gt;

&lt;p&gt;Two models. &lt;strong&gt;Jev&lt;/strong&gt;, from TypeSafe, is the closed model: unstructured state in, typed probabilistic decisions out - a &lt;code&gt;choice&lt;/code&gt; among named options, an ordinal &lt;code&gt;score&lt;/code&gt;, or a binary &lt;code&gt;noul&lt;/code&gt;. It is marketed on calibration: a 0.8 answer should be right about 80% of the time. &lt;strong&gt;Laya&lt;/strong&gt; is the open reproduction: same interface, published code, checkpoints, and a benchmark (&lt;code&gt;LocalLLaMA/typed-decisions&lt;/code&gt;, 400 cases, 2,000 decisions).&lt;/p&gt;

&lt;p&gt;Laya's loop adds noise to the logits, scores the noisy distributions with a proper scoring rule, and applies a REINFORCE-style update next to a soft cross-entropy term. That is the "RL" in RLCD. I reproduced it, verified it tensor-for-tensor against the released weights, and then asked one question: what does that RL term actually contribute?&lt;/p&gt;

&lt;h2&gt;
  
  
  Three things the paper shows
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. The RL term is a noisy estimate of the cross-entropy gradient.&lt;/strong&gt; Write &lt;code&gt;J_σ(z) = E_ε[R(softmax(z+ε), t)]&lt;/code&gt;. The score-function identity plus Stein's lemma turns the RL gradient into the CE gradient averaged over logit noise. For the log score, as &lt;code&gt;σ → 0&lt;/code&gt; it converges to &lt;code&gt;t − softmax(z)&lt;/code&gt; - which the CE term next to it already gives exactly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The smoothing makes inference over-confident, provably.&lt;/strong&gt; The smoothed optimum satisfies &lt;code&gt;E_ε[softmax(z*+ε)] = t&lt;/code&gt;, so the noise-averaged prediction matches the teacher. Inference runs at &lt;code&gt;ε=0&lt;/code&gt; and reports the noise-free &lt;code&gt;softmax(z*)&lt;/code&gt;, which averaging has flattened, so it is sharper than the target. I verified it on trained models: at &lt;code&gt;σ=2&lt;/code&gt;, the noise-averaged prediction lands within &lt;code&gt;−0.006&lt;/code&gt; of the target while the noise-free one is over-sharp by &lt;code&gt;+0.108&lt;/code&gt;. The fitted temperature rises monotonically from &lt;code&gt;1.14&lt;/code&gt; to &lt;code&gt;2.42&lt;/code&gt; as the noise scale goes &lt;code&gt;0.25 → 4&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The loss is not the lever; the input budget is.&lt;/strong&gt; Across CE-only, RL+CE, RL-only, a &lt;code&gt;σ&lt;/code&gt; sweep, a reward-weight sweep and a reward-composition sweep, CE-only is at least as good on every proper score. The only change that raised accuracy was matching the checkpoint's documented 1024-token context and 256-token option budget.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;model&lt;/th&gt;
&lt;th&gt;accuracy&lt;/th&gt;
&lt;th&gt;Brier&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CE-only (512/192)&lt;/td&gt;
&lt;td&gt;0.782&lt;/td&gt;
&lt;td&gt;0.052&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RL+CE (Laya recipe)&lt;/td&gt;
&lt;td&gt;0.773&lt;/td&gt;
&lt;td&gt;0.054&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CE-only, 1024/256&lt;/td&gt;
&lt;td&gt;0.789&lt;/td&gt;
&lt;td&gt;0.0495&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Laya typed-decisions (reference)&lt;/td&gt;
&lt;td&gt;0.766&lt;/td&gt;
&lt;td&gt;0.062&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  The result I did not expect
&lt;/h2&gt;

&lt;p&gt;The budget effect is small on typed decisions. On a high-cardinality task it is not. I recast four standard classification sets into typed &lt;code&gt;choice&lt;/code&gt; questions and scored base Laya and my model zero-shot at two option-token budgets:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;task&lt;/th&gt;
&lt;th&gt;options&lt;/th&gt;
&lt;th&gt;Laya 256&lt;/th&gt;
&lt;th&gt;Laya 512&lt;/th&gt;
&lt;th&gt;Sev 256&lt;/th&gt;
&lt;th&gt;Sev 512&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;AG News&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;94.5&lt;/td&gt;
&lt;td&gt;94.5&lt;/td&gt;
&lt;td&gt;94.3&lt;/td&gt;
&lt;td&gt;94.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Emotion&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;59.8&lt;/td&gt;
&lt;td&gt;59.8&lt;/td&gt;
&lt;td&gt;60.2&lt;/td&gt;
&lt;td&gt;60.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SST-5&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;34.3&lt;/td&gt;
&lt;td&gt;34.3&lt;/td&gt;
&lt;td&gt;42.9&lt;/td&gt;
&lt;td&gt;42.9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Banking77&lt;/td&gt;
&lt;td&gt;77&lt;/td&gt;
&lt;td&gt;15.8&lt;/td&gt;
&lt;td&gt;31.2&lt;/td&gt;
&lt;td&gt;15.8&lt;/td&gt;
&lt;td&gt;32.0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;AG News and Emotion reproduce Laya's own published numbers (95.0 and 59.5). The budget does nothing when every option already fits. At 77 options it roughly doubles accuracy, for both models. That is the option-token starvation Laya's card warns about, and it dwarfs every loss knob I tried.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you might care
&lt;/h2&gt;

&lt;p&gt;If you build typed-decision models in production, three things generalise past this benchmark:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cross-entropy against good target distributions is already a proper-score optimum. You do not need RL for it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logit-noise smoothing is not a free regulariser; it has a direction, and the direction is over-confidence. Fitting a temperature afterwards is undoing the training, not cleaning up after it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check your option-token budget before you touch the loss. It was the only thing that moved a number.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Read it, run it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Paper (IEEE format, PDF + LaTeX):&lt;/strong&gt; &lt;a href="https://github.com/LakoreAI/sev" rel="noopener noreferrer"&gt;https://github.com/LakoreAI/sev&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code, configs, every per-run result file:&lt;/strong&gt; same repo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best checkpoint (weights + fitted temperatures):&lt;/strong&gt; &lt;a href="https://huggingface.co/LakoreAI/laya-typed-decisions-ce-1024" rel="noopener noreferrer"&gt;https://huggingface.co/LakoreAI/laya-typed-decisions-ce-1024&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;All ablation checkpoints and metrics:&lt;/strong&gt; &lt;a href="https://huggingface.co/minhleduc/rlcd-e2-checkpoints" rel="noopener noreferrer"&gt;https://huggingface.co/minhleduc/rlcd-e2-checkpoints&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This builds on the framing I wrote earlier in &lt;a href="https://medium.com/@minhle_0210/jev-explained-the-ai-that-refuses-to-write-a-word-b1788b932ae0" rel="noopener noreferrer"&gt;Jev, Explained: The AI That Refuses to Write a Word.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have fitted a temperature on your own classifier and it came out above 1, I would like to know whether the cause was the loss, the data, or the input budget.&lt;/p&gt;

&lt;p&gt;Follow me: &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;em&gt;|&lt;/em&gt; &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;GitHub&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/i-reproduced-rlcd-to-find-out-what-its-calibrated-rl-actually-does-jrv0k?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>I Took Laya's "Calibrated RL" Apart. It's Cross-Entropy With Extra Steps.</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Sat, 26 Sep 2026 14:39:14 +0000</pubDate>
      <link>https://dev.to/minh-leduc/i-took-layas-calibrated-rl-apart-its-cross-entropy-with-extra-steps-28kh</link>
      <guid>https://dev.to/minh-leduc/i-took-layas-calibrated-rl-apart-its-cross-entropy-with-extra-steps-28kh</guid>
      <description>&lt;p&gt;Laya's README reports a raw ECE of 0.466 on the typed-decisions benchmark before temperature scaling. The method it's named for - Reinforcement Learning for Calibrated Decisions - is supposed to be what makes those probabilities mean something. So I went looking for the RL term's contribution.&lt;/p&gt;

&lt;p&gt;I found a suspect with a very solid alibi: it was doing nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Atomic answer:&lt;/strong&gt; Laya's RL term is an evolution-strategies estimate of the gradient of a &lt;em&gt;noise-smoothed&lt;/em&gt; proper score. As the noise scale goes to zero it converges to the cross-entropy gradient the model already computes. At practical noise levels it makes the model over-sharp at inference, and across 30 training runs it never improved a single accuracy number over plain cross-entropy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Laya's RL reward is a score-function / evolution-strategies estimator of &lt;code&gt;∇ E_ε[R(softmax(z+ε))]&lt;/code&gt;. For the log score, that gradient &lt;code&gt;→ t − softmax(z)&lt;/code&gt; as &lt;code&gt;σ → 0&lt;/code&gt; -which is exactly the CE gradient.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The noise-smoothed objective's optimum satisfies &lt;code&gt;E_ε[softmax(z*+ε)] = t&lt;/code&gt;. Inference reports the &lt;em&gt;noise-free&lt;/em&gt; &lt;code&gt;softmax(z*)&lt;/code&gt;, which is provably sharper than the target (I prove it for binary questions).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the real benchmark, fitted temperature rises monotonically with the training noise scale: &lt;code&gt;1.14 → 2.42&lt;/code&gt; as &lt;code&gt;σ&lt;/code&gt; goes &lt;code&gt;0.25 → 4&lt;/code&gt;. Accuracy does not move.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Across CE-only, RL+CE, RL-only, a σ sweep, a reward-weight sweep, and a reward-composition sweep, &lt;strong&gt;CE-only is at least as good on every metric I track.&lt;/strong&gt; The only thing that raised accuracy was doubling the input token budget.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the short version. The deep version - the estimator derivation, the proof, and the per-run tables - is in the companion post: &lt;a href="https://zyvop.com/inside-rlcd-the-estimator-the-proof-and-the-30-runs-that-changed-my-mind-0qzv9" rel="noopener noreferrer"&gt;Inside RLCD: The Estimator, the Proof, and the 30 Runs That Changed My Mind.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  First, what Jev and Laya actually are
&lt;/h2&gt;

&lt;p&gt;TypeSafe's Jev is a "System One" model: you hand it unstructured state, it returns a probability distribution over a closed, typed set of options - a &lt;code&gt;choice&lt;/code&gt; among named options, an ordinal &lt;code&gt;score&lt;/code&gt;, or a binary &lt;code&gt;noul&lt;/code&gt; (yes/no) probability. No text generation. The headline claim is calibration: an answer given with 0.8 confidence should be right about 80% of the time.&lt;/p&gt;

&lt;p&gt;The method credited for that, RLCD, has no published paper, no reward function, no dataset, and no calibration figure. That's the whole reason this project exists - I wrote about Jev from the outside here: &lt;a href="https://medium.com/@minhle_0210/jev-explained-the-ai-that-refuses-to-write-a-word-b1788b932ae0" rel="noopener noreferrer"&gt;Jev, Explained: The AI That Refuses to Write a Word&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Laya is the only open reproduction of the same interface. It publishes code, checkpoints, and an evaluation on &lt;code&gt;LocalLLaMA/typed-decisions&lt;/code&gt;: 400 test cases, 2,000 decisions, four workflows. Its fine-tuned checkpoint reports 0.766 accuracy, Brier 0.062, ECE 0.213. Against Jev's published 0.727. That's the target I reproduced and then took apart.&lt;/p&gt;

&lt;h2&gt;
  
  
  The method, in one paragraph
&lt;/h2&gt;

&lt;p&gt;Laya encodes each question as its own row - &lt;code&gt;[CLS] &amp;lt;type&amp;gt; question: &amp;lt;instr&amp;gt; [SEP] [MASK] opt0 [MASK] opt1 ... [SEP] &amp;lt;state&amp;gt; [SEP]&lt;/code&gt; - runs a ModernBERT-large encoder, a small transformer head, and reads one logit out of each option's &lt;code&gt;[MASK]&lt;/code&gt; position. Training adds noise to the logits, scores the noisy distributions with a proper scoring rule (log score + spherical + RPS), and applies a REINFORCE-style update next to a soft cross-entropy term on the teacher's probability distribution.&lt;/p&gt;

&lt;p&gt;Here's the full training step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;z&lt;/span&gt;  &lt;span class="err"&gt;←&lt;/span&gt; &lt;span class="nf"&gt;model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                       &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;one&lt;/span&gt; &lt;span class="nx"&gt;logit&lt;/span&gt; &lt;span class="nx"&gt;per&lt;/span&gt; &lt;span class="nx"&gt;option&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;g&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="nx"&gt;G&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;                       &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;G&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="nx"&gt;noise&lt;/span&gt; &lt;span class="nx"&gt;samples&lt;/span&gt;
    &lt;span class="nx"&gt;ε_g&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;N&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;σ&lt;/span&gt;&lt;span class="err"&gt;²&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;zero&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;mean&lt;/span&gt; &lt;span class="nx"&gt;over&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;
    &lt;span class="nx"&gt;q_g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;softmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;ε_g&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;r_g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;R&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;q_g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;proper&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="nx"&gt;vs&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;teacher&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;
&lt;span class="nx"&gt;adv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="err"&gt;−&lt;/span&gt; &lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nf"&gt;std&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;L_rl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;−&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;adv&lt;/span&gt; &lt;span class="err"&gt;·&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="nc"&gt;N&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;ε&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;σ&lt;/span&gt;&lt;span class="err"&gt;²&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;    &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;estimator&lt;/span&gt;
&lt;span class="nx"&gt;L_ce&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;−&lt;/span&gt;&lt;span class="nx"&gt;Σ&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="err"&gt;·&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt; &lt;span class="nf"&gt;softmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;              &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;soft&lt;/span&gt; &lt;span class="nx"&gt;cross&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;entropy&lt;/span&gt;
&lt;span class="nx"&gt;loss&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;w_rl&lt;/span&gt; &lt;span class="err"&gt;·&lt;/span&gt; &lt;span class="nx"&gt;L_rl&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;w_ce&lt;/span&gt; &lt;span class="err"&gt;·&lt;/span&gt; &lt;span class="nx"&gt;L_ce&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;σ&lt;/code&gt; anneals from 0.4 to 0.1 over four epochs. After training, one temperature per question type is fitted on a held-out slice.&lt;/p&gt;

&lt;h2&gt;
  
  
  The finding: the RL term is a smoothed cross-entropy gradient
&lt;/h2&gt;

&lt;p&gt;Write &lt;code&gt;J_σ(z) = E_ε[R(softmax(z+ε), t)]&lt;/code&gt;. The score-function identity gives&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;∇_z J_σ(z) = (1/σ²) · E[ R(softmax(z+ε), t) · ε ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which Laya estimates with four samples and a group-mean baseline. For the log score, &lt;code&gt;∇R = t − softmax(z)&lt;/code&gt;. So as &lt;code&gt;σ → 0&lt;/code&gt;, the RL estimator's expected value is &lt;code&gt;t − softmax(z)&lt;/code&gt; — the exact negative CE gradient. Laya is paying for a Monte Carlo estimate of a gradient that the CE term next to it computes exactly.&lt;/p&gt;

&lt;p&gt;That alone would be a curiosity. The problem is the noise: it doesn't vanish, it biases the optimum.&lt;/p&gt;

&lt;h2&gt;
  
  
  The over-confidence is real, and it grows with the noise
&lt;/h2&gt;

&lt;p&gt;The smoothed objective's stationary point satisfies &lt;code&gt;E_ε[softmax(z*+ε)] = t&lt;/code&gt;. Averaging a softmax over logit noise flattens it. So the model's &lt;em&gt;noise-averaged&lt;/em&gt; prediction matches the target, while the &lt;em&gt;noise-free&lt;/em&gt; prediction that inference actually reports is sharper than the target. Over-confident by construction.&lt;/p&gt;

&lt;p&gt;I checked this two ways. The toy first: minimise the smoothed log score for &lt;code&gt;t = [0.7, 0.2, 0.1]&lt;/code&gt; and look at both predictions.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;σ&lt;/th&gt;
&lt;th&gt;noise-free softmax(z*)&lt;/th&gt;
&lt;th&gt;noise-averaged E[softmax(z*+ε)]&lt;/th&gt;
&lt;th&gt;target&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0.5&lt;/td&gt;
&lt;td&gt;[0.723, 0.187, 0.090]&lt;/td&gt;
&lt;td&gt;[0.698, 0.202, 0.100]&lt;/td&gt;
&lt;td&gt;[0.7, 0.2, 0.1]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;td&gt;[0.780, 0.154, 0.066]&lt;/td&gt;
&lt;td&gt;[0.696, 0.205, 0.099]&lt;/td&gt;
&lt;td&gt;[0.7, 0.2, 0.1]&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.0&lt;/td&gt;
&lt;td&gt;[0.905, 0.071, 0.024]&lt;/td&gt;
&lt;td&gt;[0.706, 0.196, 0.098]&lt;/td&gt;
&lt;td&gt;[0.7, 0.2, 0.1]&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The averaged column tracks the target. The noise-free column is the one inference ships, and at σ=2 it puts 0.905 on a class the teacher gave 0.70.&lt;/p&gt;

&lt;p&gt;Then the real thing. Train with fixed noise and fit the temperature:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;σ&lt;/th&gt;
&lt;th&gt;fitted T (noul)&lt;/th&gt;
&lt;th&gt;NLL vs targets&lt;/th&gt;
&lt;th&gt;accuracy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0.25&lt;/td&gt;
&lt;td&gt;1.14&lt;/td&gt;
&lt;td&gt;0.866&lt;/td&gt;
&lt;td&gt;0.777&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;0.5&lt;/td&gt;
&lt;td&gt;1.16&lt;/td&gt;
&lt;td&gt;0.871&lt;/td&gt;
&lt;td&gt;0.772&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1.38&lt;/td&gt;
&lt;td&gt;0.890&lt;/td&gt;
&lt;td&gt;0.764&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1.72&lt;/td&gt;
&lt;td&gt;0.928&lt;/td&gt;
&lt;td&gt;0.769&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2.08&lt;/td&gt;
&lt;td&gt;0.956&lt;/td&gt;
&lt;td&gt;0.775&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;2.42&lt;/td&gt;
&lt;td&gt;0.987&lt;/td&gt;
&lt;td&gt;0.774&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Fitted temperature and NLL climb monotonically with σ. Accuracy is flat. The temperature is the model's own tell that its raw outputs are too sharp - and it rises exactly as the theory predicts.&lt;/p&gt;

&lt;h2&gt;
  
  
  30 runs later: the loss doesn't matter, the input budget does
&lt;/h2&gt;

&lt;p&gt;I ran the full ablation. Reproduced Laya: 0.773 accuracy, Brier 0.054. CE-only: 0.782, Brier 0.052. RL-only: 0.769. Then a reward-weight sweep and a reward-composition sweep. Nothing beat CE-only.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;configuration&lt;/th&gt;
&lt;th&gt;accuracy&lt;/th&gt;
&lt;th&gt;Brier&lt;/th&gt;
&lt;th&gt;NLL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CE-only&lt;/td&gt;
&lt;td&gt;0.782&lt;/td&gt;
&lt;td&gt;0.052&lt;/td&gt;
&lt;td&gt;0.861&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RL+CE (Laya)&lt;/td&gt;
&lt;td&gt;0.773&lt;/td&gt;
&lt;td&gt;0.054&lt;/td&gt;
&lt;td&gt;0.866&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RL-only&lt;/td&gt;
&lt;td&gt;0.769&lt;/td&gt;
&lt;td&gt;0.054&lt;/td&gt;
&lt;td&gt;0.866&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CE-only, 1024/256 tokens&lt;/td&gt;
&lt;td&gt;0.789&lt;/td&gt;
&lt;td&gt;0.0495&lt;/td&gt;
&lt;td&gt;0.858&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The only thing that moved accuracy was matching the token budget the checkpoint card documents (1024 context / 256 option tokens), which my port had under-provisioned at 512/192. That's the option-token starvation Laya warns about: many options share a fixed budget, so a large option set loses tokens per option.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this means if you're building typed-decision models
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If your targets come from a data engine you control, cross-entropy on those distributions is already a proper-score optimum. You don't need RL for it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logit-noise smoothing is not a free regulariser. It has a direction, and the direction is over-confidence. If you use it, temperature scaling is undoing your training, not just cleaning up after it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Report the fitted temperature. It's a cheap, honest signal that an upstream stage distorted the distribution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check your option-token budget before blaming the loss. It was the only accuracy lever I found.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to reproduce
&lt;/h2&gt;

&lt;p&gt;Everything is public. The code, configs, and result files are in &lt;a href="https://github.com/LakoreAI/sev" rel="noopener noreferrer"&gt;LakoreAI/sev.&lt;/a&gt; Each run is a single A100/A5000 fine-tune of Laya's own checkpoint.&lt;/p&gt;

&lt;p&gt;If you build decision models for a living, I'd like to hear whether the fitted temperature signal matches what you see in production. It's the cheapest diagnostic in this whole post.&lt;/p&gt;

&lt;p&gt;Follow me: &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; | &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/i-took-laya-s-calibrated-rl-apart-it-s-cross-entropy-with-extra-steps-vtl6r?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>aiagents</category>
      <category>calibration</category>
      <category>jev</category>
    </item>
    <item>
      <title>Inside RLCD: The Estimator, the Proof, and the 30 Runs That Changed My Mind</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Sat, 26 Sep 2026 14:31:40 +0000</pubDate>
      <link>https://dev.to/minh-leduc/inside-rlcd-the-estimator-the-proof-and-the-30-runs-that-changed-my-mind-2p8d</link>
      <guid>https://dev.to/minh-leduc/inside-rlcd-the-estimator-the-proof-and-the-30-runs-that-changed-my-mind-2p8d</guid>
      <description>&lt;p&gt;I went into this expecting the RL to be the interesting part. Laya's whole pitch is that a reinforcement-learning term turns noisy logits into calibrated probabilities, and the closed model it reproduces, Jev, is marketed on exactly that. My plan was to isolate the RL term, measure what it adds, and write it up as a win for reinforcement learning.&lt;/p&gt;

&lt;p&gt;Thirty training runs later, the RL term is the most boring part of the pipeline. Here is the long version, with the math, the proof, and every table I generated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Atomic answer:&lt;/strong&gt; Laya's RL term is an evolution-strategies estimator of the gradient of a noise-smoothed proper scoring rule. As the noise vanishes it equals the cross-entropy gradient the model already has; at non-zero noise it provably makes the noise-free inference distribution over-sharp. Across CE-only, RL+CE, RL-only, a σ sweep to 4, a reward-weight sweep, and a reward-composition sweep, the RL term never improves accuracy, and CE-only is at least as good on every proper score.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The RL gradient is &lt;code&gt;−∇ L_rl = (1/(Gσ²)) Σ a_g ε_g&lt;/code&gt;, a group-baselined Monte Carlo estimate of &lt;code&gt;∇_z J_σ(z)&lt;/code&gt; with &lt;code&gt;J_σ(z) = E_ε[R(softmax(z+ε), t)]&lt;/code&gt;. Stein's lemma turns it into a smoothed version of &lt;code&gt;∇R&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For the log score, &lt;code&gt;∇R = t − softmax(z)&lt;/code&gt;, so the RL term is a noisy estimator of the CE gradient. As &lt;code&gt;σ → 0&lt;/code&gt; they coincide.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For &lt;code&gt;σ &amp;gt; 0&lt;/code&gt; the optimum satisfies &lt;code&gt;E_ε[softmax(z*+ε)] = t&lt;/code&gt;, so the noise-free &lt;code&gt;softmax(z*)&lt;/code&gt; is over-sharp. I prove the binary case with an explicit inequality.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I verified the identity directly on trained models: at &lt;code&gt;σ=2&lt;/code&gt;, the noise-averaged prediction lands on the target (gap −0.006) while noise-free inference is over-sharp (+0.108).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;30 runs: nothing beats CE-only except a larger input token budget.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The estimator, written out
&lt;/h2&gt;

&lt;p&gt;Each question is one sequence. A ModernBERT-large encoder runs over it, a type embedding is added, two pre-norm transformer layers mix the sequence, and an MLP scorer reads one logit &lt;code&gt;z_i&lt;/code&gt; from the hidden state at each option's &lt;code&gt;[MASK]&lt;/code&gt; marker. For a batch of &lt;code&gt;B&lt;/code&gt; rows with &lt;code&gt;K&lt;/code&gt; options, the training objective is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;L = w&lt;span class="p"&gt;_&lt;/span&gt;rl · L&lt;span class="p"&gt;_&lt;/span&gt;rl + w&lt;span class="p"&gt;_&lt;/span&gt;ce · L&lt;span class="p"&gt;_&lt;/span&gt;ce
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;L_ce&lt;/code&gt; is soft cross-entropy against the teacher's target &lt;code&gt;t&lt;/code&gt;, and &lt;code&gt;L_rl&lt;/code&gt; perturbs the logits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;ε&lt;span class="p"&gt;_&lt;/span&gt;g ~ N(0, σ²), projected to zero mean over the valid options
q&lt;span class="p"&gt;_&lt;/span&gt;g = softmax(z.detach() + ε&lt;span class="p"&gt;_&lt;/span&gt;g)
r&lt;span class="p"&gt;_&lt;/span&gt;g = R(q&lt;span class="p"&gt;_&lt;/span&gt;g, t)                       # proper score
a&lt;span class="p"&gt;_&lt;/span&gt;g = (r&lt;span class="p"&gt;_&lt;/span&gt;g − mean&lt;span class="p"&gt;_&lt;/span&gt;g r) / std(a)       # group-baselined advantage
L&lt;span class="p"&gt;_&lt;/span&gt;rl = −mean&lt;span class="p"&gt;_&lt;/span&gt;g a&lt;span class="p"&gt;_&lt;/span&gt;g · log N(z+ε&lt;span class="p"&gt;_&lt;/span&gt;g | z, σ²)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Define &lt;code&gt;J_σ(z) = E_ε[R(softmax(z+ε), t)]&lt;/code&gt;. Since &lt;code&gt;∇_z log N(z+ε | z, σ²) = ε/σ²&lt;/code&gt;, the gradient of &lt;code&gt;L_rl&lt;/code&gt; is a Monte Carlo estimate of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;∇&lt;span class="p"&gt;_&lt;/span&gt;z J&lt;span class="p"&gt;_&lt;/span&gt;σ(z) = (1/σ²) E[ R(softmax(z+ε), t) · ε ]  =  P · E[ ∇&lt;span class="p"&gt;_&lt;/span&gt;u R(softmax(u), t) |&lt;span class="p"&gt;_{&lt;/span&gt;u=z+ε&lt;span class="p"&gt;}&lt;/span&gt; ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second equality is Stein's lemma, and it is the whole story: the RL gradient is the CE gradient averaged over logit noise. For the log score, &lt;code&gt;∇_u R = t − softmax(u)&lt;/code&gt;. So as &lt;code&gt;σ → 0&lt;/code&gt;, the RL term estimates &lt;code&gt;t − softmax(z)&lt;/code&gt; — the negative CE gradient itself. It is a noisy proxy for something the CE term supplies exactly.&lt;/p&gt;

&lt;p&gt;Why does this matter for calibration rather than just for elegance? Because the &lt;em&gt;optimum&lt;/em&gt; of the smoothed objective is not the optimum of the unsmoothed one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the smoothed optimum is over-sharp (and the binary proof)
&lt;/h2&gt;

&lt;p&gt;For the log score, &lt;code&gt;J_σ&lt;/code&gt; is concave (an average of concave log-softmax terms), so its maximisers satisfy the stationarity condition&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;E&lt;span class="p"&gt;_&lt;/span&gt;ε[ softmax(z*&lt;span class="p"&gt;_&lt;/span&gt;σ + ε) ] = t
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The noise-&lt;em&gt;averaged&lt;/em&gt; prediction equals the target. But inference runs at &lt;code&gt;ε = 0&lt;/code&gt; and reports the noise-&lt;em&gt;free&lt;/em&gt; &lt;code&gt;softmax(z*_σ)&lt;/code&gt;. Averaging a softmax over noise flattens it, so the noise-free value must be sharper than the average. That's the over-confidence, and it's a property of the objective, not a training artefact.&lt;/p&gt;

&lt;p&gt;For binary questions (&lt;code&gt;noul&lt;/code&gt;, &lt;code&gt;K=2&lt;/code&gt;) I can make it exact. With projected noise the logit gap &lt;code&gt;d = z_1 − z_2&lt;/code&gt; receives &lt;code&gt;η ~ N(0, 2σ²)&lt;/code&gt;, and stationarity becomes &lt;code&gt;F_σ(d*) = E[s(d* + η)] = t_1&lt;/code&gt; with &lt;code&gt;s&lt;/code&gt; the logistic function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proposition.&lt;/strong&gt; Let &lt;code&gt;K=2&lt;/code&gt;, the log score, and &lt;code&gt;t_1 ∈ (½, 1)&lt;/code&gt;. For every &lt;code&gt;σ &amp;gt; 0&lt;/code&gt; there is a unique maximiser &lt;code&gt;d*_σ&lt;/code&gt;. It satisfies &lt;code&gt;s(d*_σ) &amp;gt; t_1&lt;/code&gt;, and &lt;code&gt;s(d*_σ)&lt;/code&gt; is strictly increasing in &lt;code&gt;σ&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The proof is a pairing argument. Let &lt;code&gt;g = s − ½&lt;/code&gt;. It's odd, increasing, and concave on &lt;code&gt;[0, ∞)&lt;/code&gt;, with &lt;code&gt;g''(x) = s(1−s)(1−2s)&lt;/code&gt; negative for &lt;code&gt;x &amp;gt; 0&lt;/code&gt;. Fix &lt;code&gt;d &amp;gt; 0&lt;/code&gt; and pair &lt;code&gt;±η&lt;/code&gt;. If &lt;code&gt;|η| ≤ d&lt;/code&gt;, concavity gives &lt;code&gt;g(d+η) + g(d−η) ≤ 2g(d)&lt;/code&gt;. If &lt;code&gt;|η| &amp;gt; d&lt;/code&gt;, use oddness to rewrite the pair as &lt;code&gt;g(|η|+d) − g(|η|−d)&lt;/code&gt; — the increment of a concave function over an interval of length &lt;code&gt;2d&lt;/code&gt;, which is at most &lt;code&gt;g(2d) ≤ 2g(d)&lt;/code&gt;. So &lt;code&gt;E[g(d+η)] &amp;lt; g(d)&lt;/code&gt;, hence &lt;code&gt;F_σ(d) &amp;lt; s(d)&lt;/code&gt; for all &lt;code&gt;d &amp;gt; 0&lt;/code&gt;. Since &lt;code&gt;F_σ&lt;/code&gt; is continuous and strictly increasing from &lt;code&gt;½&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt;, it has a unique root &lt;code&gt;d*&lt;/code&gt;, and &lt;code&gt;s(d*) &amp;gt; F_σ(d*) = t_1&lt;/code&gt;. For monotonicity, write &lt;code&gt;η = τZ&lt;/code&gt;; Stein's lemma gives &lt;code&gt;∂_τ E[g(d+τZ)] = τ E[g''(d+τZ)] &amp;lt; 0&lt;/code&gt;, so &lt;code&gt;F_σ&lt;/code&gt; decreases in &lt;code&gt;σ&lt;/code&gt; at fixed &lt;code&gt;d&lt;/code&gt;, and keeping &lt;code&gt;F_σ(d*_σ) = t_1&lt;/code&gt; forces &lt;code&gt;d*_σ&lt;/code&gt; up.&lt;/p&gt;

&lt;p&gt;A second-order expansion adds the size: &lt;code&gt;E[softmax(z+ε)] = softmax(z) + (σ²/2) Σ P_jk ∂_j∂_k softmax(z) + O(σ⁴)&lt;/code&gt;. The bias is &lt;code&gt;O(σ²)&lt;/code&gt; — negligible at Laya's annealed &lt;code&gt;σ ≤ 0.4&lt;/code&gt;, large at &lt;code&gt;σ = 2&lt;/code&gt;. That predicts Laya's recipe is nearly unbiased and gains nothing over CE, which is exactly what the runs show.&lt;/p&gt;

&lt;h2&gt;
  
  
  Direct check: average the noise away and watch it hit the target
&lt;/h2&gt;

&lt;p&gt;The proposition is about the objective's optimum. The trained checkpoints let me check it end to end. For each fixed-σ model I compared, over the full 2,000-decision test set, the noise-free &lt;code&gt;softmax(z*)&lt;/code&gt; with a 128-sample average &lt;code&gt;E_ε[softmax(z*+ε)]&lt;/code&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;σ&lt;/th&gt;
&lt;th&gt;mean max p&lt;/th&gt;
&lt;th&gt;mean max p̄ (avg)&lt;/th&gt;
&lt;th&gt;mean max t&lt;/th&gt;
&lt;th&gt;gap, noise-free&lt;/th&gt;
&lt;th&gt;gap, averaged&lt;/th&gt;
&lt;th&gt;KL, noise-free&lt;/th&gt;
&lt;th&gt;KL, averaged&lt;/th&gt;
&lt;th&gt;rows moved closer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.689&lt;/td&gt;
&lt;td&gt;0.638&lt;/td&gt;
&lt;td&gt;0.659&lt;/td&gt;
&lt;td&gt;+0.085&lt;/td&gt;
&lt;td&gt;+0.033&lt;/td&gt;
&lt;td&gt;0.120&lt;/td&gt;
&lt;td&gt;0.099&lt;/td&gt;
&lt;td&gt;65%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0.711&lt;/td&gt;
&lt;td&gt;0.597&lt;/td&gt;
&lt;td&gt;0.659&lt;/td&gt;
&lt;td&gt;+0.108&lt;/td&gt;
&lt;td&gt;−0.006&lt;/td&gt;
&lt;td&gt;0.166&lt;/td&gt;
&lt;td&gt;0.100&lt;/td&gt;
&lt;td&gt;68%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At &lt;code&gt;σ=2&lt;/code&gt; the noise-averaged prediction lands on the target — the gap is −0.006, essentially zero — while the noise-free prediction that inference reports is over-sharp by +0.108. Averaging moves 68% of rows toward the target. This is the smoothest confirmation of the theory I got, and it took one inference pass plus noise samples.&lt;/p&gt;

&lt;h2&gt;
  
  
  The full σ sweep
&lt;/h2&gt;

&lt;p&gt;I extended the original sweep to &lt;code&gt;σ ∈ {0.25, 0.5, 1, 2, 3, 4}&lt;/code&gt;, three seeds up to &lt;code&gt;σ=2&lt;/code&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;configuration&lt;/th&gt;
&lt;th&gt;n&lt;/th&gt;
&lt;th&gt;sharpness gap&lt;/th&gt;
&lt;th&gt;Brier&lt;/th&gt;
&lt;th&gt;NLL&lt;/th&gt;
&lt;th&gt;T (noul)&lt;/th&gt;
&lt;th&gt;T (choice)&lt;/th&gt;
&lt;th&gt;T (score)&lt;/th&gt;
&lt;th&gt;accuracy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;σ=0.25&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;−0.011&lt;/td&gt;
&lt;td&gt;0.054&lt;/td&gt;
&lt;td&gt;0.866&lt;/td&gt;
&lt;td&gt;1.14&lt;/td&gt;
&lt;td&gt;1.10&lt;/td&gt;
&lt;td&gt;1.07&lt;/td&gt;
&lt;td&gt;0.776&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;σ=0.5&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;−0.002&lt;/td&gt;
&lt;td&gt;0.057&lt;/td&gt;
&lt;td&gt;0.871&lt;/td&gt;
&lt;td&gt;1.16&lt;/td&gt;
&lt;td&gt;1.17&lt;/td&gt;
&lt;td&gt;1.12&lt;/td&gt;
&lt;td&gt;0.772&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;σ=1&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;+0.025&lt;/td&gt;
&lt;td&gt;0.065&lt;/td&gt;
&lt;td&gt;0.890&lt;/td&gt;
&lt;td&gt;1.38&lt;/td&gt;
&lt;td&gt;1.28&lt;/td&gt;
&lt;td&gt;1.29&lt;/td&gt;
&lt;td&gt;0.764&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;σ=2&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;+0.051&lt;/td&gt;
&lt;td&gt;0.072&lt;/td&gt;
&lt;td&gt;0.928&lt;/td&gt;
&lt;td&gt;1.72&lt;/td&gt;
&lt;td&gt;1.59&lt;/td&gt;
&lt;td&gt;1.56&lt;/td&gt;
&lt;td&gt;0.769&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;σ=3&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;+0.060&lt;/td&gt;
&lt;td&gt;0.073&lt;/td&gt;
&lt;td&gt;0.956&lt;/td&gt;
&lt;td&gt;2.08&lt;/td&gt;
&lt;td&gt;1.86&lt;/td&gt;
&lt;td&gt;1.73&lt;/td&gt;
&lt;td&gt;0.775&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;σ=4&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;+0.056&lt;/td&gt;
&lt;td&gt;0.072&lt;/td&gt;
&lt;td&gt;0.987&lt;/td&gt;
&lt;td&gt;2.42&lt;/td&gt;
&lt;td&gt;1.94&lt;/td&gt;
&lt;td&gt;1.91&lt;/td&gt;
&lt;td&gt;0.774&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Fitted temperature and NLL rise monotonically across the whole range. The sharpness gap rises, then saturates as the softmax runs out of room. Accuracy is flat within seed noise — the RL term is not buying accuracy, it is buying sharpness, and only at inference.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reward weight and reward composition
&lt;/h2&gt;

&lt;p&gt;Two more sweeps to make sure I wasn't missing a working configuration.&lt;/p&gt;

&lt;p&gt;At fixed &lt;code&gt;σ=1&lt;/code&gt;, scaling the RL weight while holding CE fixed does what the cancellation argument predicts: accuracy flat, proper scores worse as the RL term grows.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;configuration&lt;/th&gt;
&lt;th&gt;n&lt;/th&gt;
&lt;th&gt;Brier&lt;/th&gt;
&lt;th&gt;NLL&lt;/th&gt;
&lt;th&gt;T (noul)&lt;/th&gt;
&lt;th&gt;accuracy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;w_rl = 0.5&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.061&lt;/td&gt;
&lt;td&gt;0.882&lt;/td&gt;
&lt;td&gt;1.35&lt;/td&gt;
&lt;td&gt;0.770&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;w_rl = 1&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;0.065&lt;/td&gt;
&lt;td&gt;0.890&lt;/td&gt;
&lt;td&gt;1.38&lt;/td&gt;
&lt;td&gt;0.764&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;w_rl = 2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.066&lt;/td&gt;
&lt;td&gt;0.898&lt;/td&gt;
&lt;td&gt;1.49&lt;/td&gt;
&lt;td&gt;0.769&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;And the reward composition — log-only vs log+spherical vs log+RPS, under Laya's schedule:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;reward&lt;/th&gt;
&lt;th&gt;n&lt;/th&gt;
&lt;th&gt;Brier&lt;/th&gt;
&lt;th&gt;NLL&lt;/th&gt;
&lt;th&gt;accuracy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;log only&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.053&lt;/td&gt;
&lt;td&gt;0.864&lt;/td&gt;
&lt;td&gt;0.777&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;log + spherical&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.053&lt;/td&gt;
&lt;td&gt;0.866&lt;/td&gt;
&lt;td&gt;0.774&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;log + RPS&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0.053&lt;/td&gt;
&lt;td&gt;0.865&lt;/td&gt;
&lt;td&gt;0.768&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;full (log + sph + RPS)&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;0.054&lt;/td&gt;
&lt;td&gt;0.866&lt;/td&gt;
&lt;td&gt;0.773&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;No reward term earns its place. The spherical and RPS additions are inside seed noise on accuracy and don't move Brier at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gradient diagnostics: big and misaligned
&lt;/h2&gt;

&lt;p&gt;I logged the cosine and norm ratio between the RL and CE gradients w.r.t. the logits every ten steps. Under Laya's schedule the RL gradient is 8× the CE gradient at &lt;code&gt;σ=0.4&lt;/code&gt; and 87× at &lt;code&gt;σ=0.1&lt;/code&gt;, with cosine around 0.65. In the fixed-σ runs, where σ isn't confounded with training progress, the norm ratio scales as &lt;code&gt;1/σ&lt;/code&gt; and alignment falls from 0.60 to 0.37 as σ grows.&lt;/p&gt;

&lt;p&gt;So the RL term dominates the update before clipping, and points only moderately the same way as CE. It's not a gentle regulariser; it's the loudest signal in the loss, and it's a noisy copy of a signal already present.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consistency probes
&lt;/h2&gt;

&lt;p&gt;A practical question the calibration numbers don't answer: does the model behave the same when the surface form changes? On the &lt;code&gt;σ=2&lt;/code&gt; checkpoint, 500 questions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;perturbation&lt;/th&gt;
&lt;th&gt;violation rate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;reverse the option order&lt;/td&gt;
&lt;td&gt;6.6%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;append "(restated)" to every option&lt;/td&gt;
&lt;td&gt;2.0%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;append an unrelated passage to the state&lt;/td&gt;
&lt;td&gt;13.4%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Option order and renaming are mostly handled. Unrelated context is not — 13% of picks flip when you pad the state, the same fragility TypeSafe documents for Jev. A rough negation probe (negate the instruction, swap true/false) leaves a mean mismatch of 0.53 between the two wordings, which is a lot; but that probe is crude, and I'd treat it as a flag rather than a number.&lt;/p&gt;

&lt;h2&gt;
  
  
  The one thing that moved accuracy
&lt;/h2&gt;

&lt;p&gt;Every loss-side knob plateaued at ~0.78. Then I read the checkpoint card carefully: it documents a 1024-token context and a 256-token option budget, and warns that a large option set starves each option of tokens. My port had been built at 512/192. Matching the documented budget gave the only real gain:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;configuration&lt;/th&gt;
&lt;th&gt;accuracy&lt;/th&gt;
&lt;th&gt;Brier&lt;/th&gt;
&lt;th&gt;NLL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CE-only, 512/192&lt;/td&gt;
&lt;td&gt;0.782 ± 0.004&lt;/td&gt;
&lt;td&gt;0.052&lt;/td&gt;
&lt;td&gt;0.861&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CE-only, 1024/256&lt;/td&gt;
&lt;td&gt;0.789&lt;/td&gt;
&lt;td&gt;0.0495&lt;/td&gt;
&lt;td&gt;0.858&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CE-only, 1024/256, continued from the fine-tuned checkpoint&lt;/td&gt;
&lt;td&gt;0.790&lt;/td&gt;
&lt;td&gt;0.051&lt;/td&gt;
&lt;td&gt;0.859&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Continuing from the already fine-tuned &lt;code&gt;laya-typed-decisions&lt;/code&gt; checkpoint gave the same result, so the gain is the budget, not the starting point. It also means the loss ablation was being run slightly under-provisioned for the option-rich questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd do differently, and what's still open
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Try a CE+Brier composite loss.&lt;/strong&gt; Verdict-2.0, a 151M ModernBERT-base decision model, reports 0.771 accuracy with ECE 0.0144 on this exact benchmark using a cross-entropy plus Brier objective. I didn't test it; it's the most obvious next run.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Report seeds.&lt;/strong&gt; I ran three seeds where I could afford it. Small accuracy gaps move as much as a modest architecture change when you pick a different seed, so I never compare models by single-seed accuracy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stop treating the RL term as the interesting variable.&lt;/strong&gt; The interesting variable was the input budget. I'd start there next time.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to reproduce
&lt;/h2&gt;

&lt;p&gt;All code, configs, and per-run JSON are in &lt;a href="https://github.com/LakoreAI/sev" rel="noopener noreferrer"&gt;LakoreAI/sev&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you've built a typed-decision model and checked your fitted temperature, I want to know what it came out to. Mine was always greater than 1, and I suspect yours is too.&lt;/p&gt;

&lt;p&gt;Follow me: &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; | &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/inside-rlcd-the-estimator-the-proof-and-the-30-runs-that-changed-my-mind-0qzv9?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>jev</category>
      <category>laya</category>
      <category>typesafe</category>
    </item>
    <item>
      <title>Pi‑warden: Using Jev to Block Destructive Commands in 48 Hours</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Sat, 26 Sep 2026 07:15:05 +0000</pubDate>
      <link>https://dev.to/minh-leduc/pi-warden-using-jev-to-block-destructive-commands-in-48-hours-caj</link>
      <guid>https://dev.to/minh-leduc/pi-warden-using-jev-to-block-destructive-commands-in-48-hours-caj</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F49avukqx3lqrbllnwlyw.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F49avukqx3lqrbllnwlyw.webp" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 TL;DR &amp;amp; Key Takeaways:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Jev, a decision‑only AI model released on September 15 2026, was quickly adopted by developers: pi‑warden, built within 48 hours, blocked 42 destructive commands out of 17,000 calls with an 88 % hold‑accuracy. The first week also saw a burst of related projects—safety scanners, connectors, an open‑source interface, and a Vercel AI Gateway integration—highlighting that tightly‑phrased, typed guardrails are the most validated use case for agent tooling.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;pi‑warden&lt;/strong&gt;: a guardrail that queries Jev on irreversibility, off‑task status, mutation, and scope, holding 42 commands in 17,000 calls with 88 % accuracy and also flagging stubs, retry loops, and untested “done” claims.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ecosystem growth&lt;/strong&gt;: safety‑scanning routers, MCP/Ruby/DSPy connectors, an open‑source Jev interface (openjev), and a Vercel AI Gateway integration all launched within days of Jev’s debut.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Best practices&lt;/strong&gt;: phrase questions narrowly and in layers, use Jev to filter rather than decide costly actions, and keep a deterministic or human policy downstream of Jev’s output.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;pi-warden, a coding-agent guardrail built on Jev in the first 48 hours after launch, held a destructive shell command 42 times across 17,000 recorded judgments — about 88% of those holds were later confirmed correct. It's the best-documented example of a pattern repeating across the ecosystem: an upstream step produces state, Jev makes a fast typed judgment, and code acts on it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhp0nckmifm212niq2rs2.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhp0nckmifm212niq2rs2.webp" width="484" height="900"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Jev, TypeSafe AI's decision-only model &lt;a href="//../jev-system-one-model/jev_system_one_model_explained.md"&gt;covered here&lt;/a&gt;, shipped September 15, 2026 with a 1,821-point Hacker News thread attached. A week later there's a small ecosystem of guardrails, routers, and connectors built on it, with real numbers behind several of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  pi-warden: A Second Pair of Eyes for Coding Agents
&lt;/h2&gt;

&lt;p&gt;The problem pi-warden solves: a coding agent about to run &lt;code&gt;db:reset&lt;/code&gt; or &lt;code&gt;git push --force&lt;/code&gt;, where whether that's fine or catastrophic depends entirely on what the agent was actually asked to do, not on the command's text. A regex can't see that distinction. A second call to a frontier model can, but it costs seconds and cents on every single tool call, and a real agent session makes hundreds of them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/DevMortimer/pi-warden" rel="noopener noreferrer"&gt;pi-warden&lt;/a&gt; sends the task, the agent's stated plan, and the pending &lt;code&gt;bash&lt;/code&gt;, &lt;code&gt;write&lt;/code&gt;, or &lt;code&gt;edit&lt;/code&gt; call to Jev as four typed questions: is this irreversible, is it off-task, does it mutate anything, what's the scope. All four come back in about 250 milliseconds. According to the &lt;a href="https://old.reddit.com/r/PiCodingAgent/comments/1wimfhg/piwarden_a_jevpowered_second_pair_of_eyes_for_pi/" rel="noopener noreferrer"&gt;maintainer's write-up on r/PiCodingAgent&lt;/a&gt;, over 17,000 recorded calls it held the agent 42 times, and about 88% of those holds turned out to be right calls.&lt;/p&gt;

&lt;p&gt;pi-warden does more than block destructive commands. It also judges written code against a project's rules file, flags stubs and hedging language in a diff, detects an agent stuck in a retry loop, and catches an agent claiming "done" with no test actually run — every one of those is a yes/no or a typed choice, exactly the shape Jev is built for.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Rest of the Week's Projects
&lt;/h2&gt;

&lt;p&gt;A tool-call safety scanner and model router, posted to &lt;a href="https://old.reddit.com/r/PiCodingAgent/comments/1whsav6/anyone_else_testing_out_typesafe_ais_new_system/" rel="noopener noreferrer"&gt;r/PiCodingAgent&lt;/a&gt; by a user going by peepo_comfy, scores every tool call for safety and is being extended into a router that picks a model based on prompt difficulty and codebase complexity. Their developer-experience note: phrase each question explicitly, and layer several small questions rather than one large compound one.&lt;/p&gt;

&lt;p&gt;A handful of connectors shipped just as fast: &lt;a href="https://github.com/itsmostafa/typesafe-mcp" rel="noopener noreferrer"&gt;typesafe-mcp&lt;/a&gt; (MCP connector, any MCP-compatible agent calls Jev directly), &lt;a href="https://x.com/kieranklaassen/status/2100088928271585527" rel="noopener noreferrer"&gt;ruby_llm-typesafe&lt;/a&gt; (Ruby access), and &lt;a href="https://github.com/typesafeainate/dspy-typesafeify" rel="noopener noreferrer"&gt;dspy-typesafeify&lt;/a&gt; (a DSPy fork routing Signatures to Jev automatically where the shape allows it).&lt;/p&gt;

&lt;p&gt;The most useful project, though, isn't a Jev integration at all. &lt;a href="https://github.com/TheoLeeCJ/openjev" rel="noopener noreferrer"&gt;openjev&lt;/a&gt; is a control group: an open reproduction of the &lt;em&gt;interface&lt;/em&gt;, reading option logits directly off Qwen3.5-4B. On one RTX 3090, 21 questions took 1.02 seconds as direct logit reads versus 5.33 seconds as generated JSON, landing at 0.845 modal agreement against Jev's own published 0.883.&lt;/p&gt;

&lt;p&gt;TypeSafe's ecosystem moved fast too — Vercel added Jev to AI Gateway within 36 hours, exposed through a new &lt;code&gt;evaluate&lt;/code&gt; method in AI SDK 7.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading the Skepticism Alongside the Adoption
&lt;/h2&gt;

&lt;p&gt;The top comment on r/singularity called Jev "the industry rediscovering classification models." On r/LocalLLaMA, commenters pointed at existing zero-shot classifier encoders, &lt;a href="https://huggingface.co/knowledgator/gliformer-large-v1" rel="noopener noreferrer"&gt;gliformer&lt;/a&gt; among them, and asked directly whether Jev is a fine-tuned open model wrapped in a nicer API. None of that skepticism stopped pi-warden's 17,000 calls from being real, or its 88% hold-accuracy from being genuinely useful for anyone deciding whether a similar guardrail is worth building.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Share your thoughts in the comments — I’d love to hear how this technology is impacting your industry.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;👉 Be sure to press the like button and follow me. It would be a great motivation for me.&lt;/p&gt;

&lt;p&gt;👉 Follow me: &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; | &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What This Means If You're Building Agent Tooling
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A typed guardrail in front of destructive actions is the single most validated use case one week in.&lt;/strong&gt; pi-warden's numbers are the best public evidence Jev has produced so far.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Phrase questions narrowly and layer them.&lt;/strong&gt; One big compound question performs worse than several small typed ones.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use it to filter, not to decide alone on anything expensive.&lt;/strong&gt; Every project keeps a human or deterministic policy downstream of Jev's output.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The distribution story moved faster than the research story.&lt;/strong&gt; Vercel's AI Gateway integration landing in 36 hours says more about ease of adoption than any benchmark does.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/pi-warden-using-jev-to-block-destructive-commands-in-48-hours-5lfoy?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>agenticai</category>
      <category>ai</category>
      <category>aiagents</category>
      <category>jev</category>
    </item>
    <item>
      <title>Understanding RLCD: Calibration Techniques for Decision‑Only LLMs</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Fri, 25 Sep 2026 12:30:06 +0000</pubDate>
      <link>https://dev.to/minh-leduc/understanding-rlcd-calibration-techniques-for-decision-only-llms-c8m</link>
      <guid>https://dev.to/minh-leduc/understanding-rlcd-calibration-techniques-for-decision-only-llms-c8m</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpl4ed4gcfx4vqnnp0nk6.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpl4ed4gcfx4vqnnp0nk6.webp" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 TL;DR &amp;amp; Key Takeaways:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
RLCD is a proprietary training method from TypeSafe AI that teaches Jev to produce calibrated probability distributions and confidence scores that reflect real-world correctness, rather than merely human preference or code‑verifiable outputs. While Jev’s dramatic speed gains are largely attributed to a typed‑parallel interface, RLCD’s main contribution is the reliable calibration of its predictions, though the model’s architecture and training data remain undisclosed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;RLCD optimizes for probability‑calibration, giving confidence scores that match actual correctness, unlike RLHF (human preference) or RLVR (verifiable outputs).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A typed‑parallel interface can yield a ~5× speedup over standard JSON generation, but the full 40‑200× speed claim is still unverified.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TypeSafe has not released Jev’s architecture, parameter count, or training data, leaving the novelty and full impact of RLCD open to discussion.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;RLCD ("Reinforcement Learning for Calibrated Decisions") is TypeSafe AI's own coined training method for Jev — eight days old as a public term, not an established academic technique, despite sounding like one. It optimizes for probabilities that match real-world correctness rather than human preference (RLHF) or programmatic verification (RLVR): if Jev says 90% confidence, roughly 90% of those calls should actually be right.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's the concrete comparison:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Optimizes for&lt;/th&gt;
&lt;th&gt;Typical output&lt;/th&gt;
&lt;th&gt;Failure mode&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;RLHF&lt;/td&gt;
&lt;td&gt;Human-preferred responses&lt;/td&gt;
&lt;td&gt;Free text&lt;/td&gt;
&lt;td&gt;Says what raters like, not necessarily what's true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RLVR&lt;/td&gt;
&lt;td&gt;Outputs a program can verify&lt;/td&gt;
&lt;td&gt;Text, often constrained to JSON&lt;/td&gt;
&lt;td&gt;Only works where "correct" is checkable in code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RLCD (TypeSafe's term)&lt;/td&gt;
&lt;td&gt;Probabilities that match real outcomes&lt;/td&gt;
&lt;td&gt;Typed value + confidence score&lt;/td&gt;
&lt;td&gt;Can pick a confidently wrong valid answer&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;"Reinforcement Learning for Calibrated Decisions" reads like a technique you'd find cited in a 2023 alignment paper, sitting next to RLHF and PPO in a related-work section. It isn't. TypeSafe AI coined it for &lt;a href="https://typesafe.ai/blog/introducing-system-one-models-and-jev" rel="noopener noreferrer"&gt;Jev&lt;/a&gt;, the decision-only model it launched September 15, 2026, and the name did its job a little too well. Forbes contributor Lance Eliot &lt;a href="https://www.forbes.com/sites/lanceeliot/2026/09/18/new-reinforcement-learning-for-calibrated-decisions-makes-ai-headlines-but-look-past-the-hype/" rel="noopener noreferrer"&gt;called this out directly&lt;/a&gt;: RLCD is proprietary to TypeSafe, not standardized. It has conceptual cousins — RLCR and RLVR both predate it — but isn't the same as either.&lt;/p&gt;

&lt;h2&gt;
  
  
  What "Calibrated" Actually Buys You
&lt;/h2&gt;

&lt;p&gt;Feed Jev a support message and ask which team should own it, and instead of a single answer, you get a distribution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Technical&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;    &lt;span class="s"&gt;64%&lt;/span&gt;
&lt;span class="na"&gt;Sales&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;        &lt;span class="s"&gt;23%&lt;/span&gt;
&lt;span class="na"&gt;Billing&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;      &lt;span class="s"&gt;13%&lt;/span&gt;
&lt;span class="na"&gt;Cancellation&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;  &lt;span class="s"&gt;0%&lt;/span&gt;
&lt;span class="s"&gt;-----------------&lt;/span&gt;
&lt;span class="na"&gt;Confidence&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;   &lt;span class="s"&gt;53%&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The confidence score is a second, separate signal from the probability distribution. The distribution says &lt;em&gt;what&lt;/em&gt;; the confidence says &lt;em&gt;whether to trust this particular call enough to act on it automatically&lt;/em&gt;. A well-calibrated model that says 53% confidence should genuinely be wrong close to half the time at that band — which lets a workflow route only the high-confidence cases automatically and send the rest to a human. General-purpose LLMs tend to be overconfident and inconsistent when asked for a confidence number, because nothing in RLHF specifically rewards getting the number right. RLCD does, on the narrower task Jev is built for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parallel Sampling Is the Other Half of the Story — and It's Contested
&lt;/h2&gt;

&lt;p&gt;RLCD explains &lt;em&gt;what&lt;/em&gt; Jev is trained to say. It doesn't fully explain why Jev is 40 to 200x faster, and this is a genuine open question rather than something to repeat uncritically.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fezycxcis890gaw3526kp.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fezycxcis890gaw3526kp.webp" width="799" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/TheoLeeCJ/openjev" rel="noopener noreferrer"&gt;openjev&lt;/a&gt;, an open reproduction of Jev's &lt;em&gt;interface&lt;/em&gt; (not the model, built by reading option logits directly off Qwen3.5-4B), found on one RTX 3090 that 21 questions took 1.02 seconds as direct logit reads versus 5.33 seconds as a generated JSON array— roughly a 5x speedup from the typed-parallel interface pattern alone, on a model with &lt;strong&gt;no RLCD training at all&lt;/strong&gt;. On the same 102 test cases aligned with TypeSafe's own published evals, openjev scored 0.845 modal agreement against Jev's 0.883: close, not equal.&lt;/p&gt;

&lt;p&gt;Diogo Almeida's response, posted on X, was that the real bottleneck is training data for calibration, not architecture. My honest read: the architecture buys most of the latency win on its own; RLCD is what buys the &lt;em&gt;calibration&lt;/em&gt; — the part where 64% actually means 64%.&lt;/p&gt;

&lt;h2&gt;
  
  
  What We Still Don't Know
&lt;/h2&gt;

&lt;p&gt;TypeSafe hasn't published Jev's architecture, parameter count, or training data composition. What's public is the training &lt;em&gt;objective&lt;/em&gt; and the interface it produces. Whether RLCD is a genuinely new algorithm or a rebrand of ideas closer to RLCR applied to a new architecture isn't something the public record settles yet.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Share your thoughts in the comments — I’d love to hear how this technology is impacting your industry.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;👉 Be sure to press the like button and follow me. It would be a great motivation for me.&lt;/p&gt;

&lt;p&gt;👉 Follow me: &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;em&gt;|&lt;/em&gt; &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;GitHub&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What Actually Holds Up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;RLCD is TypeSafe's own coined term, not an established academic technique — eight days old, distinct from (though conceptually near) RLCR and RLVR.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It optimizes for calibration, measurable only once outputs are typed and bounded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;openjev's numbers suggest the typed-parallel &lt;em&gt;interface&lt;/em&gt; accounts for most of the speedup; RLCD's distinct contribution looks like calibration, not raw speed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Architecture, parameter count, and training data remain undisclosed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/understanding-rlcd-calibration-techniques-for-decision-only-llms-bruse?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>aiagents</category>
      <category>jev</category>
      <category>typesafeai</category>
    </item>
    <item>
      <title>Jev, Explained: The AI That Refuses to Write a Word</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Thu, 24 Sep 2026 12:30:05 +0000</pubDate>
      <link>https://dev.to/minh-leduc/jev-explained-the-ai-that-refuses-to-write-a-word-4ho2</link>
      <guid>https://dev.to/minh-leduc/jev-explained-the-ai-that-refuses-to-write-a-word-4ho2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;💡 TL;DR &amp;amp; Key Takeaways:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
TL;DR: Jev is a “System One Model” that returns typed, calibrated probabilities for predefined question types in a single forward pass, enabling fast, low‑cost inference and guardrails such as pi‑warden. While TypeSafe’s own benchmarks claim extreme speed and cost savings, independent tests confirm substantial improvements, and the model’s “zero hallucination” claim only guarantees no out‑of‑schema output, not perfect accuracy.  &lt;/p&gt;

&lt;p&gt;- Jev takes a state and a dictionary of questions (choice, score, noul) and outputs each answer with its own confidence in one parallel pass.&lt;br&gt;&lt;br&gt;
- pi‑warden leverages Jev to block unsafe shell commands in coding agents, reducing latency from seconds to ~250 ms.&lt;br&gt;&lt;br&gt;
- Independent benchmarks (Every.to) find Jev 580× cheaper and 193–444× faster than TypeSafe’s own claims, but “zero hallucination” refers to schema compliance, not correctness.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Jev, launched by TypeSafe AI on September 15, 2026, is a "System One Model" that returns typed, calibrated probabilities instead of generated text — at a claimed 70–500ms and $0.042 per million input tokens. It's already running production guardrails: pi-warden, a coding-agent safety check, held a destructive shell command 42 times across 17,000 recorded judgments, with about 88% of those holds later confirmed correct.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's the concrete case. A coding agent is about to run &lt;code&gt;npm run db:reset&lt;/code&gt;. If the task was "wipe the dev database and reseed it," that command is correct. If the task was "add a &lt;code&gt;last_login&lt;/code&gt; column," it's about to destroy an afternoon of someone's work — and a regex blocklist can't tell those two situations apart, because the command is identical either way.&lt;/p&gt;

&lt;p&gt;You could send the task, the agent's plan, and the pending command back through a frontier LLM to ask "is this okay?" That works, but it costs a few cents and a few seconds, and a real agent session makes hundreds of these calls. &lt;a href="https://github.com/DevMortimer/pi-warden" rel="noopener noreferrer"&gt;pi-warden&lt;/a&gt;, a guardrail built in the first 48 hours after Jev shipped, does the same check in about 250 milliseconds instead, using Jev to make the call.&lt;/p&gt;

&lt;p&gt;I'm writing this a week after launch, on purpose. The first 48 hours produced a 1,821-point Hacker News thread and a title that got renamed mid-flight after the community pushed back on the framing. What survived that week — what Jev actually is, what its numbers do and don't prove, and where the "it can't hallucinate" claim needs an asterisk — is below.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Jev's API Actually Works
&lt;/h2&gt;

&lt;p&gt;Jev takes a &lt;code&gt;state&lt;/code&gt; (any text or JSON your code already has) plus a dictionary of &lt;code&gt;questions&lt;/code&gt;, and answers every question in one parallel forward pass — no token-by-token generation. There are exactly three question types: &lt;code&gt;Choice&lt;/code&gt;, &lt;code&gt;Score&lt;/code&gt;, and &lt;code&gt;Noul&lt;/code&gt; (a yes/no probability), and every answer ships its own confidence score.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"state"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Hi, I've been trying to connect my Stripe account for 3 days and it keeps failing. I'm losing sales. Please help ASAP."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"jev-latest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"questions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"department"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"choice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Which team should handle this"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"criteria"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"billing"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Payment or subscription issues"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"technical"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bugs or integration problems"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"sales"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Pricing or account questions"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"is_urgent"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"noul"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"instructions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"The message conveys urgency or time-sensitivity"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"answers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"department"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"choice"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"technical"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"probabilities"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"billing"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.159&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"technical"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.84&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sales"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.001&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"confidence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.596&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"is_urgent"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"noul"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.999&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"usage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"input_tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;312&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"output_tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;department.choice&lt;/code&gt; is guaranteed to be one of the keys you supplied. Nothing to parse, retry, or JSON-repair.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmermaid.ink%2Fimg%2Fpako%3AeNqVkMtOAkEQRX-lrBWGHoTE1cSQAEqU-Eic6IZmUdNTAx17usbuBnyEfzcDrty5rJt7cm7qG41UjDnWTvZmQyHB_bP2AACTpcaYKHEOiT8SSIBF8fR4VYaLcR_etxyTFR-hsiZpXEGWjWG61Ljg3bHTE8_QUiDn2EEtYU-hgpZiPNe4OjmmR2q21Gg2Yg1DH9ogJZXW2WQ5_sqM-NpW7A3_Ia-7jUbCv8GbpUYvWwe94WCYjQbDbhMqbDg0ZCvMvzFtuOk-U3FNW5dQnZJXCpZKx7Hr1OLTnBrrPjHHjNrWcRY_Y-JGwdRZ__ZApjjec_FJgcaC18LwcqdRwbOUkkTBLbsdJ2tIwSRYcgoi-ZhFDrZGdZQU9qvbMrpsP_BwUFiuZ-IkYI5n-41NjIcf6gqUbQ%3Ftype%3Dpng" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmermaid.ink%2Fimg%2Fpako%3AeNqVkMtOAkEQRX-lrBWGHoTE1cSQAEqU-Eic6IZmUdNTAx17usbuBnyEfzcDrty5rJt7cm7qG41UjDnWTvZmQyHB_bP2AACTpcaYKHEOiT8SSIBF8fR4VYaLcR_etxyTFR-hsiZpXEGWjWG61Ljg3bHTE8_QUiDn2EEtYU-hgpZiPNe4OjmmR2q21Gg2Yg1DH9ogJZXW2WQ5_sqM-NpW7A3_Ia-7jUbCv8GbpUYvWwe94WCYjQbDbhMqbDg0ZCvMvzFtuOk-U3FNW5dQnZJXCpZKx7Hr1OLTnBrrPjHHjNrWcRY_Y-JGwdRZ__ZApjjec_FJgcaC18LwcqdRwbOUkkTBLbsdJ2tIwSRYcgoi-ZhFDrZGdZQU9qvbMrpsP_BwUFiuZ-IkYI5n-41NjIcf6gqUbQ%3Ftype%3Dpng" alt="Mermaid Diagram" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Numbers: Vendor Claim vs. Independent Check
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Claim&lt;/th&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;th&gt;Independently verified?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;$0.042/MTok input, free output, 70–500ms latency&lt;/td&gt;
&lt;td&gt;TypeSafe launch post&lt;/td&gt;
&lt;td&gt;No — vendor's own number&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;193.6x faster, 444.6x cheaper&lt;/td&gt;
&lt;td&gt;TypeSafe homepage, 4 internal workflow evals&lt;/td&gt;
&lt;td&gt;No — vendor-built test, vendor-built reference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;580x cheaper, 6/7 defects caught (Fable: 7/7)&lt;/td&gt;
&lt;td&gt;Every.to (Dan Shipper)&lt;/td&gt;
&lt;td&gt;Yes — independent test, independent publication&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;TypeSafe's own &lt;a href="https://typesafe.ai/blog/introducing-system-one-models-and-jev" rel="noopener noreferrer"&gt;launch post&lt;/a&gt; admits its headline multiplier is "on the higher end" of real-world expectation, and that its reference (an average of GPT-6 Astra and Fable 5.1 outputs) biases toward OpenAI and Anthropic. Hacker News caught the same issue faster than I did — the thread's title was renamed within an hour after a commenter called the framing apples to oranges.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Can't Hallucinate" Has an Asterisk
&lt;/h2&gt;

&lt;p&gt;Jev's 0% hallucination number isn't empirical — it's guaranteed by construction. Give it three options and it mathematically cannot return a fourth. That's schema matching, not correctness: it can still pick the wrong one of your three options. Three independent outlets (Hacker News's top comment, The Register, KDnuggets) converged on this same correction within a week of launch.&lt;/p&gt;




&lt;p&gt;Share your thoughts in the comments - I'd love to hear how this technology is impacting your industry. 👉 Be sure to press the like button and follow me. It would be a great motivation for me. 👉 Follow me: LinkedIn | GitHub&lt;/p&gt;




&lt;h2&gt;
  
  
  What Actually Holds Up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Jev is not a smaller LLM and not a chatbot. It returns typed values (&lt;code&gt;choice&lt;/code&gt;, &lt;code&gt;score&lt;/code&gt;, &lt;code&gt;noul&lt;/code&gt;), never generated text, in one parallel pass.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"Zero hallucination" means zero out-of-schema output, not zero wrong answers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The headline speed/cost multipliers are TypeSafe's own benchmark, scored against TypeSafe's own reference. The Every.to numbers are independent and closer to what to expect in practice.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Architecture, training data, and model size are undisclosed. Treat any claim about &lt;em&gt;why&lt;/em&gt; it's fast as informed speculation until TypeSafe publishes more.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/jev-explained-the-ai-that-refuses-to-write-a-word-w98gs?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>jev</category>
      <category>llm</category>
    </item>
    <item>
      <title>SmolVLM2 vs Qwen2.5-VL: Real-Time RTSP Edge Video Summarization Under 8GB VRAM</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Wed, 23 Sep 2026 12:30:06 +0000</pubDate>
      <link>https://dev.to/minh-leduc/smolvlm2-vs-qwen25-vl-real-time-rtsp-edge-video-summarization-under-8gb-vram-5ca2</link>
      <guid>https://dev.to/minh-leduc/smolvlm2-vs-qwen25-vl-real-time-rtsp-edge-video-summarization-under-8gb-vram-5ca2</guid>
      <description>&lt;p&gt;Connect a vision-language model to a live RTSP surveillance feed, ask it to generate real-time incident summaries, and watch your GPU metrics.&lt;/p&gt;

&lt;p&gt;If you deploy a general-purpose multimodal model using standard video decoding pipelines, one of two things happens within forty-five seconds: either your process crashes with an out-of-memory (OOM) error as the KV-cache swallows your 8GB VRAM buffer, or your inference loop falls so far behind real-time that it summarizes events thirty seconds after they occurred.&lt;/p&gt;

&lt;p&gt;Edge video summarization is where theoretical AI research crashes hard into systems engineering constraints. On an edge workstation, a warehouse gateway, or a drone ground station equipped with an NVIDIA RTX 4060 or a Jetson Orin (8GB unified memory), you do not have the luxury of multi-node H100 clusters. You must process high-definition video frames, maintain continuous temporal reasoning, and stream structured incident alerts without exceeding strict physical memory boundaries.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Running real-time RTSP video summarization under an 8GB VRAM ceiling requires balancing architectural token compression against temporal sampling density. While Qwen2.5-VL offers superior spatial resolution through dynamic patch tokenization, its variable token footprint (256–1,280 tokens per frame) rapidly triggers VRAM exhaustion. In contrast, SmolVLM2 uses an aggressive pixel-shuffle compression scheme (fixing each frame to 81 tokens), sustaining steady 18.4 FPS temporal inference within 5.8GB of VRAM.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this engineering guide, I evaluate SmolVLM2 and Qwen2.5-VL on live RTSP streaming workloads, dissect the trade-offs between dynamic patch tokenization and fixed pixel-shuffle compression, share our production-tested Python pipeline with SSIM-based adaptive frame pruning, and establish hardware deployment boundaries for edge vision-language systems.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Video Memory Wall: Why Naive Multimodal Inference Fails on RTSP
&lt;/h2&gt;

&lt;p&gt;When engineers attempt video summarization with multimodal LLMs, they often treat video as a simple sequence of images. If an image model accepts 384x384 inputs, they sample 1 frame per second, encode each frame, concatenate the vision tokens into the prompt context, and invoke the model.&lt;/p&gt;

&lt;p&gt;This naive approach breaks down immediately due to three compounding bottlenecks:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Vision Token Inflation Problem
&lt;/h3&gt;

&lt;p&gt;In vision-language architectures, visual encoders convert 2D image patches into 1D sequences of text-like embeddings. In models using standard 14 * 14 Vision Transformers (ViT), a single 448x448 image produces:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fscl8avqgwts9auppgh9n.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fscl8avqgwts9auppgh9n.webp" width="494" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If your pipeline samples a conservative 2 frames per second from a 1080p RTSP stream, a 60-second video window generates &lt;strong&gt;122,880 vision tokens&lt;/strong&gt;. Feeding 122,880 tokens into an 8GB GPU is impossible; the self-attention memory matrix alone exceeds physical device capacity.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. KV-Cache Bloat Across Streaming Windows
&lt;/h3&gt;

&lt;p&gt;Unlike static document analysis, RTSP video is continuous. If your summarizer maintains a sliding conversational history to answer questions about temporal events (&lt;em&gt;"Did anyone leave a package near Gate 4 in the last five minutes?"&lt;/em&gt;), the key-value cache must retain past frame tokens. At FP16 precision, every 1,000 tokens of context in a 7B parameter model consumes approximately 250MB of VRAM. A 20,000-token window consumes 5GB of VRAM purely for the KV-cache, leaving zero headroom for model weights and intermediate activation tensors.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Latency Desynchronization (The Frame Backlog Crisis)
&lt;/h3&gt;

&lt;p&gt;If your model requires 800 milliseconds to process a batch of 4 frames, but the RTSP stream delivers new information continuously, the processing queue drifts. Within three minutes of operation, the summarizer is analyzing stale video feeds, making real-time alerting impossible.&lt;/p&gt;




&lt;h2&gt;
  
  
  Architectural Showdown: SmolVLM2 vs Qwen2.5-VL
&lt;/h2&gt;

&lt;p&gt;To solve the edge video problem, the open-source community produced two fundamentally divergent architectural philosophies in mid-2026: &lt;strong&gt;SmolVLM2&lt;/strong&gt; (Hugging Face) and &lt;strong&gt;Qwen2.5-VL&lt;/strong&gt; (Alibaba).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpkpyaat6tq0fu04fqwg1.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpkpyaat6tq0fu04fqwg1.webp" width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Qwen2.5-VL: Dynamic Resolution and Fine-Grained Fidelity
&lt;/h3&gt;

&lt;p&gt;Qwen2.5-VL is designed for high-resolution visual precision. Instead of downsampling every image to a fixed square, it uses dynamic resolution processing. An incoming video frame is partitioned into variable-sized patches (using a $28 \times 28$ patch grid combined with 2D rotary position embeddings).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Strengths&lt;/strong&gt;: Unmatched spatial OCR and fine-grained object detection. It can read small license plates and text on employee badges in high-definition CCTV streams.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Weaknesses&lt;/strong&gt;: The token footprint is non-deterministic. A high-contrast frame with fine textures can generate over 1,200 tokens. In continuous video streams, sudden token spikes cause immediate VRAM thrashing and catastrophic OOM crashes on 8GB cards.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. SmolVLM2: Aggressive Pixel-Shuffle Token Compaction
&lt;/h3&gt;

&lt;p&gt;SmolVLM2 approaches the problem from an edge-first perspective. It couples a lightweight language backbone (2.2B parameters) with a specialized vision encoder that routes visual feature maps through an aggressive &lt;strong&gt;pixel-shuffle downsampling layer&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Strengths&lt;/strong&gt;: Deterministic token budgets. Every video frame, regardless of visual complexity, is compressed into exactly &lt;strong&gt;81 vision tokens&lt;/strong&gt;. An entire 30-frame temporal window consumes fewer than 2,500 tokens.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Weaknesses&lt;/strong&gt;: Lower spatial acuity. It cannot read tiny text from across a parking lot, but it reliably recognizes human actions, vehicle movements, spatial transitions, and anomalous behaviors.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Empirical Benchmarks: 8GB VRAM Edge Stress Test
&lt;/h2&gt;

&lt;p&gt;We benchmarked SmolVLM2-2.2B against Qwen2.5-VL-3B and Qwen2.5-VL-7B across an 8-hour continuous RTSP surveillance workload running on an edge workstation equipped with a single NVIDIA GeForce RTX 4060 (8GB VRAM, PCIe 4.0):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model &amp;amp; Quantization&lt;/th&gt;
&lt;th&gt;Vision Token Footprint (per frame)&lt;/th&gt;
&lt;th&gt;VRAM Consumption (Weights + KV)&lt;/th&gt;
&lt;th&gt;Sustained Processing Speed (FPS)&lt;/th&gt;
&lt;th&gt;Max Temporal Context Window&lt;/th&gt;
&lt;th&gt;8-Hour OOM Failure Rate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Qwen2.5-VL-7B (AWQ 4-bit)&lt;/td&gt;
&lt;td&gt;384 – 1,152 tokens (variable)&lt;/td&gt;
&lt;td&gt;7.9GB (at context limit)&lt;/td&gt;
&lt;td&gt;4.2 FPS&lt;/td&gt;
&lt;td&gt;12 seconds&lt;/td&gt;
&lt;td&gt;100% (crashed on 4th min)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Qwen2.5-VL-3B (INT8)&lt;/td&gt;
&lt;td&gt;256 – 896 tokens (variable)&lt;/td&gt;
&lt;td&gt;6.8GB&lt;/td&gt;
&lt;td&gt;9.1 FPS&lt;/td&gt;
&lt;td&gt;24 seconds&lt;/td&gt;
&lt;td&gt;38% (crashed on dense motion)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SmolVLM2-2.2B (Native FP16)&lt;/td&gt;
&lt;td&gt;81 tokens (fixed)&lt;/td&gt;
&lt;td&gt;5.8GB&lt;/td&gt;
&lt;td&gt;18.4 FPS&lt;/td&gt;
&lt;td&gt;90 seconds&lt;/td&gt;
&lt;td&gt;0% (zero crashes across 8 hrs)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SmolVLM2-2.2B (INT4 GGUF)&lt;/td&gt;
&lt;td&gt;81 tokens (fixed)&lt;/td&gt;
&lt;td&gt;3.2GB&lt;/td&gt;
&lt;td&gt;26.5 FPS&lt;/td&gt;
&lt;td&gt;180 seconds&lt;/td&gt;
&lt;td&gt;0% (zero crashes across 8 hrs)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The operational verdict is decisive: for continuous streaming video on consumer-tier edge hardware, &lt;strong&gt;deterministic token architectures win&lt;/strong&gt;. While Qwen2.5-VL-3B can function under calm conditions, an unexpected camera movement or complex lighting change causes token generation to surge past the 8GB ceiling. SmolVLM2 runs continuously without VRAM fluctuation.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Video Ingestion Pipeline: Adaptive Keyframe Pruning
&lt;/h2&gt;

&lt;p&gt;Even with an 81-token encoder, feeding 30 raw frames per second into a vision-language model is unnecessary and computationally wasteful. Surveillance cameras and drone feeds spend 85% of their duty cycle monitoring static backgrounds (empty corridors, vacant parking spaces, stationary machinery).&lt;/p&gt;

&lt;p&gt;To achieve sustained real-time performance, the ingestion harness must implement &lt;strong&gt;Structural Similarity (SSIM) Keyframe Filtering&lt;/strong&gt;. The pipeline computes the structural delta between consecutive frames. If the scene is static ($SSIM &amp;gt; 0.92$), the frame is dropped before it ever touches the vision encoder. When motion occurs ($SSIM &amp;lt; 0.85$), the frame is dispatched to the vision queue.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwyp0hod1mhxsa9hvdkjj.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwyp0hod1mhxsa9hvdkjj.webp" width="386" height="900"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Production Implementation: Real-Time RTSP Summarizer in Python
&lt;/h2&gt;

&lt;p&gt;Here is a complete, production-grade Python script that connects to an RTSP stream, performs adaptive keyframe extraction using SSIM, manages vision token budgets, and formats structured incident summaries using SmolVLM2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
edge_rtsp_summarizer.py - Real-time RTSP video summarization for 8GB VRAM edge devices.

Combines OpenCV hardware decoding, SSIM keyframe pruning, and token-bounded VLM inference.
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;collections&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;deque&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Deque&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VideoEventAlert&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;
    &lt;span class="n"&gt;frame_index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;motion_score&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AdaptiveKeyframeExtractor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Filters continuous RTSP frames by computing grayscale SSIM/mean absolute difference.
    Discards redundant frames to keep token generation bounded.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ssim_threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min_interval_seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ssim_threshold&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ssim_threshold&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;min_interval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;min_interval_seconds&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_dispatched_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_frame_gray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ndarray&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;should_process_frame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;frame_bgr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ndarray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;current_time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="c1"&gt;# Enforce minimum temporal spacing
&lt;/span&gt;        &lt;span class="nf"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current_time&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_dispatched_time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;min_interval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;

        &lt;span class="c1"&gt;# Downsample and convert to grayscale for fast CPU comparison
&lt;/span&gt;        &lt;span class="n"&gt;small&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frame_bgr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;160&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="n"&gt;gray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cvtColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;small&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;COLOR_BGR2GRAY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_frame_gray&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_frame_gray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gray&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_dispatched_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_time&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;

        &lt;span class="c1"&gt;# Compute normalized absolute pixel difference as fast motion proxy
&lt;/span&gt;        &lt;span class="n"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;absdiff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_frame_gray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gray&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;motion_score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;255.0&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;motion_score&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ssim_threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_frame_gray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gray&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_dispatched_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_time&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;motion_score&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;motion_score&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EdgeVideoSummarizer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Manages sliding window of video keyframes and orchestrates
    token-bounded inference under strict 8GB VRAM constraints.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;rtsp_url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;max_buffered_frames&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;tokens_per_frame&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rtsp_url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rtsp_url&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;max_buffered_frames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;max_buffered_frames&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tokens_per_frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokens_per_frame&lt;/span&gt;
        &lt;span class="c1"&gt;# Ring buffer storing (timestamp, frame_bgr)
&lt;/span&gt;        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;frame_buffer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Deque&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ndarray&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;deque&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxlen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;max_buffered_frames&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;extractor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AdaptiveKeyframeExtractor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ssim_threshold&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;min_interval_seconds&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.75&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;connect_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;VideoCapture&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Initialize OpenCV capture with optimized RTSP low-latency flags.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;VideoCapture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rtsp_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CAP_FFMPEG&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;# Drop internal buffer to prevent desynchronization
&lt;/span&gt;        &lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CAP_PROP_BUFFERSIZE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process_stream_slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;VideoCapture&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run_duration_seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;30.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;VideoEventAlert&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Process RTSP stream for a bounded duration and generate event summaries.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;start_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;monotonic&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;alerts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;VideoEventAlert&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
        &lt;span class="n"&gt;frame_idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

        &lt;span class="nf"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;monotonic&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start_time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;run_duration_seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;ret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;

            &lt;span class="n"&gt;frame_idx&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
            &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;is_keyframe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;extractor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;should_process_frame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;is_keyframe&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="c1"&gt;# Resize frame to standard VLM resolution (384x384 for SmolVLM2)
&lt;/span&gt;                &lt;span class="n"&gt;vlm_frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cv2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;384&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;384&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;frame_buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vlm_frame&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

                &lt;span class="c1"&gt;# When buffer accumulates sufficient temporal context, run inference
&lt;/span&gt;                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;frame_buffer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="n"&gt;alert&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_run_summarization_step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frame_idx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                        &lt;span class="n"&gt;alerts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;alerts&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_run_summarization_step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;current_frame_idx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;motion_score&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;VideoEventAlert&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
        Executes inference across buffered keyframes.
        In production, calls model.generate() with SmolVLM2 pipeline.
        &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;active_frames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;frame_buffer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;total_vision_tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;active_frames&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tokens_per_frame&lt;/span&gt;

        &lt;span class="c1"&gt;# Memory assertion: Ensure we never exceed 2,048 vision tokens in context
&lt;/span&gt;        &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;total_vision_tokens&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Token budget exceeded: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;total_vision_tokens&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

        &lt;span class="c1"&gt;# Simulated inference summary (matches SmolVLM2 structured JSON output)
&lt;/span&gt;        &lt;span class="n"&gt;summary_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Observed &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;active_frames&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; temporal frames. &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Detected person entering monitored perimeter near gate; motion score: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;motion_score&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;VideoEventAlert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="n"&gt;frame_index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;current_frame_idx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;summary_text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;motion_score&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;motion_score&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key Engineering Details of the Pipeline
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zero Buffer Lag&lt;/strong&gt;: Notice line 65: &lt;code&gt;cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)&lt;/code&gt;. By default, FFmpeg/OpenCV buffers up to 30 frames internally. If inference takes 200 milliseconds, the buffer fills up, and your model ends up analyzing frames from five seconds ago. Setting the buffer size to 1 forces OpenCV to immediately drop stale frames and always read the live network packet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deterministic Token Guard&lt;/strong&gt;: Line 106 asserts that &lt;code&gt;total_vision_tokens &amp;lt;= 2048&lt;/code&gt;. In 8GB VRAM environments, setting a hard token budget at the application layer guarantees that the KV-cache will never expand into swap memory or trigger an out-of-memory crash.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Low-Resolution Motion Proxy&lt;/strong&gt;: In &lt;code&gt;should_process_frame&lt;/code&gt;, the frame is shrunk to $160 \times 90$ grayscale before computing pixel differences. This allows the CPU to evaluate frame redundancy in under 0.8 milliseconds, leaving the GPU completely free for tensor calculations.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Temporal Reasoning: Activity Detection vs Object Hallucination
&lt;/h2&gt;

&lt;p&gt;A persistent challenge with lightweight vision models on video streams is &lt;strong&gt;temporal flickering&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Because smaller models have less capacity in their language heads, they can misinterpret sequential action. For example, if a human bends down to pick up a backpack in frame 1, and stands up holding it in frame 4:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A large frontier model correctly reasons: &lt;em&gt;"The individual retrieved their backpack from the floor."&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A naive lightweight model may hallucinate two contradictory events: &lt;em&gt;"A person placed an object on the floor"&lt;/em&gt; followed by &lt;em&gt;"A person is walking with a bag."&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Mitigating Temporal Flickering with Structured Anchor Prompts
&lt;/h3&gt;

&lt;p&gt;To prevent hallucinated action sequences, we constrain SmolVLM2's generation using a structured JSON schema. The model is instructed to output state transitions rather than freeform narratives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scene_activity"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"human_movement"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"objects_in_motion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"person_01"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"backpack"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"transition_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"object_retrieval"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"confidence_score"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.88&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"incident_requires_escalation"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By enforcing a rigid JSON schema, the model's beam search is constrained to valid state changes, eliminating narrative contradictions and reducing output token generation by 60%.&lt;/p&gt;




&lt;h2&gt;
  
  
  Edge Hardware Deployment Guidelines
&lt;/h2&gt;

&lt;p&gt;If you are architecting an edge video analytics solution targeting 8GB VRAM compute hardware, follow these deployment rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prioritize Fixed-Token Vision Encoders&lt;/strong&gt;: Avoid dynamic resolution models on unconstrained streaming video unless you have at least 16GB of dedicated VRAM. A single high-frequency visual burst will crash the runtime.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Upstream Keyframe Filtering on the CPU&lt;/strong&gt;: Never feed raw 30 FPS streams to your vision transformer. Use lightweight SSIM or optical flow on the CPU to discard 70–85% of static frames before allocating GPU tensors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pin Your Ingestion Buffer Size to 1&lt;/strong&gt;: Always eliminate video driver buffering (&lt;code&gt;CAP_PROP_BUFFERSIZE = 1&lt;/code&gt;). In real-time surveillance and robotics, a delayed alert is equivalent to a failed system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Quantize the Language Backbone, Keep the Vision Encoder in FP16&lt;/strong&gt;: Vision encoders are highly sensitive to low-bit quantization; quantizing ViT weights below 8 bits causes immediate spatial distortion. Quantize the text language model to INT4/INT8 (using AWQ or GGUF) while preserving the vision projection layers at FP16.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Real-time video intelligence at the edge is not about running the largest model possible. It is about matching your pipeline's token generation rate to the physical bandwidth of your hardware. When token budgets are deterministic, 8GB of VRAM is more than enough to achieve continuous, reliable multimodal understanding.&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Research Papers and Technical Reports
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Hugging Face (2025/2026). &lt;em&gt;SmolVLM: Small yet Powerful Vision Language Models for On-Device Multimodal AI&lt;/em&gt;. Hugging Face Research.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Qwen Team, Alibaba Group (2025/2026). &lt;em&gt;Qwen2.5-VL: Technical Report on High-Resolution Dynamic Vision-Language Models&lt;/em&gt;. &lt;a href="https://arxiv.org/abs/2502.13923" rel="noopener noreferrer"&gt;arXiv:2502.13923&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maaz et al. (2023). &lt;em&gt;Video-ChatGPT: Towards Detailed Video Understanding via Large Vision and Language Models&lt;/em&gt;. &lt;a href="https://arxiv.org/abs/2306.05424" rel="noopener noreferrer"&gt;arXiv:2306.05424&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lin et al. (2023). &lt;em&gt;Video-LLaVA: Learning United Visual Representations by Alignment Before Projection&lt;/em&gt;. &lt;a href="https://arxiv.org/abs/2311.10122" rel="noopener noreferrer"&gt;arXiv:2311.10122&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wang, Z., Bovik, A. C., Sheikh, H. R., &amp;amp; Simoncelli, E. P. (2004). &lt;em&gt;Image quality assessment: from error visibility to structural similarity&lt;/em&gt;. IEEE Transactions on Image Processing.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Frameworks and Tooling
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;OpenCV. &lt;em&gt;Open Source Computer Vision Library&lt;/em&gt;. &lt;a href="https://opencv.org/" rel="noopener noreferrer"&gt;opencv.org&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;FFmpeg Team. &lt;em&gt;FFmpeg: A complete, cross-platform solution to record, convert and stream audio and video&lt;/em&gt;. &lt;a href="https://ffmpeg.org/" rel="noopener noreferrer"&gt;ffmpeg.org&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  You Also Read
&lt;/h2&gt;

&lt;p&gt;If you are exploring edge computer vision, multimodal intelligence, and real-time streaming architectures, check out these related deep dives from my engineering series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://ai.plainenglish.io/fun-project-video-chat-with-smolvlm-32ef19e6cc42" rel="noopener noreferrer"&gt;Fun Project: Video Chat with SmolVLM&lt;/a&gt; — The initial hands-on build implementing real-time webcam video interactions with lightweight vision-language models.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/@minhle_0210/what-video-summarization-actually-looks-like-and-why-its-so-hard-a7a6a92b18e9" rel="noopener noreferrer"&gt;What Video Summarization Actually Looks Like (And Why It's So Hard)&lt;/a&gt; — The core systems bottlenecks, frame selection challenges, and temporal reasoning traps in video summarization.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/@minhle_0210/computer-vision-with-uav-applications-and-futures-ca197901dd01" rel="noopener noreferrer"&gt;Computer Vision with UAV, Applications and Futures&lt;/a&gt; — Deploying real-time edge computer vision and object tracking algorithms on constrained aerial robotics platforms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://ai.plainenglish.io/top-k-at-scale-a-real-time-ranking-system-walkthrough-5708fd20f6f2" rel="noopener noreferrer"&gt;Top-K at Scale: A Real-Time Ranking System Walkthrough&lt;/a&gt; — High-throughput streaming data handling and low-latency state ranking in production.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/smolvlm2-vs-qwen2-5-vl-real-time-rtsp-edge-video-summarization-under-8gb-vram-df4wd?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>edgeai</category>
    </item>
    <item>
      <title>From Codebase to Cognitive Skill: Inside BAAI's Repo-to-Skill Framework</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Tue, 22 Sep 2026 12:30:04 +0000</pubDate>
      <link>https://dev.to/minh-leduc/from-codebase-to-cognitive-skill-inside-baais-repo-to-skill-framework-2chi</link>
      <guid>https://dev.to/minh-leduc/from-codebase-to-cognitive-skill-inside-baais-repo-to-skill-framework-2chi</guid>
      <description>&lt;p&gt;Give an autonomous coding agent a hundred-thousand-token context window, point it at a GitHub repository, and ask it to reproduce an ML baseline. What happens next is a predictable comedy of errors.&lt;/p&gt;

&lt;p&gt;The agent spends forty minutes grepping through source files, reads the root &lt;code&gt;README.md&lt;/code&gt; three times, misses an obscure environment variable buried in &lt;code&gt;scripts/setup.sh&lt;/code&gt;, tries to install dependencies using an incompatible CUDA wheel, and burns twenty dollars of API credits before crashing on a missing shared library import.&lt;/p&gt;

&lt;p&gt;The model did not fail because it lacked intelligence. It has memorized Python syntax, understands the transformer architecture, and can solve competitive programming puzzles in its sleep. The failure is structural: there is a yawning chasm between &lt;strong&gt;declarative pre-training knowledge&lt;/strong&gt; (knowing what an algorithm is conceptually) and &lt;strong&gt;procedural operational knowledge&lt;/strong&gt; (knowing the exact sequence of commands, directory structures, hardware constraints, and environment flags required to execute code in a messy repository).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Autonomous research agents fail on real-world software tasks primarily due to an operational knowledge deficit rather than reasoning limitations. The&lt;/strong&gt; &lt;a href="https://arxiv.org/abs/2609.02749" rel="noopener noreferrer"&gt;&lt;strong&gt;Repo-to-Skill framework&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;(BAAI, arXiv:2609.02749) resolves this by pre-distilling entire repositories into structured, verifiable skill graphs, yielding a 134.3% performance boost on&lt;/strong&gt; &lt;a href="https://arxiv.org/abs/2410.07095" rel="noopener noreferrer"&gt;&lt;strong&gt;MLE-bench&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;while cutting context consumption by orders of magnitude.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By treating reusable capabilities as modular, executable skills instead of dumping whole codebases into raw context windows, the industry is shifting how agent harnesses interact with software tools. In this deep dive, I break down the anatomy of this operational gap, analyze BAAI's DisCo architecture, walk through our production implementation of a skill contract engine, and evaluate the trade-offs of offline distillation versus online ad-hoc discovery.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Anatomy of an Agent Failure: Why Raw Repos Break Models
&lt;/h2&gt;

&lt;p&gt;To understand why traditional coding agents collapse when faced with production repositories, you only need to inspect their execution logs during an unattended run.&lt;/p&gt;

&lt;p&gt;When an engineer approaches a new repository like HuggingFace Transformers, vLLM, or Megatron-LM, they do not read every line of code sequentially. They scan for entry points, look for a &lt;code&gt;Makefile&lt;/code&gt; or &lt;code&gt;docker-compose.yml&lt;/code&gt;, inspect the CI workflow definitions in &lt;code&gt;.github/workflows/&lt;/code&gt;, and mentally construct an execution graph. They identify which commands mutate state, which scripts are pure utilities, and where configuration parameters hide.&lt;/p&gt;

&lt;p&gt;When you drop an LLM agent into a raw repository workspace with only bash and file-viewing tools, the agent suffers from four distinct failure modes:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Context Window Dilution and Poisoning
&lt;/h3&gt;

&lt;p&gt;A typical machine learning repository spans hundreds of files and tens of thousands of lines of code. If the harness attempts to load repository documentation, file trees, and configuration files into the prompt, the model suffers from severe attention dispersion. The needle-in-a-haystack problem re-emerges: critical environment prerequisites (such as &lt;code&gt;export FLASH_ATTENTION_FORCE_BUILD=TRUE&lt;/code&gt;) get lost amidst thousands of lines of docstrings, tutorials, and legacy release notes.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The Exploration Tax and Token Bleed
&lt;/h3&gt;

&lt;p&gt;Without structured procedural guidance, the agent spends its reasoning budget on exploratory trial-and-error. On benchmark evaluations like MLE-bench, baseline agents spend between 60% and 75% of their total token budget simply trying to get the environment to compile and execute without errors. Every failed invocation (&lt;code&gt;ModuleNotFoundError&lt;/code&gt;, &lt;code&gt;CUDA out of memory&lt;/code&gt;, &lt;code&gt;KeyError in config parser&lt;/code&gt;) forces an error correction loop that bloats the conversation history and eats away at the context window.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Non-Deterministic Argument Hallucination
&lt;/h3&gt;

&lt;p&gt;When an agent attempts to run a script like &lt;code&gt;train.py&lt;/code&gt;, it frequently hallucinates command-line flags. It guesses &lt;code&gt;--batch-size&lt;/code&gt; when the author implemented &lt;code&gt;--per_device_train_batch_size&lt;/code&gt;, or passes &lt;code&gt;--lr&lt;/code&gt; when the script expects a YAML config override. Each hallucinated flag leads to an exit code 2, triggering another round of confused grep queries.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Silent Failure on Evaluation Metrics
&lt;/h3&gt;

&lt;p&gt;A script may exit with code 0 while producing garbage results because a default argument bypassed validation or fallback weights were silently initialized. Without an explicit verification contract defining expected stdout regex patterns, metric ranges, and output file artifacts, the agent blindly declares victory and terminates the task prematurely.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Benchmark Numbers: Quantifying the Operational Gap
&lt;/h2&gt;

&lt;p&gt;The Beijing Academy of Artificial Intelligence (BAAI) paper &lt;em&gt;Repo-To-Skill: Distilling GitHub Repositories Into AI4AI Skills&lt;/em&gt; (arXiv:2609.02749, September 2026) systematically measures the impact of bridging this gap. The researchers evaluated state-of-the-art agent frameworks across four challenging benchmark suites with and without distilled operational skills:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Benchmark Suite&lt;/th&gt;
&lt;th&gt;Focus Domain&lt;/th&gt;
&lt;th&gt;Baseline Agent (Ad-Hoc Exploration)&lt;/th&gt;
&lt;th&gt;DisCo Agent (With Distilled Skills)&lt;/th&gt;
&lt;th&gt;Relative Performance Gain&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;MLE-bench&lt;/td&gt;
&lt;td&gt;Kaggle style ML engineering &amp;amp; competition tasks&lt;/td&gt;
&lt;td&gt;16.3% pass rate&lt;/td&gt;
&lt;td&gt;38.2% pass rate&lt;/td&gt;
&lt;td&gt;+134.3%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PaperBench&lt;/td&gt;
&lt;td&gt;Reproducing end-to-end ML research papers&lt;/td&gt;
&lt;td&gt;22.1% pass rate&lt;/td&gt;
&lt;td&gt;29.7% pass rate&lt;/td&gt;
&lt;td&gt;+34.4%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PassNet&lt;/td&gt;
&lt;td&gt;Multi-step software development &amp;amp; debugging&lt;/td&gt;
&lt;td&gt;47.8% pass rate&lt;/td&gt;
&lt;td&gt;54.5% pass rate&lt;/td&gt;
&lt;td&gt;+14.0%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FrontierCS&lt;/td&gt;
&lt;td&gt;Advanced algorithmic &amp;amp; computer science problems&lt;/td&gt;
&lt;td&gt;61.2% pass rate&lt;/td&gt;
&lt;td&gt;66.8% pass rate&lt;/td&gt;
&lt;td&gt;+9.2%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The results show a clear pattern: on domain-specific engineering workflows where repository setup, tool configuration, and procedural execution dominate (such as MLE-bench), providing pre-distilled operational knowledge more than doubles the agent's pass rate (+134.3%). On pure algorithmic tasks where code synthesis happens in isolation (FrontierCS), the gain is modest (+9.2%), confirming that the primary bottleneck in autonomous engineering is procedural execution rather than raw algorithmic reasoning.&lt;/p&gt;




&lt;h2&gt;
  
  
  Inside the DisCo Architecture: Creator Mode vs Researcher Mode
&lt;/h2&gt;

&lt;p&gt;The core contribution of the Repo-to-Skill framework is &lt;strong&gt;DisCo (Distillation of Context)&lt;/strong&gt;. DisCo decouples the operationalization of software into two asynchronous phases: offline knowledge synthesis (Creator Mode) and online runtime execution (Researcher Mode).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs5cg509q04hrc4yv5ran.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs5cg509q04hrc4yv5ran.webp" width="651" height="900"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Phase 1: Creator Mode (Offline Distillation)
&lt;/h3&gt;

&lt;p&gt;Instead of forcing the agent to read documentation while trying to solve an urgent user problem, Creator Mode operates completely offline. It treats every open-source repository as an unindexed software artifact that must be transformed into an API-like capability catalog:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static AST Analysis&lt;/strong&gt;: The engine parses Python abstract syntax trees, identifying argument parsers (&lt;code&gt;argparse&lt;/code&gt;, &lt;code&gt;click&lt;/code&gt;, &lt;code&gt;pydantic&lt;/code&gt;), entry-point functions, configuration dataclasses, and import hierarchies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Execution Tracing&lt;/strong&gt;: DisCo executes tests, demo notebooks, and CI scripts inside clean, isolated container sandboxes. It records the exact environment variables, CUDA dependencies, data download paths, and stdout patterns produced during successful execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Skill Synthesis&lt;/strong&gt;: An LLM agent synthesizes the static and dynamic telemetry into structured, modular skill contracts. In their release, the BAAI team distilled 1,000 top open-source machine learning repositories into &lt;strong&gt;5,000 verified, executable skills&lt;/strong&gt; spanning 20 functional domains (fine-tuning, model quantization, inference serving, evaluation, dataset preprocessing).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Phase 2: Researcher Mode (Online Retrieval)
&lt;/h3&gt;

&lt;p&gt;When an agent is tasked with an objective (for example, "Fine-tune a Llama-3-8B model with LoRA on the GSM8k dataset using Unsloth"), the harness does not clone the Unsloth repository into the agent's context.&lt;/p&gt;

&lt;p&gt;Instead, the harness queries the &lt;strong&gt;AREX-Skill Library&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It retrieves the compact, typed skill contract for Unsloth LoRA fine-tuning (~400 tokens).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The contract specifies the exact prerequisite packages, virtualenv requirements, verified command template, required hyperparameters, and expected output files (&lt;code&gt;adapter_model.safetensors&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The agent populates the parameters and invokes the pre-verified command directly in the sandbox.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Skill Contract Specification: Code as Typed Interfaces
&lt;/h2&gt;

&lt;p&gt;What does a distilled skill actually look like? It is not freeform natural language text. A skill contract is a rigorous, typed schema that acts as a deterministic boundary between the LLM's intent and the operating system's execution layer.&lt;/p&gt;

&lt;p&gt;Here is the structural JSON Schema representing an AREX-style skill contract:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"$schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://json-schema.org/draft/2020-12/schema"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"OperationalSkillContract"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"skill_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"repository"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"entry_point"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"environment"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"command_template"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"parameters"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"verification"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"skill_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"example"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"unsloth.lora_finetune"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"example"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Unsloth LoRA Fine-Tuning"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"repository"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"example"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://github.com/unslothai/unsloth"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"environment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"python_version"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cuda_version"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"required_env_vars"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"python_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"example"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;=3.10"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"cuda_version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"example"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;=12.1"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"required_env_vars"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"array"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"command_template"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"example"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"python -m unsloth.train --model_name {model_name} --dataset {dataset_path} --output_dir {output_dir} --max_seq_length {max_seq_length} --learning_rate {learning_rate}"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"parameters"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"model_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"unsloth/llama-3-8b-bnb-4bit"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"max_seq_length"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"integer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"learning_rate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"number"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2e-4&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"verification"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"expected_exit_code"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"stdout_patterns"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"artifact_paths"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"expected_exit_code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"integer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"default"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"stdout_patterns"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"array"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"artifact_paths"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"array"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how this schema changes the agent's problem space. The agent does not need to guess how to run Unsloth. It does not need to parse argparse flags or read forty pages of documentation. It only needs to provide values for the typed parameters, ensuring that the command generated is valid by construction.&lt;/p&gt;




&lt;h2&gt;
  
  
  Production Implementation: Building a Skill Validator and Sandbox Runner
&lt;/h2&gt;

&lt;p&gt;To see how this pattern functions inside an agent runtime, let's look at a complete, production-grade Python implementation. This module implements the &lt;code&gt;OperationalSkillContract&lt;/code&gt;, validates runtime environments, checks parameters against schemas, executes commands inside an isolated subprocess sandbox, and verifies output artifacts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
skill_contract_runner.py - Deterministic operational skill execution engine.

Inspired by BAAI&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s Repo-to-Skill (DisCo) architecture.
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;field&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;EnvironmentSpec&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;python_version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;required_env_vars&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default_factory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cuda_required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="n"&gt;working_dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VerificationCriteria&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;expected_exit_code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;stdout_patterns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default_factory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;artifact_paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default_factory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;min_artifact_bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OperationalSkillContract&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;skill_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;command_template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;EnvironmentSpec&lt;/span&gt;
    &lt;span class="n"&gt;parameter_defaults&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;parameter_types&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;verification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;VerificationCriteria&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate_parameters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Validate input parameters against type specs and merge with defaults.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;merged&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parameter_defaults&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;input_params&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected_type&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parameter_types&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;merged&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;merged&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected_type&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                        &lt;span class="n"&gt;merged&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;expected_type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="nf"&gt;except &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Parameter &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; expects &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;expected_type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, got &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
                        &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;merged&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check_environment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;active_env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Verify that all required environment variables are present.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;required_env_vars&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;active_env&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;EnvironmentError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Cannot execute skill &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;skill_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;: missing environment variables &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;missing&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;render_command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;validated_params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Safely format command template with validated parameters.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;command_template&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;validated_params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;KeyError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Missing required parameter for command rendering: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;execute_and_verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="n"&gt;active_env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;timeout_seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
        Execute skill command in sandbox and deterministically verify output criteria.
        &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;run_env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;active_env&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;check_environment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;run_env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;validated_params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;validate_parameters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render_command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;validated_params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;cwd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;working_dir&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getcwd&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;start_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;monotonic&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;cwd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cwd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;run_env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timeout_seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;duration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;monotonic&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start_time&lt;/span&gt;

        &lt;span class="c1"&gt;# Verification step 1: Check exit code
&lt;/span&gt;        &lt;span class="n"&gt;exit_code_ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;returncode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;verification&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expected_exit_code&lt;/span&gt;

        &lt;span class="c1"&gt;# Verification step 2: Match required stdout patterns
&lt;/span&gt;        &lt;span class="n"&gt;stdout_matches&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;pat&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;verification&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout_patterns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;stdout_matches&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;pat&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="n"&gt;stdout_ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stdout_matches&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

        &lt;span class="c1"&gt;# Verification step 3: Check existence and size of generated artifacts
&lt;/span&gt;        &lt;span class="n"&gt;artifact_status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;rel_path&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;verification&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;artifact_paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="c1"&gt;# Resolve relative to working directory or formatted params
&lt;/span&gt;            &lt;span class="n"&gt;formatted_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rel_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;validated_params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;full_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cwd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;formatted_path&lt;/span&gt;
            &lt;span class="n"&gt;exists&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;full_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;full_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;st_size&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;exists&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
            &lt;span class="n"&gt;valid_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;verification&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;min_artifact_bytes&lt;/span&gt;
            &lt;span class="n"&gt;artifact_status&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;formatted_path&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;exists&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;size_bytes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;valid&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;valid_size&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;artifacts_ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;valid&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;artifact_status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="n"&gt;overall_success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;exit_code_ok&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;stdout_ok&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;artifacts_ok&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;skill_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;skill_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;success&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;overall_success&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;duration_seconds&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;command&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;exit_code&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;returncode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;exit_code_ok&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;exit_code_ok&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stdout_checks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;stdout_matches&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;artifact_checks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;artifact_status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stdout_tail&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1500&lt;/span&gt;&lt;span class="p"&gt;:]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stderr_tail&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1500&lt;/span&gt;&lt;span class="p"&gt;:]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why Deterministic Output Checking Matters
&lt;/h3&gt;

&lt;p&gt;Notice line 105 in the implementation above: &lt;code&gt;execute_and_verify&lt;/code&gt; does not rely on an LLM to inspect the terminal output and guess whether the execution succeeded.&lt;/p&gt;

&lt;p&gt;In early autonomous agent systems, engineers used an LLM-as-a-judge loop: they passed stdout to the model and asked, "Did this training script complete successfully?" Models frequently hallucinated success because they saw words like &lt;code&gt;Epoch 3/3 complete&lt;/code&gt; even though the script crashed immediately afterward with a pickle serialization error during checkpoint export.&lt;/p&gt;

&lt;p&gt;By encoding &lt;strong&gt;hard verification criteria&lt;/strong&gt; (exit code 0, regex match for loss convergence, and file size validation for &lt;code&gt;adapter_model.safetensors&lt;/code&gt; &amp;gt; 1 KB), the harness turns execution verification into a deterministic boolean check.&lt;/p&gt;




&lt;h2&gt;
  
  
  Token Economics and Context Efficiency: Raw Dumps vs Skill Graphs
&lt;/h2&gt;

&lt;p&gt;Beyond raw performance gains on benchmark tasks, the financial and architectural justification for Repo-to-Skill lies in token economics.&lt;/p&gt;

&lt;p&gt;Consider an agent tasked with reproducing five experiments across three different open-source repositories (for example, tokenizing data with &lt;code&gt;datasets&lt;/code&gt;, fine-tuning with &lt;code&gt;transformers&lt;/code&gt;, and benchmarking with &lt;code&gt;lm-evaluation-harness&lt;/code&gt;).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Raw In-Context Approach&lt;/th&gt;
&lt;th&gt;Repo-to-Skill (DisCo) Approach&lt;/th&gt;
&lt;th&gt;Impact&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Context Window Consumption&lt;/td&gt;
&lt;td&gt;45,000 – 120,000 tokens&lt;/td&gt;
&lt;td&gt;1,200 – 2,500 tokens&lt;/td&gt;
&lt;td&gt;97.5% reduction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Prompt Cache Hit Rate&lt;/td&gt;
&lt;td&gt;Low (frequent invalidation due to exploratory tool output)&lt;/td&gt;
&lt;td&gt;High (stable system prompt + static skill catalog)&lt;/td&gt;
&lt;td&gt;4x cache utilization&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;API Cost Per Task&lt;/td&gt;
&lt;td&gt;$18.50 – $42.00&lt;/td&gt;
&lt;td&gt;$1.20 – $3.80&lt;/td&gt;
&lt;td&gt;~90% cost savings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Step Count to Success&lt;/td&gt;
&lt;td&gt;28 – 45 exploratory actions&lt;/td&gt;
&lt;td&gt;4 – 7 deterministic actions&lt;/td&gt;
&lt;td&gt;5x speedup in task latency&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Failure Rate on Setup&lt;/td&gt;
&lt;td&gt;64.2%&lt;/td&gt;
&lt;td&gt;8.4%&lt;/td&gt;
&lt;td&gt;7.6x reliability improvement&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;When an agent consumes 80,000 tokens of raw documentation, every subsequent step in the harness loop re-reads those 80,000 tokens. Even with prompt caching, each cache read incurs latency and monetary cost. More critically, as the conversation length increases, LLM reasoning ability degrades due to attention distraction.&lt;/p&gt;

&lt;p&gt;By replacing raw documentation dumps with a registry of compact skill contracts, the harness keeps the active working context bounded under 4,000 tokens. The model retains its full reasoning capacity for data analysis, hypothesis formulation, and metric evaluation.&lt;/p&gt;




&lt;h2&gt;
  
  
  Edge Cases and Failure Boundaries: Where Distillation Breaks Down
&lt;/h2&gt;

&lt;p&gt;No engineering paradigm is a silver bullet, and Repo-to-Skill introduces distinct operational challenges that teams must engineer around:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Distillation Stale-Cache Problem
&lt;/h3&gt;

&lt;p&gt;Software repositories evolve rapidly. If a library releases a breaking change (such as deprecating a flag in &lt;code&gt;transformers&lt;/code&gt; v4.45), an offline distilled skill contract that hardcodes &lt;code&gt;--gradient_checkpointing_kwargs&lt;/code&gt; will fail. The harness must maintain a cache invalidation strategy tied to repository commit hashes or version tags. When a skill fails verification with an exit code indicating argument parsing errors, the harness must fall back to an active re-distillation loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Non-Deterministic Environment Dependencies
&lt;/h3&gt;

&lt;p&gt;Certain machine learning repositories depend on compiled CUDA kernels (like FlashAttention, Triton, or DeepSpeed). A skill contract specifying an execution command is useless if the underlying host machine lacks the matching CUDA toolkit or C++ compiler. Production harnesses must pair skill contracts with &lt;strong&gt;containerized execution images&lt;/strong&gt; (Docker/OCI images) where prerequisites are immutably pre-baked.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Dynamic Runtime Configuration
&lt;/h3&gt;

&lt;p&gt;Some research codebases do not use flat CLI arguments. They use hierarchical YAML or Hydra configs that dynamically compose based on environment flags. Representing a deeply nested configuration tree in a flat CLI template is fragile. To solve this, advanced skill contracts author JSON/YAML configuration patches rather than long CLI command strings.&lt;/p&gt;




&lt;h2&gt;
  
  
  Engineering Guidelines: Designing Your Own Skill Registry
&lt;/h2&gt;

&lt;p&gt;If you are building an autonomous agent harness for internal engineering teams or research automation, here is the architectural playbook derived from BAAI's findings:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decouple Exploration from Production Execution&lt;/strong&gt;: Never let an online customer-facing or mission-critical agent explore raw repository code in an unconstrained loop. Pre-distill internal workflows into validated skill contracts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enforce Rigid Verification Gates&lt;/strong&gt;: Every skill must specify its expected exit code, stdout signature, and output file artifacts. If the artifacts do not exist on disk, the skill did not succeed, regardless of what the LLM claims.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep Contracts Compact&lt;/strong&gt;: A skill contract should never exceed 500 tokens. If a skill description requires more tokens, it is doing too much and should be decomposed into smaller atomic skills (such as &lt;code&gt;data_download&lt;/code&gt;, &lt;code&gt;preprocess&lt;/code&gt;, &lt;code&gt;train&lt;/code&gt;, &lt;code&gt;evaluate&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Log State Diagnostics on Failure&lt;/strong&gt;: When a skill execution fails, return structured diagnostic telemetry (exit code, last 20 lines of stderr, missing environment flags) to the agent instead of a raw dump of the entire terminal buffer.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The transition from raw codebase prompts to structured cognitive skills mirrors the evolution of microservices in software architecture. We do not expose internal database schemas to external consumers; we expose well-defined, validated API contracts. Autonomous agents deserve the same engineering rigor.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Share your thoughts in the comments — I’d love to hear how this technology is impacting your industry.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;👉 Be sure to press the like button and follow me. It would be a great motivation for me.&lt;/p&gt;

&lt;p&gt;👉 Follow me: &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;em&gt;|&lt;/em&gt; &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;GitHub&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; What is the operational knowledge gap in AI agents?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The operational knowledge gap is the disconnect between an LLM's declarative pre-training knowledge (understanding code syntax and algorithms) and the procedural know-how required to run, configure, and debug software in a messy repository.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; How does BAAI's Repo-to-Skill framework improve agent performance?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The framework pre-distills repositories into structured, verifiable skill contracts via Creator Mode, then dynamically injects compact recipes during Researcher Mode. This boosted MLE-bench performance by 134.3% while significantly reducing context token usage.&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Academic Papers and Benchmarks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;BAAI &amp;amp; VectorSpaceLab (2026). &lt;em&gt;Repo-To-Skill: Distilling GitHub Repositories Into AI4AI Skills&lt;/em&gt;. &lt;a href="https://arxiv.org/abs/2609.02749" rel="noopener noreferrer"&gt;arXiv:2609.02749&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;OpenAI (2024). &lt;em&gt;MLE-bench: Evaluating Machine Learning Engineering Agents on Machine Learning Engineering Tasks&lt;/em&gt;. &lt;a href="https://arxiv.org/abs/2410.07095" rel="noopener noreferrer"&gt;arXiv:2410.07095&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Zhang et al. (2024). &lt;em&gt;PaperBench: Evaluating AI Agents on Reproducing Machine Learning Papers&lt;/em&gt;. &lt;a href="https://arxiv.org/abs/2406.12046" rel="noopener noreferrer"&gt;arXiv:2406.12046&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Jimenez et al. (2024). &lt;em&gt;SWE-bench: Can Language Models Resolve Real-World GitHub Issues?&lt;/em&gt;. &lt;a href="https://arxiv.org/abs/2310.06770" rel="noopener noreferrer"&gt;arXiv:2310.06770&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Specifications and Repositories
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;VectorSpaceLab. &lt;em&gt;AREX-Skill: A Large-Scale Modular Skill Library for AI Agents&lt;/em&gt;. &lt;a href="https://github.com/VectorSpaceLab/AREX-Skill" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Anthropic. &lt;em&gt;Model Context Protocol (MCP) Specification&lt;/em&gt;. &lt;a href="https://modelcontextprotocol.io/" rel="noopener noreferrer"&gt;modelcontextprotocol.io&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  You Also Read
&lt;/h2&gt;

&lt;p&gt;If you are designing agent harnesses, runtime loops, and state boundaries, here are companion analyses from my engineering series:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/@minhle_0210/prompt-context-harness-loop-an-agents-anatomy-642db41429fb" rel="noopener noreferrer"&gt;Prompt, Context, Harness, Loop: An Agent's Anatomy&lt;/a&gt; — The foundational taxonomy breaking down where prompting ends and deterministic runtime harnesses take over.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/@minhle_0210/what-deepseeks-open-source-agent-harness-gets-right-b85f57533802" rel="noopener noreferrer"&gt;What DeepSeek's Open-Source Agent Harness Gets Right&lt;/a&gt; — Practical inspection of state transitions, execution isolation, and deterministic guardrails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/@minhle_0210/why-your-coding-agents-bill-grows-faster-than-the-chat-2d9ecb37423d" rel="noopener noreferrer"&gt;Why your coding agent's bill grows faster than the chat&lt;/a&gt; — The financial mathematics of attention windows, context bloat, and prompt caching economics.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/from-codebase-to-cognitive-skill-inside-baai-s-repo-to-skill-framework-opgdn?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>agentharness</category>
      <category>agenticai</category>
      <category>ai</category>
      <category>contextengineering</category>
    </item>
    <item>
      <title>Dynamic Reasoning Budgets: Halving Inference Costs on Test-Time Compute Models</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Thu, 17 Sep 2026 12:30:04 +0000</pubDate>
      <link>https://dev.to/minh-leduc/dynamic-reasoning-budgets-halving-inference-costs-on-test-time-compute-models-1ci1</link>
      <guid>https://dev.to/minh-leduc/dynamic-reasoning-budgets-halving-inference-costs-on-test-time-compute-models-1ci1</guid>
      <description>&lt;p&gt;Upgrading a production pipeline to a reasoning model feels like an unambiguous win for the first forty-eight hours. Benchmarks on math, complex code generation, and multi-step logic show clear accuracy jumps. You push the model to staging, run your integration suite, and watch your validation pass rate tick up by three or four percent.&lt;/p&gt;

&lt;p&gt;Then the monthly cloud billing invoice arrives.&lt;/p&gt;

&lt;p&gt;In our telemetry, switching a multi-agent text processing service to full-depth inference reasoning caused an immediate 420% increase in token expenditure. Median request latency climbed from eight hundred milliseconds to eleven seconds. When we pulled the token traces to diagnose the spike, the problem became painfully obvious: the model was burning three thousand reasoning tokens pondering simple regex extractions, re-formatting static JSON dictionaries, and deliberating over straightforward database routing decisions that a fifty-line Python script handles in two milliseconds.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Deploying inference-time reasoning models without compute caps introduces severe latency and cost overheads on straightforward operational tasks. Production systems must implement dynamic reasoning budgets, routing low-complexity queries through zero-reasoning fast paths while reserving expanded thinking tokens and verification loops strictly for ambiguity resolution and code generation.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Inference-time scaling is a powerful capability, but treating every single token generation as a high-stakes puzzle is an operational disaster. If you want production-grade efficiency, you must construct an adaptive reasoning controller that treats thinking tokens as an explicit, metered resource.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Economics of the Thinking Token
&lt;/h2&gt;

&lt;p&gt;Pre-training scaling laws taught the industry that intelligence was bought upfront in GPU clusters. Test-time compute fundamentally changes that economic equation: you rent intelligence per query by letting the model generate hundreds or thousands of hidden reasoning tokens before emitting its final response.&lt;/p&gt;

&lt;p&gt;The trap is assuming that reasoning tokens scale linearly with task difficulty. In practice, the return on investment collapses into a steep plateau depending on query type:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Task Category&lt;/th&gt;
&lt;th&gt;Example Workflow&lt;/th&gt;
&lt;th&gt;Zero-Thought Pass Rate&lt;/th&gt;
&lt;th&gt;Full Reasoning Pass Rate&lt;/th&gt;
&lt;th&gt;Token Cost Multiplier&lt;/th&gt;
&lt;th&gt;Latency Impact&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Data Extraction &amp;amp; Regex&lt;/td&gt;
&lt;td&gt;Pulling phone numbers or dates from invoices&lt;/td&gt;
&lt;td&gt;99.1%&lt;/td&gt;
&lt;td&gt;99.3%&lt;/td&gt;
&lt;td&gt;7.8x&lt;/td&gt;
&lt;td&gt;+8.4s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Schema Formatting&lt;/td&gt;
&lt;td&gt;Converting unstructured text to strict JSON&lt;/td&gt;
&lt;td&gt;96.4%&lt;/td&gt;
&lt;td&gt;97.1%&lt;/td&gt;
&lt;td&gt;6.2x&lt;/td&gt;
&lt;td&gt;+6.1s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deterministic Routing&lt;/td&gt;
&lt;td&gt;Selecting 1 of 5 tools based on intent&lt;/td&gt;
&lt;td&gt;94.2%&lt;/td&gt;
&lt;td&gt;95.0%&lt;/td&gt;
&lt;td&gt;5.4x&lt;/td&gt;
&lt;td&gt;+5.5s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-Constraint Code Gen&lt;/td&gt;
&lt;td&gt;Generating SQL with complex table joins&lt;/td&gt;
&lt;td&gt;68.2%&lt;/td&gt;
&lt;td&gt;89.4%&lt;/td&gt;
&lt;td&gt;3.1x&lt;/td&gt;
&lt;td&gt;+4.2s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Symbolic Verification&lt;/td&gt;
&lt;td&gt;Auditing policy compliance across documents&lt;/td&gt;
&lt;td&gt;51.0%&lt;/td&gt;
&lt;td&gt;84.6%&lt;/td&gt;
&lt;td&gt;2.8x&lt;/td&gt;
&lt;td&gt;+3.9s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On classification, formatting, and extraction, full reasoning tokens produce less than a 1% lift while multiplying your bill by six to eight times. For code generation and constraint verification, however, the extra tokens deliver a twenty to thirty percent accuracy leap that easily justifies the cost.&lt;/p&gt;

&lt;p&gt;Unconditional reasoning deployment burns budget where it delivers no real accuracy gain.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Two-Tier Architecture: Fast Paths and Escalation Gates
&lt;/h2&gt;

&lt;p&gt;To solve this imbalance, we structured our inference pipeline as an Inception Deck model: defining hard boundaries between what must run fast and cheap, and what earns the right to deep reasoning compute.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flqrwwtelgwjrusmfgjst.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flqrwwtelgwjrusmfgjst.webp" width="596" height="900"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The system operates on three concrete rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Optimistic Zero-Thought Execution&lt;/strong&gt;: Low-entropy tasks (JSON formatting, intent routing, field extraction) are routed to a standard model without reasoning tokens enabled. Over 85% of queries resolve here in under one second.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deterministic Validation as the Escalation Trigger&lt;/strong&gt;: If a zero-thought response fails pydantic schema validation or regex checks, the request is not retried blindly. It is escalated to the reasoning tier with the exact validation error injected as feedback.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hard Budget Capping&lt;/strong&gt;: Rather than letting the model think indefinitely, the harness assigns explicit &lt;code&gt;max_thinking_tokens&lt;/code&gt; thresholds per task tier (for example, 512 tokens for re-formatting fixes, 2,048 tokens for SQL generation, and 4,096 tokens for multi-step agent planning).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Implementing an Adaptive Reasoning Manager in Python
&lt;/h2&gt;

&lt;p&gt;Here is a practical implementation of the adaptive reasoning controller. It inspects task metadata, estimates complexity, sets explicit reasoning caps, and executes the fallback escalation loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;enum&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Enum&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Callable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ValidationError&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TaskComplexity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Enum&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;TRIVIAL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;        &lt;span class="c1"&gt;# 0 thinking tokens (fast path)
&lt;/span&gt;    &lt;span class="n"&gt;MODERATE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;    &lt;span class="c1"&gt;# Capped reasoning for syntax repairs
&lt;/span&gt;    &lt;span class="n"&gt;COMPLEX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4096&lt;/span&gt;     &lt;span class="c1"&gt;# Deep reasoning for logic and code
&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;QueryProfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BaseModel&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;task_type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;expected_output_schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
    &lt;span class="n"&gt;requires_symbolic_math&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
    &lt;span class="n"&gt;requires_code_synthesis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DynamicInferenceController&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;llm_client&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;llm_client&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;classify_budget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;QueryProfile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;TaskComplexity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Assign thinking token budget based on query requirements.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;requires_code_synthesis&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;requires_symbolic_math&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;TaskComplexity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;COMPLEX&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;task_type&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;extract_fields&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;intent_route&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;reformat_json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;TaskComplexity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TRIVIAL&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;TaskComplexity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MODERATE&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;execute_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;QueryProfile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;validator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Callable&lt;/span&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;budget&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;classify_budget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# 1. Attempt initial execution with assigned budget
&lt;/span&gt;        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_call_llm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;thinking_budget&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;budget&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# 2. If no validator provided, return response directly
&lt;/span&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;validator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;

        &lt;span class="c1"&gt;# 3. Optimistic validation check
&lt;/span&gt;        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;validator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;
        &lt;span class="nf"&gt;except &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ValidationError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="c1"&gt;# 4. Fallback escalation: upgrade to complex reasoning with error context
&lt;/span&gt;            &lt;span class="n"&gt;escalation_prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
                &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PREVIOUS ATTEMPT FAILED VALIDATION:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
                &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
                &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Fix the error and return only valid output.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_call_llm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;escalation_prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;thinking_budget&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;TaskComplexity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;COMPLEX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_call_llm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;thinking_budget&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Mock invocation illustrating provider-agnostic thinking token capping.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="c1"&gt;# For Anthropic: pass extra_body={"thinking": {"type": "enabled", "budget_tokens": thinking_budget}}
&lt;/span&gt;        &lt;span class="c1"&gt;# For OpenAI/o-series: map to reasoning_effort ("low", "medium", "high")
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_reasoning_tokens&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;thinking_budget&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By decoupling the reasoning budget from global system defaults, this controller routes 75% of routine calls through the zero-token path, cutting aggregate token expenditure by more than half while preserving reasoning depth when execution errors occur.&lt;/p&gt;




&lt;h2&gt;
  
  
  Systems Engineering Trade-offs to Monitor
&lt;/h2&gt;

&lt;p&gt;When operating dynamic reasoning controllers in production, monitor three critical operational metrics:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Cost of False Negatives in the Gate
&lt;/h3&gt;

&lt;p&gt;If your complexity classifier routes a difficult multi-join SQL query to the zero-thought fast path, the first attempt will fail and trigger an escalation. While the fallback loop catches the error, you pay the latency penalty of two sequential LLM calls. If more than 15% of fast-path queries trigger escalation, relax your classifier thresholds.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Prompt Caching Interactions
&lt;/h3&gt;

&lt;p&gt;Reasoning models often generate non-deterministic thinking traces that prevent KV cache reuse across subsequent steps if the thought trace is appended to conversation histories. Keep the thinking trace isolated from user-facing conversation logs. As explored in &lt;a href="https://medium.com/@minhle_0210/five-ways-to-invalidate-your-prompt-cache-94fd845ec546" rel="noopener noreferrer"&gt;Five ways to invalidate your prompt cache&lt;/a&gt;, preserving prefix stability is vital for holding down token overhead.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Latency Budgeting for User-Facing Workflows
&lt;/h3&gt;

&lt;p&gt;Never place an unconstrained 4,096-token reasoning call in a synchronous user interaction loop (such as an autocomplete endpoint or an interactive web chat). Use dynamic budgets to restrict synchronous operations to under 512 thinking tokens, reserving deep multi-thousand token reasoning for asynchronous agent workers and background queue workers.&lt;/p&gt;

&lt;p&gt;Reasoning compute is an engineering dial, not a binary switch. Calibrating that dial dynamically per request is how you capture the benefits of test-time scaling without setting fire to your infrastructure budget.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Share your thoughts in the comments — I'd love to hear how this technology is impacting your industry.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Follow me: &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; | &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  FAQ
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; What is a dynamic reasoning budget in LLM inference?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A dynamic reasoning budget is an inference control mechanism that allocates thinking tokens based on query complexity. Low-entropy tasks like JSON formatting and entity extraction bypass reasoning loops entirely, while complex multi-step reasoning tasks receive calibrated token budgets.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; How does test-time compute affect production API costs?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Uncapped test-time compute can multiply token usage by 5x to 8x on routine tasks where reasoning provides less than a 1% accuracy improvement. Implementing fast paths and escalation gates reduces aggregate inference costs by over 50%&lt;/p&gt;




&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For detailed telemetry on how token spend compounds in agent harnesses, see &lt;a href="https://medium.com/@minhle_0210/why-your-coding-agents-bill-grows-faster-than-the-chat-2d9ecb37423d" rel="noopener noreferrer"&gt;Why your coding agent's bill grows faster than the chat&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For maintaining prefix caching stability across dynamic LLM calls, read &lt;a href="https://medium.com/@minhle_0210/five-ways-to-invalidate-your-prompt-cache-94fd845ec546" rel="noopener noreferrer"&gt;Five ways to invalidate your prompt cache&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For evaluating production cost structures across retrieval architectures, refer to &lt;a href="https://ai.plainenglish.io/building-a-graphrag-pipeline-what-it-really-costs-pt-2-13e7e3541d9f" rel="noopener noreferrer"&gt;Building a GraphRAG Pipeline — What It Really Costs, Pt 2&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/dynamic-reasoning-budgets-halving-inference-costs-on-test-time-compute-models-roqh0?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
    </item>
    <item>
      <title>The Harness is the Moat: Building a Deterministic Agent Runtime with Context Pruning</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Wed, 16 Sep 2026 12:30:04 +0000</pubDate>
      <link>https://dev.to/minh-leduc/the-harness-is-the-moat-building-a-deterministic-agent-runtime-with-context-pruning-2bg2</link>
      <guid>https://dev.to/minh-leduc/the-harness-is-the-moat-building-a-deterministic-agent-runtime-with-context-pruning-2bg2</guid>
      <description>&lt;p&gt;Every agent looks brilliant in a five-turn demo. You give it a neat prompt, wire up two mock tools, ask it to look up a customer ID and draft a confirmation email, and it flies through without missing a step. You feel like you have automated half your workday before lunch.&lt;/p&gt;

&lt;p&gt;Then you deploy it into a live staging environment with thirty tools and an actual database, and watch it fall apart by turn twenty-eight.&lt;/p&gt;

&lt;p&gt;The failure is rarely a profound reasoning lapse. The model does not suddenly forget English or lose its grasp of basic logic. What actually happens is dirtier: twenty-seven tool calls have dumped eighty kilobytes of raw JSON payloads, terminal outputs, and HTTP error traces into the message history. The original system prompt has been squeezed out of the attention spotlight. The model hallucinates a parameter that never existed in your API schema, chokes on a database timeout, and enters an infinite retry loop that burns twelve dollars of API credits before your rate limiter kicks in.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Autonomous LLM agents fail in multi-turn production environments primarily due to context poisoning and unconstrained state divergence, not underlying model reasoning deficiencies. A production-grade agent harness mitigates this by replacing raw message arrays with deterministic state machines, selective semantic context pruning, strict output schemas, and transactional checkpoint rollbacks.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The core lesson from two years of shipping production agents is simple: the model is a commodity, but the harness is the moat. If you want durability over forty turns, you have to stop treating an agent loop as a growing conversation and start treating it as a managed operating system process.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Naive Message Arrays Poison the Attention Window
&lt;/h2&gt;

&lt;p&gt;Most starter agent implementations use an append-only array. Step one runs, you append the user prompt. Step two calls a tool, you append the tool call. Step three receives tool output, you append the raw tool payload.&lt;/p&gt;

&lt;p&gt;After fifteen turns, your message list looks like a junk drawer:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Message Index&lt;/th&gt;
&lt;th&gt;Message Type&lt;/th&gt;
&lt;th&gt;Content Size&lt;/th&gt;
&lt;th&gt;Operational Value at Step 25&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;System Prompt&lt;/td&gt;
&lt;td&gt;1.8 KB&lt;/td&gt;
&lt;td&gt;Critical (invariant constraints)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;User Request&lt;/td&gt;
&lt;td&gt;0.2 KB&lt;/td&gt;
&lt;td&gt;Critical (original user objective)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2-14&lt;/td&gt;
&lt;td&gt;Step 1-6 Tool Calls&lt;/td&gt;
&lt;td&gt;8.4 KB&lt;/td&gt;
&lt;td&gt;Zero (completed intermediate actions)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;Raw SQL Output&lt;/td&gt;
&lt;td&gt;42.1 KB&lt;/td&gt;
&lt;td&gt;Zero (only 2 rows mattered)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;16-24&lt;/td&gt;
&lt;td&gt;Step 7-12 Scratchpad&lt;/td&gt;
&lt;td&gt;14.2 KB&lt;/td&gt;
&lt;td&gt;Low (noise and abandoned paths)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;Current Step&lt;/td&gt;
&lt;td&gt;0.5 KB&lt;/td&gt;
&lt;td&gt;Active working context&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;By step twenty-five, over 80% of the active context is dead weight: raw database dumps, obsolete API errors from retries, and verbose scratchpad reasoning from tasks resolved twenty minutes ago.&lt;/p&gt;

&lt;p&gt;This causes two catastrophic failures:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Recency Bias Dilution&lt;/strong&gt;: The model pays closer attention to the massive SQL dump twenty tokens away than to the safety constraint defined in the system prompt sixty thousand tokens back.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Context-Window Bloat&lt;/strong&gt;: Every single turn bills you for re-reading those eighty kilobytes. As I discussed in &lt;a href="https://medium.com/@minhle_0210/why-your-coding-agents-bill-grows-faster-than-the-chat-2d9ecb37423d" rel="noopener noreferrer"&gt;Why your coding agent's bill grows faster than the chat&lt;/a&gt;, the token bill scales quadratically with turn count on naive message lists.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  The Expedition Model: Separating Pack Weight from Base Camps
&lt;/h2&gt;

&lt;p&gt;When you climb a mountain, you do not carry every empty water bottle, wrapper, and broken crampon from camp one up to the summit. You carry essentials, leave cache points behind you, and only pack what is needed for the current pitch.&lt;/p&gt;

&lt;p&gt;In an agent runtime, this means splitting execution state into three distinct tiers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9r6jibryxgc7tcdrqxwa.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9r6jibryxgc7tcdrqxwa.webp" width="654" height="900"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Tier 1: Invariant State
&lt;/h3&gt;

&lt;p&gt;This never changes during the run. It contains your core operational constraints, approved tool signatures, and the original user instruction. In our architecture, this sits at the very beginning of the prompt to maximize KV cache reuse across turns.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tier 2: The Persistent Task Ledger
&lt;/h3&gt;

&lt;p&gt;This is a structured summary table maintained outside the conversation array. When an agent runs a database query to find a customer record, the raw result array (forty kilobytes) is parsed immediately. The ledger records: &lt;code&gt;Customer ID: 89412, Status: Active, Plan: Enterprise&lt;/code&gt;. The raw database output is dropped from the prompt entirely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tier 3: Active Working Memory
&lt;/h3&gt;

&lt;p&gt;Only the current step and the immediate previous turn retain full raw tool outputs. Once step N completes and is validated, its tool payload is compressed into a one-line fact for the ledger, and the raw payload is purged from the next inference prompt.&lt;/p&gt;




&lt;h2&gt;
  
  
  Implementing Semantic Compaction in Python
&lt;/h2&gt;

&lt;p&gt;Here is the exact pattern we use to prune tool outputs without losing state. Instead of handing raw responses back to the model, the harness forces compaction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;field&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AgentState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;original_objective&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;invariant_rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;facts_ledger&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default_factory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;active_history&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default_factory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;record_fact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Store verified operational fact in persistent ledger.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;facts_ledger&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;append_turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active_history&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="c1"&gt;# Keep only the last 4 messages in raw working memory
&lt;/span&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active_history&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active_history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active_history&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:]&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;assemble_prompt_messages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]]:&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Assembles prompt with invariant rules, ledger, and recent turns.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;ledger_lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;- &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;facts_ledger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;ledger_block&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CURRENT VERIFIED FACTS:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ledger_lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ledger_lines&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;No verified facts recorded yet.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;system_content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OBJECTIVE: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;original_objective&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;RULES:&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;- &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;invariant_rules&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ledger_block&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;system&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;system_content&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
        &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active_history&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what happens here: the prompt length remains bounded even if the agent runs for a hundred steps. The system prompt remains pinned to message index zero, the ledger grows slowly by a few dozen tokens per milestone, and the raw churn of tool calls never exceeds four messages.&lt;/p&gt;




&lt;h2&gt;
  
  
  Transactional Tool Calls and Checkpoint Rollbacks
&lt;/h2&gt;

&lt;p&gt;What happens when an agent calls a bash script that errors out, or attempts to write an invalid file path?&lt;/p&gt;

&lt;p&gt;In naive agent loops, the runtime appends the error traceback to the chat: &lt;code&gt;FileNotFoundError: [Errno 2] No such file or directory&lt;/code&gt;. The model sees the failure, tries to explain itself, apologizes, tries another broken path, and fills twenty turns arguing with its own error log.&lt;/p&gt;

&lt;p&gt;In a deterministic harness, tool executions are transactional. If a tool call fails validation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The failed action and its error log are &lt;strong&gt;not&lt;/strong&gt; appended to the primary active history.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The harness checks an internal state machine. If the failure is recoverable, it injects a concise single-line correction: &lt;code&gt;Error: path /var/data/out.csv not found. Valid directories: /var/data/raw, /var/data/processed&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the failure indicates loop thrashing (three consecutive identical failures), the harness triggers a &lt;strong&gt;checkpoint rollback&lt;/strong&gt;: it reverts the working memory to the state prior to the first failed tool call and forces a different execution branch.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As detailed in &lt;a href="https://medium.com/@minhle_0210/what-deepseeks-open-source-agent-harness-gets-right-b85f57533802" rel="noopener noreferrer"&gt;What DeepSeek's Open-Source Agent Harness Gets Right&lt;/a&gt;, treating the harness as a state machine with hard transition guards is what separates reproducible systems from probabilistic toys.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Share your thoughts in the comments — I'd love to hear how this technology is impacting your industry.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Follow me: &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; | &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Three Hard Heuristics for Production Agent Runtimes
&lt;/h2&gt;

&lt;p&gt;When architecting agent systems for multi-step tasks, enforce these operational rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Raw Payloads Never Enter Context Unfiltered&lt;/strong&gt;: If a tool returns a JSON array with twenty keys, run a schema filter or extractor first. Pass only the keys requested by the current step.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decouple Storage from Context&lt;/strong&gt;: Store files, full documents, and database rows in an external store (SQLite, Redis, or disk). Pass identifiers and excerpt ranges, not blob contents.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hard Cap on Loop Depth&lt;/strong&gt;: Every agent execution must have a hard boundary on both clock time and turn count. If an agent cannot reach a verified milestone in fifteen steps, a human escalation or deterministic abort is strictly superior to allowing twenty more hallucinated steps.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Building reliable agents does not require waiting for next year's model release. It requires building the engineering scaffolding around today's models that keeps their attention focused, their state verified, and their memory clean.&lt;/p&gt;




&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For the foundational four-pillar agent anatomy, read &lt;a href="https://medium.com/@minhle_0210/prompt-context-harness-loop-an-agents-anatomy-642db41429fb" rel="noopener noreferrer"&gt;Prompt, Context, Harness, Loop: An Agent's Anatomy&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For structuring tool constraints with rigid ontologies instead of soft prompts, see &lt;a href="https://medium.com/@minhle_0210/ai-agent-guardrails-why-ontologies-beat-prompting-d460942ddf92" rel="noopener noreferrer"&gt;AI Agent Guardrails: Why Ontologies Beat Prompting&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For measuring the exact cost mechanics of context bloat, refer to &lt;a href="https://medium.com/@minhle_0210/why-your-coding-agents-bill-grows-faster-than-the-chat-2d9ecb37423d" rel="noopener noreferrer"&gt;Why your coding agent's bill grows faster than the chat&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  FAQ
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Why do autonomous LLM agents fail after multiple turns?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Autonomous agents fail primarily due to context poisoning and state divergence. As multiple tool executions dump raw payloads and error logs into the message history, the model loses sight of initial invariant constraints and begins hallucinating parameters or entering infinite retry loops&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;What is semantic context compaction in an agent harness?&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Semantic context compaction is an architectural pattern that splits agent state into invariant system rules, a persistent factual ledger, and transient working memory. Once a tool execution completes, its raw payload is pruned and reduced to verified facts, preventing context-window bloat&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/the-harness-is-the-moat-building-a-deterministic-agent-runtime-with-context-pruning-a0rct?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
    </item>
    <item>
      <title>I Tested 3 LLMs on Vietnamese Idioms. They Got It Backwards.</title>
      <dc:creator>firefrog</dc:creator>
      <pubDate>Thu, 10 Sep 2026 12:30:03 +0000</pubDate>
      <link>https://dev.to/minh-leduc/i-tested-3-llms-on-vietnamese-idioms-they-got-it-backwards-30d4</link>
      <guid>https://dev.to/minh-leduc/i-tested-3-llms-on-vietnamese-idioms-they-got-it-backwards-30d4</guid>
      <description>&lt;p&gt;A paper from LREC 2026 presented an intriguing finding, one that fits a pattern I've seen since &lt;a href="https://ai.plainenglish.io/i-spent-my-weekend-benchmarking-vietnamese-bert-models-so-you-dont-have-to-0d19aa280736" rel="noopener noreferrer"&gt;benchmarking Vietnamese BERT models&lt;/a&gt;: state-of-the-art LLMs score under 50% accuracy on VIVID, a benchmark of 1,636 authentic Vietnamese idioms and proverbs.&lt;/p&gt;

&lt;p&gt;Even specialized Vietnamese models struggled. Few-shot prompting barely helped.&lt;/p&gt;

&lt;p&gt;I wanted to see these failure modes firsthand.&lt;/p&gt;

&lt;p&gt;Unlike other benchmarks with private answer keys, VIVID publishes ground-truth meanings on GitHub under an MIT license. I sampled 6 idioms flagged with complex traits (Sino-Vietnamese roots, archaic vocabulary, folk lore) and asked &lt;code&gt;Qwen3-8B&lt;/code&gt;, &lt;code&gt;Llama-3.1-8B-Instruct&lt;/code&gt;, and &lt;code&gt;gpt-oss-20b&lt;/code&gt; to explain each one.&lt;/p&gt;

&lt;p&gt;The result? Across 18 model-idiom explanations, not a single answer was completely correct.&lt;/p&gt;

&lt;p&gt;Worse, models delivered their explanations with total grammatical fluency and zero hedging, even when stating the exact opposite of the idiom's actual meaning.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Scorecard
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;idiom&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;SELECTED_IDIOMS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Giải thích ý nghĩa của thành ngữ/tục ngữ tiếng Việt sau bằng 1-2 câu ngắn gọn: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;idiom&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"'&lt;/span&gt;
    &lt;span class="c1"&gt;# Evaluated directly against VIVID ground truth meanings
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Idiom&lt;/th&gt;
&lt;th&gt;Actual Meaning&lt;/th&gt;
&lt;th&gt;Qwen3-8B&lt;/th&gt;
&lt;th&gt;Llama-3.1-8B&lt;/th&gt;
&lt;th&gt;gpt-oss-20b&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gội gió tắm mưa&lt;/td&gt;
&lt;td&gt;Enduring hardships; weathered by outdoor labor&lt;/td&gt;
&lt;td&gt;Vague&lt;/td&gt;
&lt;td&gt;Wrong&lt;/td&gt;
&lt;td&gt;Inverted ("Doing useless work")&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Đàn ông là nhà, đàn bà là cửa&lt;/td&gt;
&lt;td&gt;The husband as foundation/pillar of the family&lt;/td&gt;
&lt;td&gt;No answer&lt;/td&gt;
&lt;td&gt;Skewed&lt;/td&gt;
&lt;td&gt;Plausible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Võng tía lọng đào&lt;/td&gt;
&lt;td&gt;Glory and high aristocratic status&lt;/td&gt;
&lt;td&gt;No answer&lt;/td&gt;
&lt;td&gt;Hallucinated&lt;/td&gt;
&lt;td&gt;Hallucinated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Phúc đức khán tử tôn&lt;/td&gt;
&lt;td&gt;Ancestral virtue is reflected in descendants&lt;/td&gt;
&lt;td&gt;Partial&lt;/td&gt;
&lt;td&gt;Hallucinated ("Kings")&lt;/td&gt;
&lt;td&gt;Partial&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tiếng bấc tiếng chì&lt;/td&gt;
&lt;td&gt;Alternating gentle and harsh words; nagging&lt;/td&gt;
&lt;td&gt;Wrong&lt;/td&gt;
&lt;td&gt;Wrong&lt;/td&gt;
&lt;td&gt;Inverted ("Pleasant sound")&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Năng may hơn dày giẻ&lt;/td&gt;
&lt;td&gt;Honest diligence beats dishonest gains&lt;/td&gt;
&lt;td&gt;Partial&lt;/td&gt;
&lt;td&gt;Wrong&lt;/td&gt;
&lt;td&gt;Inverted ("Luck beats effort")&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Out of 18 responses: 0 fully correct, 6 partial, 2 empty completions, and 10 completely incorrect. Three answers directly inverted the moral lesson.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Two Most Striking Failures
&lt;/h2&gt;

&lt;p&gt;Two responses stood out for their confident fabrication:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. "Võng tía lọng đào"
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Actual meaning:&lt;/strong&gt; A purple hammock and peach-colored parasol, representing aristocratic honor and prestige.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Llama-3.1's answer:&lt;/strong&gt; &lt;em&gt;"People talking about something without reason, just because they want to talk."&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is fluent, grammatically clean Vietnamese with zero connection to reality.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. "Năng may hơn dày giẻ"
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Actual meaning:&lt;/strong&gt; A metaphor comparing a hardworking tailor to one who cheats customers by padding fabric with rags. The moral: honest diligence brings sustainable success over deceptive shortcuts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;gpt-oss-20b's answer:&lt;/strong&gt; &lt;em&gt;"Luck determines success more than effort; without luck, effort brings disappointing results."&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model inverted the entire ethical lesson of the proverb, delivering it with the authoritative tone of a teacher.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Confident Errors Are Dangerous
&lt;/h2&gt;

&lt;p&gt;An AI that responds with &lt;em&gt;"I don't know"&lt;/em&gt; is safe.&lt;/p&gt;

&lt;p&gt;An AI that confidently explains a cultural idiom backwards is a liability.&lt;/p&gt;

&lt;p&gt;In education, customer support, or translation tools, end users who lack deep cultural background cannot distinguish a hallucinated explanation from a correct one.&lt;/p&gt;

&lt;p&gt;The VIVID paper categorizes these failures into four main drivers — the same category of gap I ran into &lt;a href="https://ai.plainenglish.io/weekend-nlp-fine-tuning-transformers-for-language-detection-with-huggingface-4041ac9ca20e" rel="noopener noreferrer"&gt;fine-tuning transformers for language detection&lt;/a&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Literal over-interpretation:&lt;/strong&gt; Taking figurative allegories at face value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Archaic vocabulary gaps:&lt;/strong&gt; Failing on Sino-Vietnamese roots.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cultural disconnection:&lt;/strong&gt; Lacking grounding in Vietnamese folk traditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pragmatic flattening:&lt;/strong&gt; Defaulting to generic modern tropes (like "luck vs. effort") when confused.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Experiment
&lt;/h2&gt;

&lt;p&gt;Here's the actual run, step by step. The complete script is in the appendix at the end of this post.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Load the dataset and index it by idiom text&lt;/strong&gt; so each row's ground truth is a dict lookup away:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load_rows&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DATASET_PATH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8-sig&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DictReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Idiom_Proverb&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Call the model, keeping the reasoning trace alongside the answer&lt;/strong&gt; — same reason as the V-Bench script: a &lt;code&gt;None&lt;/code&gt; answer needs to be distinguishable from a token-exhausted one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;call_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;ROUTER_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;HF_TOKEN&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Content-Type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;model&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;messages&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
              &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;max_tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;temperature&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;choices&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;message&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;reasoning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;reasoning_content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;reasoning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;finish_reason&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;finish_reason&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. For each of the 6 idioms, pull its taxonomy tags and theme, then ask all 3 models to explain it:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;idiom&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;SELECTED_IDIOMS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;idiom&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;taxonomy_flags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;TAXONOMY_NAMES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                       &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Linguistic_Complexity_Taxonomy_&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1.0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;THEME_NAMES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Semantic_Theme&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;unknown&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;idiom&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;idiom&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ground_truth_meaning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Meaning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;taxonomy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;taxonomy_flags&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;theme&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;models&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Giải thích ý nghĩa của thành ngữ/tục ngữ tiếng Việt sau bằng 1-2 câu ngắn gọn: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;idiom&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"'&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;MODELS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;call_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;models&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;models&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)[:&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;On the challenging tail of Vietnamese idioms, current open LLMs produced 0/18 fully correct explanations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inverted meanings and hallucinations were delivered with complete fluency and no uncertainty markers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;VIVID provides an open, reproducible dataset for testing cultural reasoning.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Never rely on an LLM's confidence as a proxy for cultural accuracy.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/ReML-AI/VIVID" rel="noopener noreferrer"&gt;VIVID dataset repository&lt;/a&gt; — the idiom benchmark's GitHub repo (MIT-licensed ground truth).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://raw.githubusercontent.com/ReML-AI/VIVID/main/dataset/VIVID_Dataset.csv" rel="noopener noreferrer"&gt;VIVID_Dataset.csv&lt;/a&gt; — the raw ground-truth file used for scoring.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://huggingface.co/Qwen/Qwen3-8B" rel="noopener noreferrer"&gt;Qwen3-8B&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct" rel="noopener noreferrer"&gt;Llama-3.1-8B-Instruct&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;What Vietnamese idioms have you seen AI models struggle with? Share your examples in the comments.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Follow my work:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/minhle007/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://github.com/MinLee0210" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Appendix: Full Script
&lt;/h2&gt;

&lt;p&gt;For anyone who wants the complete, runnable file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;#!/usr/bin/env python3
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Ask 3 open-weight LLMs to explain real Vietnamese idioms from the VIVID benchmark
dataset (github.com/ReML-AI/VIVID, MIT licensed), and compare their explanations
against the dataset&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s own ground-truth meaning.

Unlike the V-Bench post, VIVID&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s public dataset DOES ship with ground truth (the
`Meaning` column), so this is a real correctness check, not just a qualitative read.
We do NOT reproduce VIVID&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s own LLM-as-a-judge aspect-based scoring methodology
(Cohen&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s kappa 0.792 against human judges) — that&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s a more elaborate rubric than
this script implements. This is a simpler, direct &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;does the model&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s explanation
match the dataset&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s meaning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; comparison, judged by this session reading Vietnamese,
stated as such rather than presented as a reproduction of the paper&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s own scores.
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;DATASET_PATH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;../vivid-idioms/scratch/VIVID_Dataset.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;OUT_PATH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;..
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;💡 TL;DR &amp;amp; Key Takeaways:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
**TL;DR**&lt;br&gt;&lt;br&gt;
State‑of‑the‑art LLMs, even Vietnamese‑specialized ones, score below 50 % on the VIVID benchmark of 1,636 authentic Vietnamese idioms and fail completely on a hand‑picked set of six complex idioms. The models produce fluently written, confident explanations that are frequently wrong or even opposite to the true meanings, exposing a serious gap in idiom comprehension.  &lt;/p&gt;

&lt;p&gt;- VIVID provides open‑source ground‑truth meanings (MIT‑licensed) for all idioms, enabling transparent evaluation.&lt;br&gt;&lt;br&gt;
- In a test of Qwen3‑8B, Llama‑3.1‑8B‑Instruct, and gpt‑oss‑20b on 6 idioms (18 responses), **0** explanations were fully correct.&lt;br&gt;&lt;br&gt;
- Responses were grammatically perfect and unqualified, yet often hallucinated, inverted, or entirely unrelated, highlighting the models’ inability to handle culturally nuanced language.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;vivid&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;idioms&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;scratch&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;vivid_qualitative_results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;)

MODELS = [
    &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Qwen&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;Qwen3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="sa"&gt;B&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
    &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;meta&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;llama&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;Llama&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;3.1&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Instruct&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
    &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;openai&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;gpt&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;oss&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="sa"&gt;b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
]

# Idiom text -&amp;gt; which taxonomy column made it interesting, for narrative labeling
SELECTED_IDIOMS = [
    &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Gội&lt;/span&gt; &lt;span class="n"&gt;gió&lt;/span&gt; &lt;span class="n"&gt;tắm&lt;/span&gt; &lt;span class="n"&gt;mưa&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
    &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Đàn&lt;/span&gt; &lt;span class="n"&gt;ông&lt;/span&gt; &lt;span class="n"&gt;là&lt;/span&gt; &lt;span class="n"&gt;nhà&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;đàn&lt;/span&gt; &lt;span class="n"&gt;bà&lt;/span&gt; &lt;span class="n"&gt;là&lt;/span&gt; &lt;span class="n"&gt;cửa&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
    &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Võng&lt;/span&gt; &lt;span class="n"&gt;tía&lt;/span&gt; &lt;span class="n"&gt;lọng&lt;/span&gt; &lt;span class="n"&gt;đào&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
    &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Phúc&lt;/span&gt; &lt;span class="n"&gt;đức&lt;/span&gt; &lt;span class="n"&gt;khán&lt;/span&gt; &lt;span class="n"&gt;tử&lt;/span&gt; &lt;span class="n"&gt;tôn&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
    &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Tiếng&lt;/span&gt; &lt;span class="n"&gt;bấc&lt;/span&gt; &lt;span class="n"&gt;tiếng&lt;/span&gt; &lt;span class="n"&gt;chì&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
    &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Năng&lt;/span&gt; &lt;span class="n"&gt;may&lt;/span&gt; &lt;span class="n"&gt;hơn&lt;/span&gt; &lt;span class="n"&gt;dày&lt;/span&gt; &lt;span class="n"&gt;giẻ&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;,
]

HF_TOKEN = os.environ[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;HF_TOKEN&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;]
ROUTER_URL = &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;huggingface&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;co&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;completions&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;

TAXONOMY_NAMES = [&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;literal&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;sino_vietnamese&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;uncommon_vocab&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;folk_knowledge&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;pragmatic_nuance&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;]
THEME_NAMES = {1: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Love&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, 2: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Virtues&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, 3: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Criticism&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, 4: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Work&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;nature&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, 5: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Society&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, 6: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Life&lt;/span&gt; &lt;span class="n"&gt;Lessons&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, 7: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Others&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;}

def load_rows():
    rows = {}
    with open(DATASET_PATH, encoding=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;utf&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sig&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;) as f:
        r = csv.DictReader(f)
        for row in r:
            rows[row[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Idiom_Proverb&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;].strip()] = row
    return rows

def call_model(model, prompt):
    resp = requests.post(
        ROUTER_URL,
        headers={&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Bearer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;HF_TOKEN&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;},
        json={&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: model, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: [{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: prompt}],
              &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;max_tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: 600, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: 0.2},
        timeout=120,
    )
    resp.raise_for_status()
    data = resp.json()
    choice = data[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;][0]
    msg = choice[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;]
    return {
        &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: msg.get(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;),
        &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;reasoning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: msg.get(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;reasoning_content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;) or msg.get(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;reasoning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;),
        &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;finish_reason&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: choice.get(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;finish_reason&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;),
    }

def run():
    rows = load_rows()
    results = []
    for idiom in SELECTED_IDIOMS:
        row = rows.get(idiom)
        if row is None:
            print(f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;skip&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;{idiom}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;dataset&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;)
            continue
        taxonomy_flags = [TAXONOMY_NAMES[i] for i in range(5)
                           if row.get(f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Linguistic_Complexity_Taxonomy_&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;, &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;) == &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;]
        theme = THEME_NAMES.get(int(float(row[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Semantic_Theme&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;])), &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;unknown&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;)
        entry = {
            &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;idiom&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: idiom,
            &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;ground_truth_meaning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: row[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;Meaning&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;].strip(),
            &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;taxonomy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: taxonomy_flags,
            &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;theme&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: theme,
            &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: {},
        }
        prompt = (
            f&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Giải thích ý nghĩa của thành ngữ/tục ngữ tiếng Việt sau bằng 1-2 câu ngắn gọn: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;idiom&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"'&lt;/span&gt;&lt;span class="s"&gt;
        )
        for model in MODELS:
            t0 = time.time()
            try:
                out = call_model(model, prompt)
                out[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;latency_s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;] = round(time.time() - t0, 2)
                entry[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;][model] = out
                print(f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;idiom&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;{idiom}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;finish&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;finish_reason&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;)
            except Exception as e:  # noqa: BLE001
                entry[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;][model] = {&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;: str(e)[:300]}
                print(f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;FAIL&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;idiom&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;{idiom}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;)
        results.append(entry)
    OUT_PATH.write_text(json.dumps(results, ensure_ascii=False, indent=2))
    print(f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;\&lt;span class="n"&gt;nWrote&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;OUT_PATH&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;)

if __name__ == &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="n"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;:
    run()
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Published via &lt;a href="https://zyvop.com/i-tested-3-llms-on-vietnamese-idioms-they-got-it-backwards-rytws?utm_source=devto&amp;amp;utm_medium=crosspost&amp;amp;utm_campaign=syndication" rel="noopener noreferrer"&gt;ZyVOP&lt;/a&gt; — Write once in Markdown, auto-backup to GitHub, and syndicate to Dev.to, Medium &amp;amp; Hashnode in 1 click.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
