<?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: yu matt</title>
    <description>The latest articles on DEV Community by yu matt (@yu_matt_fba71e5a49471bd29).</description>
    <link>https://dev.to/yu_matt_fba71e5a49471bd29</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%2F4178310%2F7a7a6ad4-77c2-41fb-82e0-fd4988b6cb7a.png</url>
      <title>DEV Community: yu matt</title>
      <link>https://dev.to/yu_matt_fba71e5a49471bd29</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yu_matt_fba71e5a49471bd29"/>
    <language>en</language>
    <item>
      <title>Let the LLM Talk, Let a Script Do the Math: A Three-Part Pattern for Decision Agents</title>
      <dc:creator>yu matt</dc:creator>
      <pubDate>Mon, 12 Oct 2026 04:42:37 +0000</pubDate>
      <link>https://dev.to/yu_matt_fba71e5a49471bd29/let-the-llm-talk-let-a-script-do-the-math-a-three-part-pattern-for-decision-agents-l5i</link>
      <guid>https://dev.to/yu_matt_fba71e5a49471bd29/let-the-llm-talk-let-a-script-do-the-math-a-three-part-pattern-for-decision-agents-l5i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;The code is open source (MIT). &lt;strong&gt;The repo link is at the end of this post&lt;/strong&gt; — a star would mean a lot. ⭐&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A quick test
&lt;/h2&gt;

&lt;p&gt;You have two McDonald's coupons and can use only one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spend 40, get 10 off&lt;/li&gt;
&lt;li&gt;12% off any burger&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You order a ¥25 burger:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Threshold coupon: you'd have to add ¥15 more → pay ¥30&lt;/li&gt;
&lt;li&gt;Percentage coupon: 25 × 0.88 = ¥22 → &lt;strong&gt;the percentage coupon wins&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now make that burger ¥40:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Threshold coupon: pay ¥30 → &lt;strong&gt;the threshold coupon wins&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Percentage coupon: pay ¥35.2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Which coupon is cheaper depends entirely on what's in the order.&lt;/strong&gt; There is no general answer.&lt;/p&gt;

&lt;p&gt;That's two coupons and one item. A real order is three coupons, twenty items, plus constraints like "two people, under ¥50, keep it under 1100 kcal, at least 35g protein." The number of combinations that satisfy all of that runs into the thousands.&lt;/p&gt;

&lt;p&gt;Ask an LLM to solve that and you get three predictable outcomes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Slow&lt;/strong&gt; — thousands of multiply-adds, generated token by token&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expensive&lt;/strong&gt; — every step burns tokens&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wrong&lt;/strong&gt; — LLM arithmetic, as anyone who's tried it knows&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So this project started from one rule:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The LLM handles understanding and expression. A script handles computation and determinism.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User speaks plainly
   │  "two people, under ¥50, nothing too greasy"
   ▼
LLM (WorkBuddy) parses intent ──► hard constraints
   │  max_payable=45, max_calories=1100, min_protein=35
   ▼
McDonald's MCP fetches real data ──► store menu / nutrition / coupons
   │
   ▼
optimize_meal.py (local, no network) ──► enumerate + best-coupon match
   │
   ▼
LLM turns results back into plain language ──► three plans
&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;Role&lt;/th&gt;
&lt;th&gt;Owns&lt;/th&gt;
&lt;th&gt;Doesn't own&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;LLM&lt;/td&gt;
&lt;td&gt;Interpreting "nothing too greasy"; narrating results&lt;/td&gt;
&lt;td&gt;Money math, calorie math, remembering menus&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MCP&lt;/td&gt;
&lt;td&gt;Structured, trustworthy data&lt;/td&gt;
&lt;td&gt;Decisions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Local script&lt;/td&gt;
&lt;td&gt;Enumeration, filtering, coupon matching, ranking&lt;/td&gt;
&lt;td&gt;Natural language&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The payoff is direct: the script runs in milliseconds, is reproducible, costs zero tokens, and never gets the money wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not let the model do the math
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Enumeration is arithmetic, not language.&lt;/strong&gt; It's a Cartesian product plus constraint filtering: 1–2 mains + 0–1 sides + 0–1 drinks + 0–1 desserts. Deterministic, unambiguous, no "understanding" required. Using a probabilistic model for deterministic computation is the wrong tool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Coupon matching has a constraint models miss: one coupon per order.&lt;/strong&gt; So you can't just pick the biggest face value. You have to compute &lt;em&gt;what this specific order actually saves&lt;/em&gt; — does the threshold clear, what's the discounted total, does the category restriction apply. Only enumeration gets it right.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. There are three different ranking objectives.&lt;/strong&gt; Cheapest (ascending total), healthiest (ascending deviation from targets), best value (descending protein per yuan). All three run over the same candidate set. That's a script's job.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the LLM is still good for
&lt;/h2&gt;

&lt;p&gt;The other half of the split: shrink the model's workload without shrinking its value.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Translate vague language into hard constraints.&lt;/strong&gt; "Two people" → raise the protein target. "Nothing too greasy" → maybe a calorie cap, maybe exclude fried categories. "Under ¥50" → &lt;code&gt;max_payable = 45&lt;/code&gt;, leaving headroom for delivery and packaging fees the client can't see. Scripts can't do this mapping; models do it well.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Narrate structured output.&lt;/strong&gt; The script emits JSON. The model explains &lt;em&gt;why&lt;/em&gt; this plan over that one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The boundary is clean: the model translates and narrates. It does not compute and does not remember.&lt;/p&gt;

&lt;h2&gt;
  
  
  A cautionary note on data
&lt;/h2&gt;

&lt;p&gt;Hard rule in this project: &lt;strong&gt;every number comes from MCP, nothing is hardcoded.&lt;/strong&gt; An LLM's memory of a fast-food menu is outdated, incomplete, and occasionally invented. More importantly:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The same chain's different locations carry different items and different coupons.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So the flow must be: &lt;strong&gt;confirm the store first, then fetch menu and coupons.&lt;/strong&gt; During testing I nearly picked a store by keyword search — the results were all inside train stations. Had I chosen one for the user, they'd have been nowhere near it and the order would have been wasted. That became the hardest rule in the skill: &lt;strong&gt;the store must be confirmed by the human, never guessed.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Two MCP setup gotchas (WorkBuddy-specific)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;code&gt;type&lt;/code&gt; casing.&lt;/strong&gt; McDonald's docs show lowercase:&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="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;"streamablehttp"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WorkBuddy only accepts camelCase:&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="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;"streamableHttp"&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;works&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;"streamablehttp"&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;not&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;recognized&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I reverse-engineered this by reading WorkBuddy's built-in connector list — every built-in uses camelCase. When docs and client disagree, compare against the built-ins.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Config path.&lt;/strong&gt; Many tutorials say &lt;code&gt;~/.workbuddy/mcp.json&lt;/code&gt;. The one that actually takes effect is &lt;code&gt;~/.workbuddy-ai/mcp.json&lt;/code&gt;. The &lt;code&gt;~/.workbuddy/&lt;/code&gt; directory does exist — it just holds &lt;code&gt;device-id&lt;/code&gt; and &lt;code&gt;logs&lt;/code&gt;, not config.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Configuring isn't enabling.&lt;/strong&gt; After writing the config you still have to enable the server in the custom-connector panel, or the client won't load it.&lt;/p&gt;

&lt;p&gt;Verify with a raw JSON-RPC call rather than trusting the UI — a &lt;code&gt;tools/list&lt;/code&gt; round trip returned 35 tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  One more step people skip: server-side repricing
&lt;/h2&gt;

&lt;p&gt;The local engine's total is an &lt;em&gt;estimate&lt;/em&gt;. Delivery fees, packaging, and store-level promotions only exist server-side. Before showing any plan, send its item codes through the pricing tool and reconcile — &lt;strong&gt;server wins when they disagree.&lt;/strong&gt; Skip this and users find out your math doesn't match what they actually paid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;The valuable part of this project isn't the cheapest combo. It's the division of labor:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;LLM for understanding and expression, script for computation and determinism, MCP for trustworthy data.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you're building anything decision-shaped — meal picking, product selection, scheduling, price comparison — this three-part structure transfers directly.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Repo&lt;/strong&gt;: &lt;a href="https://github.com/minxin88/mcd-meal-optimizer" rel="noopener noreferrer"&gt;https://github.com/minxin88/mcd-meal-optimizer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;MIT licensed, pure Python standard library, zero dependencies. Run &lt;code&gt;python scripts/optimize_meal.py --demo&lt;/code&gt; to exercise the enumeration and coupon-matching flow with no token required — that runs on the bundled offline sample data, not a real store's prices.&lt;/p&gt;

&lt;p&gt;Scope: no ordering, no coupon claiming, no order cancellation, and store selection always requires human confirmation. Personal, non-commercial use only.&lt;/p&gt;

</description>
      <category>agents</category>
      <category>ai</category>
      <category>architecture</category>
      <category>llm</category>
    </item>
  </channel>
</rss>
