How I Track Claude, Codex, and Gemini Quotas from One Script

Claude Code status line showing token consumption percentages for Claude, Codex, and Gemini

(If you’re trying to decide which model to switch to when one runs dry, I benchmarked 15 models on 38 real coding tasks with full cost-per-task breakdowns.)

Claude Code status line showing token consumption percentages for Claude, Codex, and Gemini

I run three AI coding CLIs daily. None of them tell me whether I’m about to hit a rate limit. I periodically get locked out mid-task and spend ten minutes figuring out which tool ran out, when it resets, and whether I should switch models or wait.

I built a script that collects quota data from all three, writes it to a single JSON file, and runs on an hourly cron. The whole thing feeds a status line in Claude Code:

Session: ███░░░⏐░░░░░░░░░░░░░ 10% (3h12m left)
Weekly:  ████████░░⏐░░░░░░░░░ 44% (Thu Mar 05 8pm PT)

The filled blocks (█) show usage consumed. The marker (⏐) shows where you are in the time window. If the blocks outpace the marker, you’re burning budget faster than time is passing.

How do you query Claude Code’s rate limit programmatically?

Claude Code authenticates via OAuth, with credentials stored at ~/.claude/.credentials.json. What I couldn’t find in any official documentation is that api.anthropic.com/api/oauth/usage returns the data you need: utilization percentages and reset timestamps for both the 5-hour rolling window and the 7-day weekly allocation. It’s used internally by Claude Code’s HUD, but it doesn’t appear in Anthropic’s public API reference.

TOKEN=$(jq -r '.claudeAiOauth.accessToken // empty' "$HOME/.claude/.credentials.json")

curl -s --max-time 10 
  -H "Authorization: Bearer $TOKEN" 
  -H "anthropic-beta: oauth-2025-04-20" 
  https://api.anthropic.com/api/oauth/usage

The response:

{
  "five_hour": { "utilization": 0.42, "resets_at": "2026-02-28T17:00:00Z" },
  "seven_day": { "utilization": 0.61, "resets_at": "2026-03-07T08:00:00Z" },
  "seven_day_sonnet": { "utilization": 0.35, "resets_at": "2026-03-07T08:00:00Z" }
}

I found this by searching Anthropic’s GitHub issues for “usage” and “quota,” then trying endpoints until one worked. The catch is that anthropic-beta: oauth-2025-04-20 header. Without it, you get a 401. The date in the version string suggests this header has been updated before, so when it changes again, the collector breaks silently.

Claude Code uses a 5-hour rolling session window, not a 24-hour one, and the weekly limit resets Thursday at 8pm PT, not midnight UTC. I only discovered both by watching the numbers change over a week of collection. The docs don’t mention either detail.

I’ve been hitting this endpoint hourly since February with zero failures. But “undocumented beta endpoint” is not a phrase that inspires long-term confidence.

How do you track Gemini CLI usage without an API?

Gemini CLI has a /stats command that works interactively, but non-interactively it completes silently with no output (the stats render through Ink, a React-based terminal renderer, which doesn’t survive piping or capture). GitHub issue #19067 has a user asking the same question I had. The maintainer response: “there’s no way within Gemini CLI to see your daily quota.”

The workaround: Gemini stores session files at ~/.gemini/tmp/_/chats/session-YYYY-MM-DD_.json. Each file is one session. The free tier allows 1,000 requests per day, resetting daily. There’s no official way to query how many you’ve used. You count your own files. I verified the session counts against Google’s AI Studio usage dashboard to make sure the file-based approach was tracking correctly.

A note on what this actually measures: the free tier limit is requests, but what we’re counting is session files and token consumption. Session files don’t map 1:1 to API requests (a single session can contain multiple turns), so the session count is a lower bound, not an exact quota meter. For my usage patterns, the counts track closely enough to be useful as a warning signal, but they won’t catch you at exactly request 999.

Counting files only tells you session counts. For actual consumption data, you parse the JSON. Each session file has a messages array where every message includes a tokens.total field:

files = glob.glob(os.path.join(base, '*/chats/session-*.json'))
for f in files:
    fname = os.path.basename(f)
    file_date = fname[8:18]  # YYYY-MM-DD from session-YYYY-MM-DDTHH-MM-*.json
    with open(f) as fh:
        data = json.load(fh)
    file_tokens = sum(
        m.get('tokens', {}).get('total', 0)
        for m in data.get('messages', [])
    )
    if file_date in week:
        week[file_date]['sessions'] += 1
        week[file_date]['tokens'] += file_tokens

The output includes today’s session and token counts, lifetime totals, and per-day breakdowns for the past week. All from flat files that were never intended to be an API. If Google changes the session file schema or directory structure, there’s no migration path. You find out when the numbers stop updating.

How does Codex CLI expose rate limits?

Codex has an interactive /status command that shows rate limits in a TUI modal. The same problem as Gemini: it only works inside the REPL (the interactive read-eval-print loop). codex /status exits immediately with nothing.

My first approach felt like performing surgery with oven mitts: launch Codex inside a tmux session, send /status as keystrokes, wait for the modal to render, press Escape to dismiss it, send /help to push the status into the scroll buffer, capture 300 lines of scroll history, grep for “% left.” It required sleep statements between every step and never worked reliably.

Then I found codex app-server.

Codex ships with an app-server subcommand that speaks JSON-RPC over stdin/stdout. OpenAI has documentation for it, though I only found it after discovering the feature in the source code. The account/rateLimits/read method isn’t prominently featured, but it works. You spawn the process, send an initialize handshake, then call it. The 500ms delay between handshake and request is necessary because shorter values produce empty responses before the connection is ready.

const proc = spawn('codex', ['app-server'], { stdio: ['pipe','pipe','ignore'] });
const rl = readline.createInterface({ input: proc.stdout });

const send = (m) => proc.stdin.write(JSON.stringify(m) + 'n');

// Handshake
send({
  method: 'initialize', id: 0,
  params: { clientInfo: { name: 'quota-collector', title: 'Quota Collector', version: '1.0' } }
});

// Request rate limits after handshake completes
setTimeout(() => send({ method: 'account/rateLimits/read', id: 1, params: {} }), 500);

The response comes back with rateLimits.primary (five-hour window) and rateLimits.secondary (weekly), each with usedPercent and resetsAt. No scroll buffer archaeology required.

Codex also maintains a SQLite database at ~/.codex/state_5.sqlite (the _5 is a schema version, so this path may change in future releases) with a threads table that tracks every session:

WITH days AS (
    SELECT date('now', '-' || n || ' days') AS day
    FROM (SELECT 0 AS n UNION SELECT 1 UNION SELECT 2
          UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6)
)
SELECT d.day, COUNT(t.id) AS sessions, COALESCE(SUM(t.tokens_used),0) AS tokens
FROM days d
LEFT JOIN threads t ON date(t.created_at, 'unixepoch') = d.day
GROUP BY d.day ORDER BY d.day;

The collector: one cron, one JSON

claude_json=$(collect_claude)
codex_json=$(collect_codex)
gemini_json=$(collect_gemini)

ts=$(date -u +%Y-%m-%dT%H:%M:%SZ)

jq -n 
    --argjson claude "$claude_json" 
    --argjson codex "$codex_json" 
    --argjson gemini "$gemini_json" 
    --arg ts "$ts" 
    '{collected_at: $ts, claude: $claude, codex: $codex, gemini: $gemini}' 
    > "$OUTFILE"

After writing latest.json, the script appends a compacted copy to a daily JSONL file for historical tracking. One line per collection, roughly 15 lines per day, about 2KB. Want to know how fast you burned through your five-hour window last Tuesday? jq -r '.claude.five_hour.utilization' quota/history/2026-03-11.jsonl and watch the numbers climb line by line.

How I display it

A separate status line script reads latest.json and renders progress bars on every Claude Code interaction. Green below 70%, amber at 70-90%, red above 90%. The time marker (⏐) gives you an instant burn-rate signal without reading numbers.

The same JSON feeds a dashboard with budget bars and threshold alerts. Both are reading a flat file, no live API calls during rendering. The hourly cron does the expensive work once, everything downstream reads the result.

Why not just use ccusage?

ccusage reads Claude Code and Codex JSONL logs, giving you per-model cost breakdowns with date filtering. It’s better than the collector at USD cost tracking and historical queries. If that’s what you need, use it.

I built my own because the collector does three things ccusage doesn’t:

  • It tracks Gemini (1,000 req/day free tier, no JSONL logs to read, only session file parsing).
  • It acts on the data (configurable spend alerts, pipeline kill switches when costs spike).
  • It burns unused Codex budget on maintenance tasks when weekly utilization drops below 60%.

It also doesn’t require an additional MCP server. It reads a flat JSON file.

The usage data exists somewhere in every AI CLI. It might be an undocumented endpoint, a pile of session files, or a JSON-RPC server. An hourly cron that normalizes it all into one JSON file is about 250 lines of bash, Python, and JavaScript. An afternoon of reverse engineering, once you know where to look.

First-call checklist before trying a new LLM gateway

I have been using the same small checklist whenever I try a new OpenAI-compatible LLM gateway. It catches most integration failures before I move any real workload.

  1. Create one API key and keep it scoped to a test project.
  2. Run one tiny chat completion with the cheapest model first.
  3. Check whether streaming chunks match the client you already use.
  4. Test one tool-call shape if your app depends on tools or agents.
  5. Open the usage logs and confirm model name, tokens, timestamp and error mapping are visible.
  6. Only then test fallback, higher QPS, or paid traffic.

For Chinese models like Qwen, DeepSeek, GLM and Kimi, the first blocker is often not model quality. It is account setup, payment, model naming and whether the gateway gives enough request logs to debug the first call.

I am collecting small first-call failure cases while building AnLink API notes. If you are testing this path, the beta entry is here: https://anlinkai.com/?ref=r_d0dbd2241021

From Burnout to Building: One Indie Dev’s Story Behind Mozart

“I’m sick of working for other people’s dreams.”

That’s the sentence that started it all. Not a rational decision, not a business plan, not a flash of genius, just exhaustion turning into clarity. One evening, in Montpellier, after weeks of chasing freelance gigs and hitting walls.

A few days later, I started building Mozart. This blog tells what comes next.

But first, let me rewind a bit.

I’m a self-taught developer. I discovered code at 14, and I learned everything on my own, through documentation, failed projects, and YouTube tutorials until 5 in the morning. For the last two years, I’ve done a few freelance gigs for small companies while travelling: Vietnam, Turkey, Portugal, Morocco, Thailand. Between stopovers, I tried to launch my own apps. None of them took off. I ended up dropping code for a while, I have this annoying tendency to overdose on what I love. But the passion always comes back.

When I picked code back up after a few months without a computer, it hit me hard. LLMs had made a massive leap.

I realised that the way we code was changing at a deep level. The craft of code is mutating: developers aren’t just the ones writing each line anymore, they’re becoming the ones who orchestrate, direct, and arbitrate.

A code manager.

Arthur Mensch, co-founder of Mistral, made the point recently in front of the French National Assembly: the bottleneck is no longer code production. It has shifted toward design and coordination. The more agents you stack, the more productivity you gain, but that productivity plateaus quickly if you don’t know how to pilot them.

That’s exactly the problem I want to solve.

The dormant dream

Around 2014, I discovered Y Combinator. At the time, I wasn’t a developer yet. I had a civil engineering technician degree and worked in a lab, mostly on the road inspecting sports facilities. In the car, I listened to podcasts by Oussama Ammar (co-founder of The Family). A controversial figure, you love him or you don’t, but he infused YC culture into France and inspired my generation. In parallel, I was reading Paul Graham’s essays. All of that shaped how I saw startups, but only as a spectator. Watching from the sidelines, not daring to get my hands dirty.

Later, when I got seriously into code, the urge to start my own company never left me. But I always had an excellent excuse to put it off: “I’m self-taught”, “I lack experience”, “I still need to earn my stripes”, “It’s not the right time”.

In hindsight, I know what was happening. There’s never a right time. The real blocker wasn’t my level. It was that I hadn’t yet found the idea. The one that makes you say: this is it, this is now, I’m not letting it pass.

Crossing the desert

Finding your path is a chaotic process. At least it was for me. I regularly cross deserts, long stretches where nothing sticks, where doubt sets in. And then, every so often, I stumble onto an oasis. That’s enough to get me moving again.

Before Mozart, I launched several projects. Not all of them finished, not all of them I’d own up to:

The lesson fits in one word: distribution.

In The Hitchhiker’s Guide to the Galaxy, Douglas Adams tells the story of a civilisation that has a brilliant idea: ship off everyone deemed “useless”, salespeople, marketers, consultants, hairdressers… At first, everything’s great. Fewer meetings. Less posturing. The planet feels better.

Then comes the boring detail: without those people, civilisation collapses. Moral of the story: never underestimate distribution… or hairdressers lol.

You can build without distributing for a while. But not forever.

The genesis: memory first

The first serious intuition wasn’t actually about Mozart. It was a thought about memory.

I was sick of having to repeat the same context over and over.

From one prompt to the next, memory is very limited. From one LLM to another, it disappears entirely. You explain your project to ChatGPT, then you start over with Claude, then with a third tool.

Even when memory exists, it tends to stay opaque, frustrating, and hard to control.

The starting idea: build a universal memory layer, pluggable into any model. A space that belongs to you, that stores your notes, your code, your projects, and exposes itself to the LLMs of your choice.

I quickly realised the topic was far more complex than it looked: embeddings, entity graphs, retrieval… every path opened up new problems. And if people much more advanced than me are already working on it without a clear solution emerging, it’s probably because it isn’t that simple.

The idea didn’t disappear: it became the first pillar of Mozart.

Then one evening, the second click. If multiple LLMs can share a common context, why stick to a single agent?

Every AI giant is pushing its own closed interface. ChatGPT has one, Claude has one. But none of them is designed to make several agents work together, from different models, on interconnected tasks, in parallel.

Mozart was born out of that void. A cockpit: you launch your agents, they each move forward on their own work, and you keep your hand on the whole thing.

First step: look at the competition. It exists, it’s well-funded, further along. The first instinct is to get discouraged. But an empty market would be far more worrying.

Competitors prove one thing: the problem is real. Serious teams believe in it, investors too. But no one seems to have definitively cracked it yet.

The window is probably still open.

What is Mozart?

Here are the three founding pillars:

  • For developers (at first), Mozart is designed for technical profiles who work with files and code, and who like to configure their own tools.
  • Local-first & Markdown, your files live on your machine, readable by you, ideal for LLMs, easily synced via GitHub. Ultra-low latency and more privacy.
  • Multi-agent & extensible, orchestration will be the heart of the product. Coordinating agents, distributing tasks, aggregating results without depending on a single AI vendor. This logic will eventually extend beyond code (admin, ops, business).

Where things stand

Mozart isn’t public yet. I’m building the MVP. Or rather an “MVP++”, because I have this annoying tendency to over-polish, a real flaw when you know how important “talk to users” is. I’m working on it.

The next step is a beta with a few peers and early adopters, before opening up publicly ASAP.

I already know where my pain point will be: distribution. Knowing how to build, that’s fine. Getting it known, that’s another story.

Hello, world.

This is the English version of an article originally written in French. Originally published on mozart.build.

Understanding Reinforcement Learning with Human Feedback Part 1: Pre-Training Large Language Models

In this article, we will explore Reinforcement Learning with Human Feedback (RLHF).

RLHF is one of the techniques used to help train large language models like ChatGPT.

Starting with an Untrained Model

Suppose we want to build a model like ChatGPT from scratch so that we can ask it questions.

To do this, we first need to understand how to train an untrained decoder-only transformer model.

By untrained, we mean that all the weights and biases in the model are initialized with random values.

At this stage, the model does not understand language or meaning.

The First Step: Pre-Training

The first step in training a large language model is to teach it to predict the next token using a very large body of text, such as Wikipedia articles.

We take segments of text and use the earlier words as input tokens. The model then learns to predict the next token in the sequence.

For example, if the input is:

“The cat sat on the…”

The model learns to predict the next likely word.

By repeating this process across a massive amount of text, the model gradually learns:

  • grammar
  • sentence structure
  • facts and patterns in language

This training stage is called pre-training.

Over time, this process produces a pretrained model.

Why Pre-Training Is Not Enough

At this point, the model becomes good at predicting the next token in text.

However, simply predicting the next token is not enough to solve the problem of answering questions like a chatbot.

For example, being good at continuing Wikipedia text does not automatically mean the model will give helpful, safe, or conversational responses.

To make the model useful for chat, we need to align it with human expectations.

We will explore this in the next article.

Looking for an easier way to install tools, libraries, or entire repositories?
Try Installerpedia: a community-driven, structured installation platform that lets you install almost anything with minimal hassle and clear, reliable guidance.

Just run:

ipm install repo-name

… and you’re done! 🚀

Installerpedia Screenshot

🔗 Explore Installerpedia here

What an AI in HR Practitioner Actually Builds: Claude API HR Workflows from the Field

There is a version of AI in HR that lives entirely in conference keynotes and vendor slide decks. Then there is the version I work in.

I am Drew Soule. I am a Wisconsin-based HR executive with 15 years across hypergrowth tech, aerospace, financial services, and healthcare. I was born with a physical disability. I use a wheelchair. I have navigated every dimension of a professional career in a world that still designs its infrastructure around the assumption of able-bodied participation. That experience is not incidental to my work as an HR leader. It is foundational to it. It shapes how I think about systems, barriers, and the difference between what organizations say they value and what they actually build.

I build custom HR workflow automations using the Claude API. Not as a proof of concept. In production. In real organizations, with real constraints, real labor agreements, and real people on the other end of the output.

This is what that actually looks like.

*What the Claude API HR Workflows Actually Do
*

Let me be specific, because specificity is where most AI in HR writing falls apart.

When I was serving as Sr. HRBP to an 800-person global Product and Engineering organization, we were running 10 to 40 concurrent employee relations cases every single week. That is not a typo. That is the operational reality of a high-growth tech org where tenure is short, pressure is high, and managers are often promoted past their leadership competency before anyone notices. The documentation load alone was a second job inside the job.

The workflows I build using the Claude API address that load directly. Structured ER case documentation. First-draft PIPs built from factual input the practitioner provides. Investigation summary frameworks that ensure consistency across a case portfolio. These are not AI making HR decisions. This is AI handling the mechanical drafting so the HR practitioner can focus on the judgment that actually requires human expertise: reading the room, assessing credibility, navigating the relationship between manager intent and employee impact.

That distinction matters. It matters legally. It matters ethically. And it matters for the practitioner who is trying to do serious work without burning out.

*HR Analytics AI Integration Is Not a Dashboard Problem
*

One of the places I see organizations waste the most time is building dashboards nobody acts on. HR analytics AI integration gets positioned as a reporting problem. More visualizations. Better filters. Cleaner exports.

That is not the problem.

When I joined a healthcare organization and built an entire People Programs function in 60 days, the first thing I did was not build a dashboard. I diagnosed. I ran structured pattern recognition across qualitative exit interview data, tenure data, and manager-level cohort analysis. What I found was that 53% of exits were happening within the first 90 days of employment. That insight did not come from a model. It came from knowing what questions to ask and having enough practitioner experience to recognize the pattern when the data confirmed it.

What AI in HR analytics does well is compression and surfacing. When you are looking at volume, AI can accelerate the movement from raw data to structured signal. But the practitioner has to know what signal matters. You cannot outsource that to a vendor. You cannot buy it in a platform. It comes from having been in rooms where the stakes were real.

We redesigned onboarding based on that diagnosis. We measured a 22% attrition reduction and over $400,000 in cost avoidance. That is what HR analytics AI integration looks like when it is grounded in operational reality rather than vendor positioning.

*AI Ethics in People Operations Is a Practitioner Responsibility
*

I want to address AI ethics people operations directly, because most of the writing on this topic is either too abstract to be useful or too cautious to be honest.

Here is my position: the ethical risk in AI-assisted HR work is not that the AI will make a decision. The ethical risk is that a practitioner will let it, and then disclaim accountability when it goes wrong.

I have led labor relations work across a 1,200-person multi-site manufacturing and supply chain organization with active collective bargaining agreements. I know what it means when a document has legal weight. I know what it means when a manager acts on a recommendation without understanding its basis. I know what it means for a real person when the process fails them.

Every workflow I build has the practitioner in the loop. Not as a formality. As a structural requirement. The Claude API outputs a draft. A human reviews it, edits it, owns it, and signs off on it. If that step is removed, the workflow is not safe for use in HR. Full stop.

I say that not for pity, and not for applause. I say it because the HR practitioners reading this are the ones who will be held accountable when something goes wrong, regardless of what the vendor promised in the sales call.

*Generative AI HR Use Cases That Are Actually Ready
*

I am based in Southeast Wisconsin. The organizations I work with are not always San Francisco startups with unlimited engineering resources. They are manufacturers, healthcare systems, financial services firms, and mid-market companies trying to do serious people work with lean HR teams. The generative AI HR use cases that matter here are the ones that reduce friction on high-volume, low-discretion tasks so that practitioners can put their time into high-discretion, high-stakes work.

Ready now, in production, grounded in what I have actually built: ER case documentation frameworks, PIP first drafts from structured practitioner input, onboarding communication templates calibrated to role and manager, exit interview synthesis for pattern identification, job architecture drafts for compensation band work, and manager coaching prep documents built from performance data.

Not ready, and I will not pretend otherwise: any workflow where AI output goes directly to an employee without human review, any process where the AI is making a determination about someone’s employment status, and anything that touches protected class data without explicit legal review of the architecture.

Those lines are not soft suggestions. They are the difference between a practitioner using AI to do better work and an organization using AI to avoid accountability.

*The HR Tech Practitioner Wisconsin Perspective
*

I will close with this.

Yes, I use a wheelchair. I have built a 15-year career across industries that were not designed for me, in rooms that were not always accessible, on teams that sometimes had to be challenged before they understood what inclusion actually required. I have learned, because I had no alternative, to build systems that work when the standard infrastructure does not.

That is the lens I bring to AI in HR. Not excitement about what is theoretically possible. Discipline about what actually works, what the risks are, and what the practitioner owes the people on the other end of the process.

The results I have measured are real. The workflows I have built are in production. The accountability is mine.

Not because AI is magic. Because the humans building it understood the work first.

Is Claude Pro Worth $20/Month? A Developer’s Honest Take

Is Claude Pro Worth $20/Month? A Developer’s Honest Take

I spent $20/month on Claude Pro for six months and almost cancelled. Then I started building my own AI agents and realized I wasn’t just paying for a chatbot—I was paying for a development environment.

Here’s why I’m keeping it, and whether you should too.

The Problem: Free Claude Hits Walls

If you’re using the free Claude, you’ve hit the ceiling. You know the feeling—you’re in the middle of something interesting, and suddenly:

  • Rate limits kick in
  • You’re waiting 5+ minutes between responses
  • You can’t upload larger files
  • Feature access is restricted

For casual use, free Claude is genuinely great. But the moment you want to build something, automate workflows, or iterate quickly on complex problems, those limitations become friction. Every constraint slows your momentum.

The real question isn’t “Is Claude worth $20?” It’s “How much is my time worth?”

What You Actually Get With Claude Pro

Let me break down the concrete differences:

5x Higher Rate Limits

With Pro, you go from 40 to 200 messages per 10-second window. This sounds technical, but practically? You can iterate without watching loading spinners.

When I was learning to build agents with Claude, this mattered. I’d test a prompt, adjust it, test again—5 times in a row. On free tier, that’s a waiting game. On Pro, it’s flow state.

Extended Thinking (The Game Changer)

This is the feature that actually justifies the cost. Extended thinking lets Claude spend extra compute time reasoning through complex problems before answering.

Example: I used it to debug a multi-step agent workflow where the logic was breaking in unexpected ways. Instead of Claude giving me a quick (and wrong) answer, extended thinking let me see its reasoning process and catch the actual issue in the agent loop.
Problem: Agent not passing context between steps
Extended thinking output:

Step 1: Identified where context was getting lost
Step 2: Traced the data flow through three functions
Step 3: Found the specific line causing the issue
Step 4: Suggested three different fixes with tradeoffs

That depth of analysis is worth $20 right there if you do it once a month.

Larger File Uploads & Vision

Pro lets you upload larger documents and use vision capabilities. When I’m building automation workflows, I can paste screenshots directly and get Claude to analyze UI layouts or debug visual issues.

Early Access to New Features

Claude Pro gets first access to new capabilities. Right now, that means you’re testing Claude Code (improved coding capabilities) and Agent integration before the general public.

The Real Cost/Benefit: Productivity Gains

Here’s where the math gets interesting:

Monthly Cost: $20

Realistic Time Saved (conservative estimate): 2-3 hours/month

If your time is worth:

  • Hobbyist ($0/hr): Probably not worth it
  • Freelancer ($50/hr): $100-150 in time saved = net +$80-130/month
  • Employed developer ($75/hr): $150-225 in time saved = net +$130-205/month
  • Startup founder ($∞/hr): The faster iteration speed is worth way more than $20

I’m in the “startup/learning” category right now, which is why I keep it. The extended thinking feature alone helps me debug agent architectures that would take 3x longer to figure out on free tier.

Building Agents: The Use Case That Changed My Mind

Here’s my honest personal context: I’m learning to build AI agents right now, and I’m using Claude directly through this platform. The speed of iteration matters a lot.

When you’re testing an agent workflow:

  1. You adjust the system prompt
  2. You run the agent
  3. You check the output
  4. You’re back at step 1

On free tier, steps 1-4 take 15 minutes when you hit rate limits. On Pro, it’s 2 minutes. Over a week of learning, that’s hours of reclaimed time.

I actually built this blog post with the help of an AI agent I’m developing—the agent helped structure my thoughts, suggested sections, and gave me feedback. That kind of iterative work is only pleasant with higher rate limits.

![INSERT_IMAGE_HERE: Screenshot of Claude Agent creating blog structure]
A glimpse of using Claude Agent for content iteration—faster feedback loops with Pro

Watch my detailed video on getting started with Claude: https://youtu.be/wg02wUYnxQs

Who Should Actually Buy Claude Pro?

Definitely buy it if:

  • You’re a developer iterating on code/prompts (time savings compound)
  • You’re building AI agents or automation (extended thinking is essential)
  • You’re using Claude for work (ROI on 2 hours saved is obvious)
  • You hit rate limits regularly (that’s the biggest sign you need it)

Maybe skip it if:

  • You use Claude casually (few times a week)
  • You’re learning but don’t need rapid iteration
  • You have unlimited budget from a company already paying
  • You primarily need basic chat, not advanced reasoning

Definitely skip it if:

  • You’re completely broke and have other priorities
  • You only use Claude for simple Q&A
  • You can work around rate limits with patience

The Real Comparison: What Changes

Here’s a side-by-side of the most important differences:

Feature Free Claude Claude Pro
Rate Limit 40 msg/10s 200 msg/10s
Extended Thinking ❌ ✅
Vision/File Size Limited Generous
Response Speed Normal Priority queue
Cost Free $20/month
Time saved per month — 2-5 hours

The rate limit difference is the productivity multiplier. Everything else is nice-to-have.

My Honest Take

After six months, I’m keeping Claude Pro. Not because it’s expensive (it’s not), but because I’ve now structured my workflow around it—building agents, iterating on prompts, debugging complex logic.

The $20 covers about one hour of saved time at a decent freelance rate. Once you’re in that mode, you’ll easily hit that target.

But if you’re using Claude for casual questions, the free tier is legitimately perfect. There’s no shame in skipping Pro.

Next Steps

  1. Try Pro free for a week — Claude offers a trial period. See if you hit rate limits.
  2. Use extended thinking for ONE complex problem — see if the reasoning helps.
  3. Decide based on your workflow — not based on FOMO.

If you’re building anything with AI, coding, or automating workflows, give Pro a shot. If you’re purely using it as a search engine replacement, stick with free.

What’s your Claude use case? Drop a comment and let me know if you’re Pro or sticking with free—I’m curious what tipped the scales for other developers.

P.S this was a learning material type of post with own Agent creation.

Want to dive deeper? Check out the video I referenced: https://youtu.be/wg02wUYnxQs for more on Claude’s capabilities.

Agentic Analytics: Architecture, Context, and Why the Semantic Layer Does the Heavy Lifting

Agentic system

An agentic analytics system is one where LLM-powered agents autonomously break a data question into sub-tasks, retrieve relevant context, execute queries, evaluate the results, and return a reasoned answer. There’s no human coordinating each step.

If you’ve sat through a BI vendor demo recently, you’ve heard some version of this: connect your warehouse, build a semantic layer, ask questions in plain English (natural language). It’s a solid pitch. Most teams buy it, set it up, and then find themselves wondering why the analyst queue still looks the same on Monday morning.

Here’s what actually got built: a natural language interface sitting on top of static metric definitions. You ask, it answers. You stop asking, it stops working. Useful? Sure. But it’s still a system that waits for you, and that’s a meaningful architectural constraint, not a minor inconvenience.

Agentic analytics is a different offering altogether. An LLM-powered agent doesn’t wait to be asked. It receives a question or detects an anomaly on its own, breaks it into smaller pieces, pulls the right context from a semantic layer, runs the queries, checks whether the results hold up, and comes back with a synthesized answer showing exactly how it got there.

Why does that distinction matter? Because it changes how you architect your stack, where your engineering time actually goes, and whether the numbers coming out of your system are ones your CFO would sign off on or ones that just look right until someone checks the table they came from.

What “Agentic Analytics” Actually Means

The term “agentic” gets applied to pretty much anything that puts an LLM somewhere near a database. So it’s worth being precise about what it actually means in an analytics context.

Agentic analytics is where AI stops waiting to be asked. Instead of returning a chart in response to a question, an LLM-powered agent breaks the question into pieces, pulls the right context from a semantic layer, runs queries against your data warehouse, checks whether the results actually hold up, and comes back with a synthesized answer showing exactly how it got there. No human coordinating each step. The system drives.

Two architectural properties separate this from standard NLQ BI or a generative AI assistant: loop-based autonomy and grounded execution.

NLQ BI runs on a single-turn request/response cycle. You ask, it answers. If the answer is incomplete, you rephrase and ask again. Generative AI assistants are increasingly gaining warehouse connectivity and tool execution through open standards like MCP, but they aren’t purpose-built for multi-step data reasoning the way agentic analytics systems are.

An agentic system runs a loop instead:

Agentic system

Perceive is the entry point: a question comes in, or an automated trigger fires, like an anomaly threshold breach or a scheduled scan. Reason is where the agent breaks that question into smaller sub-questions, each with specific data dependencies. Act is where it calls tools: semantic search on the business glossary, SQL execution against the warehouse, relationship mapping across entities. Observe is the check: did the returned data actually answer the sub-question, or does the agent need to dig further? Report is the output: all intermediate results synthesized into a natural-language answer with the full reasoning chain visible.

That Act step is where things get interesting, and where architectures tend to diverge. An agent calling tools against a raw table schema has to guess: column names, join conditions, what a given metric actually means. An agent calling tools against a grounded semantic layer retrieves authoritative definitions and generates SQL that matches how your analysts actually calculate revenue. That difference is what the rest of this article is really about.

Why Dashboards Hit an Engineering Ceiling

Dashboard-based analytics has a structural latency problem that doesn’t get talked about enough. In a 2024 Gartner survey, over 60% of data leaders ranked “reducing time to action” as their top priority for analytics investments, and dashboards are a core reason why that gap exists. A dashboard reflects the questions your analyst thought to ask during last sprint’s planning session. The questions your RevOps director fires off in Slack on Tuesday afternoon, the ones involving multi-metric correlations or trends that need explaining, were never going to be on any dashboard because nobody had thought to ask them two weeks ago when it was built.

Self-service BI helps, but only up to a point. Simple questions (revenue by region, deals closed this month) move into self-serve. The harder ones, like why win rate dropped 12% in enterprise accounts in Q3 while SMB held steady, still need an analyst to translate intent into SQL, validate the join logic, and confirm that “net ARR” in the Salesforce export actually means the same thing as “net ARR” in the warehouse before anyone can answer.

And that’s where the real problem lives. Metric definitions, join logic, and business rules tend to pile up in people’s heads, in Slack threads, in undocumented LookML, in SQL file comments that only one analyst knows exist. When you point an LLM directly at a raw schema, it has to guess: what does opp_arr_adjusted mean, which accounts table should it join, should it use closed_date or booked_date for ARR recognition? Those guesses are where agent hallucinations on data tasks actually come from. The missing ingredient is context, not a better model.

The problem gets worse as your data org grows. The gap between what is documented and what people actually know widens over time. A well-designed agentic analytics architecture closes that gap at the infrastructure layer, before the LLM ever sees a query.

The Three-Layer Architecture of a Production Agentic Analytics System

Building agentic analytics that actually works in production means getting three layers right. Each one has a different level of engineering complexity, and each one plays a distinct role in whether your agent returns answers you can trust.

The Three-Layer Architecture of a Production Agentic Analytics System

Layer 1: Data Access

This layer covers connectors to warehouses (Snowflake, BigQuery, Databricks, Redshift) and to BI tools, dbt models, query logs, and document repositories. Honestly, this is largely a solved problem. Mature connector ecosystems and stable APIs mean getting set up is mostly configuration work.The hard part is elsewhere.

Layer 2: The Semantic/Context Layer

This is where real engineering lives. The semantic layer is the load-bearing structure of the entire architecture. A knowledge graph maps every business entity to its definition, its relationships to adjacent entities, and its SQL implementation. The quality and completeness of this layer is what separates agents that return correct ARR numbers from agents that return convincing-looking ones.

Each node in a well-built knowledge graph carries two things: a contextual definition expressing the business meaning of the entity in terms your RevOps team would actually recognize, and an SQL implementation with the exact query that calculates it against your data source. That pairing is what grounds the agent. It knows both what “net ARR” means and exactly how to calculate it, so there is nothing left to infer and nothing to get wrong.

Building that graph well means pulling from multiple input sources: SQL query logs, organizational terminology, BI tool exports from Looker or dbt, external APIs, and unstructured documents processed through Named Entity Recognition (NER). Metric definitions in a growing company change constantly, so the ability to update the model over time, with version control built in, is not optional.

Layer 3: The Orchestration and Agent Layer

This is where task decomposition, tool-calling, multi-step reasoning, and response generation happen. The Model Context Protocol (MCP) structures communication between the agent and the context layer. When an agent in Claude Desktop or Cursor needs to resolve an entity, it requests context through a permissioned MCP server rather than querying raw table schemas directly. The server returns the authoritative definition and SQL implementation (including relevant column names) for that entity, so the agent never encounters raw column names and has no reason to hallucinate them.

Jedify implements this pattern through an MCP server that exposes the semantic context graph to external AI tooling without surfacing the underlying schema, keeping access controls intact while giving those tools the grounding they need to work reliably.

Context Is the Hard Problem, Not the Model

If your agent is returning wrong ARR numbers, upgrading to a different (or better) LLM is not going to fix it. The problem is definitional ambiguity, and that lives in your data stack, not in the model.

The failure mode to understand here is entity disambiguation. Take a straightforward query: “What’s our net ARR this quarter?” Across a typical enterprise data stack, “net ARR” can quietly resolve to at least three different calculations:

  • The Salesforce CRM export, which calculates ARR from signed contract value with a manual churn adjustment maintained by the Customer Success team
  • The Redshift warehouse, which calculates ARR from actual invoiced amounts with a different treatment for multi-year deals
  • The dbt model, which follows finance’s definition and excludes professional services revenue that sometimes sneaks into the other two

An agent hitting your raw schema in the database will generate a different SQL query depending on which table it finds first, which column names look familiar, and which joins seem plausible based on field name patterns. Three queries, three numbers, all technically valid SQL, but none of them necessarily matching what your CFO actually means when they ask about net ARR.

This is well-documented territory. dbt Labs’ analysis of agentic analytics puts it plainly: agents fail at data tasks because they lack business definitions, tribal knowledge, and data source disambiguation. SQL construction ability is not the bottleneck. Informatica’s research on autonomous data agents arrives at the same conclusion: high-quality, well-governed, accessible data is the critical foundation.

A properly built semantic layer solves this at ingestion time. It mines your query logs (the SQL your analysts actually run, which reflects real metric definitions), applies NER across runbooks and wiki documents, extracts calculated field definitions from LookML or dbt, and runs co-occurrence analysis to resolve conflicting definitions. The result is a single semantic entity for “net ARR” with one authoritative definition and one SQL implementation. When the agent queries through the MCP server, it gets that entity and produces one unambiguous answer.

Real-World Use Cases: RevOps, Customer Success, and Product

The architecture argument is easier to follow when you see it in contexts where the questions are genuinely complex and wrong answers have dire consequences.

In RevOps, imagine an agent that’s continuously monitoring pipeline data and detects when deal velocity drops below a configured threshold. Without anyone asking, it runs a root cause analysis: stage-by-stage conversion, rep-level breakdown, time-in-stage delta versus the prior quarter. It writes up a natural-language summary with key drivers ranked by impact and drops it in Slack. The RevOps analyst never opens a dashboard. The insight arrives with the full reasoning visible, and the actual strategy decisions stay with the humans.

In Customer Success, agents can run account health scoring by pulling product usage data, support interaction counts, contract data, and engagement signals across connected sources. Churn risk and expansion opportunities surface before the CSM even opens their account view. The scale is what makes this genuinely useful: an agent can assess all 500 accounts in a portfolio at the same time and flag the 12 showing correlated disengagement signals. That’s not something a CSM team can do manually every morning. Contract changes and outreach decisions still belong to the CSM.

In product analytics, root cause analysis is where agentic architecture really earns its keep. When a product manager asks “Why did feature adoption drop 18% in the last two weeks for enterprise accounts?”, a standard NLQ system returns a number. That number tells you what happened. It has nothing to say about why.

An agentic system breaks the question apart: which enterprise cohort, which feature surface, what changed in the deployment timeline during that window, whether support ticket spikes appeared at the same time. It runs cross-metric correlation queries across product usage, deployment logs, and support data, then comes back with a root cause analysis showing every intermediate query and finding. The answer is auditable and actionable in a way no single chart can match.

What Makes or Breaks Production Deployment

Getting agentic analytics into production is one thing. Keeping it accurate and trustworthy at scale is another. Three things tend to determine whether it holds up: governance, observability, and how you sequence the rollout.

Governance comes down to access scoping at the semantic layer. An agent with read access to your entire data warehouse is a security risk that scales with the size of that warehouse. When agents query through named semantic entities instead, access controls apply at the entity level. An agent configured for RevOps can see pipeline entities and nothing in HR or payroll, even if those tables sit in the same Snowflake account. RBAC at the entity level within the context graph keeps access controls consistent regardless of which AI tool connects through the MCP server.

Observability is the feedback loop that keeps the system honest over time. Thumbs-up/down feedback on agent responses is the primary signal for catching when entity definitions are wrong, incomplete, or ambiguous. When an analyst rates a response negatively and notes “this calculated churn wrong,” you know exactly which entity needs attention. A simple weekly process where a data engineer reviews low-rated responses, identifies the definition that caused the error, and updates the semantic layer is how the context graph gets better rather than drifting.

Rollout sequencing is where most teams trip up by trying to deploy agents across all domains at once. Start with one well-bounded domain where ground truth is independently verifiable. RevOps pipeline metrics are a good starting point because you can compare agent output directly against a known analyst answer and catch errors before they spread. Run that comparison for two weeks, validate accuracy, then expand by adding semantic entities for the next domain. The agent layer stays the same. The context graph grows.

Gartner’s enterprise AI adoption analysis projects that 33% of enterprise software will include agentic AI capabilities by 2028. Teams that invest in the semantic layer now will be able to extend agents into new domains without rebuilding from scratch each time. Teams that treat it as a problem for later will find their agent accuracy capped by whatever institutional knowledge never made it into documentation.

Audit Your Semantic Layer for Agent-Readiness

Before you start evaluating agent platforms, it’s worth assessing objectively where your semantic layer actually stands. Four questions that cut straight to it:

  1. Are your core business metrics defined in code with explicit formulas? A dbt metric definition or a LookML measure counts. A wiki page that explains what a metric means does not.
  2. Are entity relationships, like account to opportunity to ARR, documented with the join logic that actually implements them?
  3. Is there a single authoritative definition for ambiguous terms like “active user,” “churned customer,” or “qualified pipeline”?
  4. Does that definition point to a specific table and column, or does it only exist in a runbook somewhere?

If any of those answers is no, that’s your context debt. And it will show up as agent errors no matter which LLM you put in the driver’s seat.

The good news is you don’t have to solve all of it at once. Start with the metric your team argues about most, the one behind every “wait, which number are we using?” thread in Slack. Turn it into a proper semantic entity: write the business definition, nail down the SQL implementation, document its relationships to adjacent entities. Then test it. Can your agent answer three different versions of that question correctly, with its reasoning visible? If yes, you have your foundation.

That’s the approach that actually works in practice: one domain, one entity at a time, context graph growing steadily while the agent layer stays stable. It’s less exciting than a big-bang deployment and considerably more likely to produce a system people trust six months from now.

What does your current semantic layer actually cover? If you’ve been working through the context debt problem in your own stack, it’d be great to hear what’s worked.

Why MTP doesn’t speed up your llama.cpp inference (and how to actually fix it)

Last week, I spent two days banging my head against a wall. I had just spun up a fresh llama.cpp build with multi-token prediction (MTP) support, loaded a quantized Qwen3 model, and ran my benchmark suite expecting that sweet 2-3x speedup everyone keeps talking about.

The result? Roughly the same tokens per second. Sometimes slower. After a lot of profiling, I figured out what was happening — and it turns out the issue is more common than the celebratory benchmark posts suggest.

This post is for anyone who’s enabled MTP, expected a speedup, and got nothing.

What MTP actually does (the short version)

Multi-token prediction is a form of speculative decoding baked into the model itself. Instead of running a separate, smaller draft model to guess the next few tokens, the main model emits multiple candidate tokens per forward pass. The verifier (usually the same model with a slightly different head) accepts or rejects them in one shot.

The theory is simple. If acceptance rate is high, you get 2-3 tokens per forward pass instead of one, with roughly the same latency per pass. In practice, MTP can make things worse if any of three things go wrong.

The three reasons MTP fails to speed things up

Here are the actual root causes I hit, in order of frequency:

1. Low acceptance rate

This is the big one. MTP only helps if predictions are accepted. If your acceptance rate is below ~60%, you’re paying the extra compute cost of generating drafts without getting tokens back. Wall-clock time goes up.

I see this most often when:

  • The prompt is unusual (specific code style, niche domain)
  • Temperature is too high (anything above ~0.7 starts hurting)
  • The model was quantized aggressively and the MTP head suffered more than the main weights

2. KV cache thrashing

When you generate multiple candidates per step, you churn the KV cache more aggressively. On consumer GPUs with limited VRAM, this can spill into slower memory or cause re-allocation. The forward pass speedup gets eaten by memory stalls.

3. CUDA graph capture failures

This one bit me hard. llama.cpp tries to capture CUDA graphs for the inference loop. If MTP introduces dynamic shapes (variable number of accepted tokens per step), the graph gets re-captured every step. You lose the performance win of graphs entirely, and the per-step overhead actually goes up.

Step-by-step: diagnosing your setup

Here’s the order I work through now whenever MTP doesn’t seem to help.

Step 1: Measure the actual acceptance rate

llama.cpp surfaces speculation metrics with verbose logging. Build with CUDA support and run with -v:

# Build llama.cpp with CUDA support
cmake -B build -DGGML_CUDA=ON
cmake --build build --config Release -j

# Run with verbose stats so we can see acceptance numbers
./build/bin/llama-cli 
  -m models/qwen3-quantized.gguf 
  -p "Write a Python function for binary search" 
  --n-predict 256 
  -ngl 99 
  -v 2>&1 | tee run.log

Then grep the log for the speculation stats. You’re looking for an n_accept ratio. Below 0.6 means MTP is actively hurting throughput on your workload.

Step 2: Check VRAM headroom

If acceptance is fine but throughput is still bad, you’re probably memory-bound. Watch VRAM usage during inference in a separate terminal:

# Poll memory and GPU utilization once per second
nvidia-smi --query-gpu=memory.used,memory.total,utilization.gpu 
  --format=csv -l 1

If you’re sitting at >95% VRAM utilization while running, MTP’s extra KV cache pressure is pushing you over the edge. The fix is usually to reduce context length, drop to a more aggressive quant (Q4_K_M instead of Q5_K_M), or shorten the draft window.

Step 3: Disable CUDA graphs as a control

To check whether graph re-capture is killing you, force graphs off and re-run:

# Disable CUDA graphs to test if they're being re-captured each step
GGML_CUDA_DISABLE_GRAPHS=1 ./build/bin/llama-cli 
  -m models/qwen3-quantized.gguf 
  -p "Write a Python function for binary search" 
  --n-predict 256 
  -ngl 99

If throughput is roughly the same with graphs disabled, capture isn’t your problem. If throughput goes up with this flag set, that’s the smoking gun — graphs were being re-captured every step under MTP and the overhead was worse than not using them at all.

The actual fix

Once you’ve identified which of the three issues you’re hitting, the fix is usually simple:

  • Low acceptance — shorten the draft window. Most MTP implementations let you set a draft length of 1-4 tokens. Dropping from 4 to 2 often pushes acceptance above 70% because the model has to commit to fewer guesses in a row.
  • VRAM pressure — reduce context length or quantize more aggressively. KV cache size scales linearly with context, so cutting --ctx-size in half buys you real headroom.
  • Graph capture churn — pull the latest llama.cpp. The speculation code path changes frequently and padded graph capture has improved a lot recently.

Here’s the config that finally worked for me on a quantized Qwen3 model with around 24 GB of VRAM available:

# Final working config — moderate draft length, conservative context
./build/bin/llama-cli 
  -m models/qwen3-quantized.gguf 
  -p "$PROMPT" 
  --n-predict 512 
  --ctx-size 8192 
  --draft-max 2 
  --draft-min 1 
  -ngl 99

That gave me roughly 1.7x throughput over the no-MTP baseline on my workload. Not the magical 3x some posts claim, but a real, repeatable win that I could ship.

Prevention tips

A few things I now do by default whenever I touch MTP:

  • Always benchmark with and without MTP. Don’t trust that it’s helping just because it’s enabled. Run both, measure both, save the numbers.
  • Pin your llama.cpp version. The MTP code path changes frequently. A config that works today can regress between commits.
  • Match quantization to the head carefully. Some MTP heads are sensitive to aggressive quantization. If acceptance rate suddenly tanks after a re-quant, that’s usually why.
  • Log acceptance rate as a metric, not just throughput. Throughput tells you the symptom; acceptance rate tells you the cause. When you can see both side by side, regressions become obvious.

The honest takeaway is that MTP is a real win when the conditions line up, but it isn’t free. If you’ve enabled it and gotten nothing, you’re not doing it wrong — you’ve just hit one of the failure modes nobody talks about in the benchmark threads. Walk the three steps above and you’ll usually find the culprit within an hour.

Longest Substring Without Repeating Characters — LeetCode #3 (Medium)

The Problem

Given a string s, return the length of the longest substring that contains no duplicate characters.

Example

Input: s = "abcabcbb"

Output: 3

The answer is “abc”, with the length of 3. Note that
“bca”
and
“cab”
are also correct answers.

Constraints

  • 0 <= s.length <= 5 * 10^4
  • s consists of English letters, digits, symbols and spaces

The Key Insight

Here’s what we’re throwing away. When we hit the duplicate ‘a’, we already knew the window held ‘a’, ‘b’, ‘c’. We had that information. What if instead of restarting, we just nudged the left edge forward until the duplicate was gone?

That’s the sliding window. A left pointer and a right pointer. Right grows the window, left shrinks it. We need instant answers: is this character already in the window? That’s a set. Think of a guest list, names only, no duplicates.

You might think to add the character first, then check. Don’t. Check first, then add, or you’d match a character against itself. The rule: while right’s character is in the set, remove from the left and slide left forward. Then add right’s character.

Why It Works

Notice what happened. Both pointers only ever moved right. Every character entered the set once and left once. No backtracking.

Walking Through It

Left and right both start at zero. ‘a’ is not in the empty set. We add it. Window is one wide. Max is one. Right moves to one. ‘b’ is not in the set. Add it. Window spans zero to one. Max is two.

Right to two. ‘c’ is not in the set. Add it. Window is three wide. Max becomes three. Right to three. That’s ‘a’ again. ‘a’ is already in the set. Duplicate.

Remove ‘a’ at index zero, slide left to one. ‘a’ is out of the set. Add the new ‘a’. Window spans one to three. Right to four. ‘b’ is in the set. Remove ‘b’ at left, slide to two. Add new ‘b’. Window is two to four. Max still three.

Right to five. ‘c’ repeats. Remove ‘c’ at left, slide to three. Add ‘c’. Window three to five. Max still three. Right to six. ‘b’ is in the set. Remove ‘a’ at left, slide. ‘b’ is still there. Remove ‘b’ too, slide again.

Now ‘b’ is clear. Add it. Window is just two wide. Right finishes at seven the same way. Max never exceeded three.

Complexity

Each character enters the window once and leaves once. The set holds only the current window. Time and memory both grow with the string’s length.

The Code

OK, same logic in Python. We initialize the set, the left pointer, and the running max. The outer loop walks right one step at a time through every character.

The inner while keeps removing from the left until the repeat is out of the set. Then we add the new character and check if this window beats our best.

Hand back the best length we found.

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        seen = set()
        left = 0
        max_len = 0
        for right in range(len(s)):
            while s[right] in seen:
                seen.remove(s[left])
                left += 1
            seen.add(s[right])
            max_len = max(max_len, right - left + 1)
        return max_len

Wrap-up

And that’s the pattern. Grow until you can’t, shrink until you can. You’ll see this shape again.

📺 Watch the full walkthrough on YouTube: https://youtu.be/dZ395_AbzcA

High-Value If, Low-Value Foreach: Why Agents Trade in Judgment Structures, Not Models

High-Value If, Low-Value Foreach

Why agents trade in judgment structures, not models

Why model placement, not model frequency, determines whether agents become real products

This is the first in a series on the engineering of Agent Runtimes. It argues that the 2026 problem for agent builders is not intelligence — it is where intelligence is placed. The full series builds the discipline from high-value ifs to value functions, schemas, workflows, and the if/foreach ledger.

Abstract

You are not selling model access. You are selling reusable judgment.

Most agent products fail not because the model is too weak, but because the model is in the wrong place. They put a frontier model inside the foreach loop — re-reading every page, re-planning every step, re-generating every action — then collapse under cost, latency, and reliability failures the moment they leave the demo environment.

The discipline this essay proposes: place the stochastic model at high-value ifs — branches with high uncertainty, dense semantics, and high stakes — and hand the deterministic foreach to programs, workflows, and tools. Once the model makes a useful judgment, the system must absorb it into schemas, workflows, audit logs, skills, and evaluation sets. The goal is not more model calls. The goal is fewer unnecessary ones over time.

Frontier models open paths. Deterministic systems pave roads. Everything else is engineering.

1. The 2026 Problem for Agent Builders

Most agent demos — built by what I’ll call agent builders: the teams designing model routing, workflows, schemas, permissions, approvals, and audit logs — fail for the same reason: they put the model in the wrong place.

They ask the model to read every page, re-understand every DOM, re-plan every step, and generate every action. The demo looks impressive. The product collapses under cost pressure, latency, reliability failures, and lack of reuse.

The first commercial problem of agents is not intelligence. It is where intelligence is placed. Where should the stochastic model appear inside a deterministic system?

Over the past two years, from the Chat Completions explosion to the emergence of Computer Use compatibility layers, the industry has hit a structural wall: there is no mechanism to crystallize stochastic judgment into deterministic assets. Every model call is still a one-time expense. When the task ends, the exploration vanishes with it.

In 2026, the model layer is moving from chat-completion interfaces toward agent-building primitives — Responses API, Structured Outputs, Computer Use, Agents SDK, Sandbox Agents. Frontier inference costs are dropping into a range where deep semantic analysis finally pencils out. Local runtime ecosystems are becoming mature enough to orchestrate complex tasks. And the old internet spent three decades compressing reality into low-resolution proxies — degrees, ratings, sales volume, clicks, rankings, and other sortable fields — which are now exposing systemic weakness under information degradation and Goodhart’s Law.

Agent builders need a complete methodology spanning high-value ifs, value functions, and engineering implementation. The question reduces to one thing:

How can a single model judgment become a durable system asset?

Builders won’t win by out-scaling model providers. They’ll win by owning the judgment structures, workflows, and responsibility boundaries that models serve.

2. Model Placement, Not Model Frequency

In agent systems, model placement matters more than model frequency.

The do-everything agent that wows demo audiences dies in production from cost blowups and reliability collapse. The answer lies not in parameter count or prompt sophistication, but in the most fundamental engineering discipline: where the model sits in the architecture.

Luo Fuli, who led DeepSeek-V2 research before joining Xiaomi’s MiMo team in late 2025, framed it in a recent interview as a product of three factors: effectiveness × cost × efficiency. The framing matters because it forces agent design back from the “fully autonomous” myth to the engineering reality of the runtime. None of the three is optional. Effectiveness without cost control cannot become a commercial product. Low cost without trustworthy results creates no willingness to pay. Efficiency that only runs deterministic flows is not an agent — it is RPA with a wrapper.

Translating this into concrete architectural decisions gives us the first engineering discipline of the agent era.

What Models Should and Should Not Do

The past two years of Agent Runtime practice — the execution layer that manages state, permissions, workflows, tool calls, model routing, audit logs, and human approval — point repeatedly to one division of labor:

The Agent Runtime should place the model at high-uncertainty, semantically dense, high-stakes decision branches. It should hand repeatable, well-scoped, verifiable, low-risk execution to programs, workflows, and tool layers.

Low-value foreach: what it looks like

Foreach is batchable, repetitive, procedural, well-scoped work:

  • Batch-scraping web pages
  • Batch-organizing files
  • Batch-exporting conversation logs
  • Batch-converting Markdown to other formats
  • Batch-executing known browser flows
  • Batch-calling API endpoints
  • Batch-structuring content into uniform formats
  • Batch-classifying items in a low-risk first pass

These tasks are often packaged as “AI automation,” but structurally they belong to programs, scripts, CLI, SQL, queue systems, rule engines, Playwright, MCP tools, or deterministic pipelines.

On tasks that can be deterministically described, programs are typically orders of magnitude cheaper, faster, more stable, and easier to audit and reproduce than LLM calls.

If a task can be described as:

for item in items:
    do_something(item)

the model should not be the primary executor of that loop.

High-value if: the model’s anchor point

I call these branches high-value ifs: decision points with high uncertainty, semantic density, and high stakes. They cannot be reliably captured by a few fields, nor safely decided by low-trust rules.

Not every if is high-value. file_exists(path) is an if — but it is a state check. user.is_logged_in is an if — but it is a boolean lookup. inventory > 0 is an if — but it is a numeric comparison. These are low-value state judgments better handled by programs, databases, caches, rule engines, or workflows.

High-value ifs in an Agent Runtime are judgment nodes that require the model to synthesize context, objectives, risk, constraints, and user intent across multiple possibilities, then choose:

  • Intent judgment: What does the user actually want?
  • Information sufficiency: Is the current context enough to proceed?
  • Cost-benefit judgment: Is this task worth continuing?
  • Tool selection: Which tool best fits this step?
  • Quality judgment: Is this result trustworthy?
  • Signal-noise judgment: Which parts are noise?
  • Information value: What should enter long-term memory?
  • Risk classification: Which operations need human confirmation?
  • Pattern recognition: Which processes can be hardened into workflows?
  • Error attribution: Is the failure a page change, permission issue, model misunderstanding, or unclear user intent?

None of these can be solved by a simple foreach. These decision branches are where the LLM should appear in an agent system.

A high-value if is not completed by the LLM alone. It is completed by two layers:

Layer 1 — The LLM operates in high-dimensional semantic space: understanding, extracting, attributing, comparing, generating candidate judgments, and handling uncertainty.

Layer 2 — Schema, enums, booleans, workflows, rules, and human approval gates constrain the model’s output into auditable, reproducible, accountable final decisions.

Without the LLM, high-value ifs regress to field filtering. Without the schema, high-value ifs become unauditable free-form generation. Both layers are indispensable.

If and Foreach Are Nested, Not Exclusive

High-value ifs and low-value foreach loops rarely appear in isolation. They interleave constantly.

The user says: “Organize this week’s important emails and classify them by project.” Structurally, this is a foreach:

for email in this_week:
    classify(email)

But expand one layer, and every step contains ifs:

for email in this_week:
    if is_spam(email):
        skip(email)

    if is_newsletter(email):
        archive(email)

    if is_work_related(email):
        project = infer_project(email)

        if project.confidence > 0.85:
            classify_into_project(email, project)
        else:
            ask_user_or_create_candidate_project(email)

        if contains_deadline(email):
            date = extract_date(email)

            if date.confidence > 0.9:
                create_task(email, date)
            else:
                mark_for_review(email)

If and foreach nest inside each other. This nesting does not imply every step should call an LLM. The primary engineering job of the Agent Runtime is to precisely decompose this mixed structure:

  • Which foreach loops can run through deterministic pipelines with no LLM at all.
  • Which ifs require a frontier model, because they are high-value judgment nodes.
  • Which ifs can be resolved by historical workflows, because the pattern has been absorbed.
  • Which ifs can be handled by a lightweight model plus rule engine, because the risk is low.
  • Which ifs require human approval, because the action is irreversible.
  • Which exceptions need to re-invoke a frontier model, because existing workflows have broken.

The key thesis compresses to one line:

The key to agent engineering is model placement.

3. Why Agents Fail When the Model Becomes the Executor

Many agent products fail because they treat the LLM as a universal executor rather than a critical judgment engine. They make the model re-read the page, re-understand the DOM, re-plan the path, and re-generate the action at every step. This looks powerful in demos. Once deployed, it hits five structural failures simultaneously.

Failure 1: Uncontrollable cost

Every step calls a frontier model and recomputes the full context. A task advertised as “fully automated” rapidly accumulates model cost, latency cost, and failure-recovery cost.

Failure 2: Uncontrollable reliability

An LLM is a stochastic system. Every re-decision adds another stochastic failure point. A 10-step task at 95% per-step success has ~60% overall success. A 20-step task drops to ~36%.

The 95%^n figure is an independence approximation. Real agent steps are not independent: page changes, permission expirations, context pollution, and upstream errors increase correlation, making actual failure modes more complex. The problem is not that the model is “slightly off.” It is the physics of error accumulation in a long-sequence autoregressive decision process.

Failure 3: Uncontrollable state pollution

As the LLM ingests execution results across a long loop, the context gets progressively dirtier. Early system prompts, task objectives, risk boundaries, and output constraints get diluted by page noise, failed attempts, and intermediate results. Lost-in-the-middle (U-shaped attention decay in long contexts, Liu et al., 2023) amplifies state pollution. Handing foreach to programs means every necessary model call happens inside a shorter, cleaner context window.

Failure 4: Throughput-latency mismatch

Foreach means high throughput demand. If means high latency tolerance. Batch-processing thousands of items requires throughput, concurrency, retries, and monitoring. LLMs’ autoregressive generation makes them inherently unsuited to high-throughput execution. A model can be slow and expensive at a few critical nodes, but not at every iteration of a pipeline.

Failure 5: Non-reusable results

Every task starts from scratch. After the task ends, the system retains nothing. The same user issuing the same task triggers the same cost and probability gamble from zero.

These five failures explain why many Computer Use and Browser Agent products stall: they put the LLM inside the foreach, then try to brute-force their way out by reaching for stronger models. The root cause is failing to draw the physical boundary between stochastic judgment and deterministic execution.

The model contributes semantic judgment at the high-value if. The system crystallizes that judgment into structure. The foreach then reuses it at low cost.

4. Explore, Prune, Harden, Evolve

Expanding “model placement over model frequency” into a product architecture yields four phases.

Phase 1: Explore

The user initiates a new type of task for the first time. The system recognizes an unseen scenario: no reusable workflow, no cache hit, no known fallback.

This is the moment to call the frontier model.

Its job goes beyond “completing this task.” It explores the real structure of the task in high-dimensional semantic space:

  • What is the user’s true intent — does it match the literal request?
  • Where are the critical judgment nodes?
  • Which steps are deterministic, which require judgment?
  • What are the success conditions for the critical path?
  • Where should the system fall back on failure?
  • Which steps involve irreversible actions requiring human approval?

The frontier model’s output should be a structured decision graph: explicit schema, explicit step sequence, explicit branching conditions, explicit success signals, explicit fallbacks.

This call is expensive because it bears the cost of task-structure discovery, risk-boundary identification, and the foundation for all subsequent low-cost reuse.

Phase 2: Prune

The decision graph from Phase 1 is a first draft — “theoretically completable.” Real environments expose stability gaps: pages redesign, networks fluctuate, user inputs are ambiguous, third-party APIs fail intermittently.

The key action is testing and pruning with real data:

  • Which branch conditions have never actually been triggered.
  • Which “requires human review” nodes can actually be automated.
  • Which nominally uncertain steps always take the same branch in practice.
  • Which fallback paths are more stable than the primary path.

Pruning compresses the “redundant decision graph” into a “minimal necessary decision graph validated by real data.” This phase often does not need a frontier model. Mid-tier models, real-data replays, rule-based statistics, and manual review are usually sufficient.

Phase 3: Harden

The pruned decision graph gets hardened into an executable structured workflow. A real industrial Agent Runtime stores DAG-level (directed acyclic graph) or FSM-level (finite state machine) state-transition logic — “under what conditions to transition from state A to state B,” not “do step one then step two.”

A simplified example:

{
  "workflow": "export_bank_statement",
  "site": "example_bank.com",
  "intent": "download monthly statement as PDF",
  "preconditions": [
    "user_logged_in",
    "two_factor_completed"
  ],
  "steps": [
    {
      "type": "navigate",
      "target": "/account/statements"
    },
    {
      "type": "click",
      "selector_hint": "button containing 'Statements'"
    },
    {
      "type": "select",
      "field": "month",
      "value_from_user": "target_month"
    },
    {
      "type": "click",
      "selector_hint": "download_pdf_button"
    }
  ],
  "approval_required": false,
  "success_signal": "file_downloaded_with_pdf_extension",
  "fallback": [
    "ask_user_to_confirm_page",
    "rerun_page_exploration"
  ],
  "max_retries": 2,
  "confidence": 0.78
}

Key properties of this workflow:

  • Structured and machine-parseable — not a natural-language wish.
  • Explicitly declares uncertainty — selector_hint instead of pretending there is always a stable selector.
  • Explicit success signal — not a false completion.
  • Fallback paths — knows where to retreat on failure.
  • Retry limits — prevents infinite loops.
  • Confidence score — knows how reliable it currently is.

From LLM output to stable DAG, there must be an alignment layer. Real hardening is not saving model-generated JSON directly into production. It means decomposing successful trajectories into nodes, actions, preconditions, state transitions, failure branches, and success signals, then validating through replay, unit tests, shadow testing, and evals. Any action hardened into a workflow must first pass deterministic shadow testing or evaluation-set replay. The confidence score is computed, not self-reported by the model.

The second time, the tenth time, the hundredth time the user says “export my statement,” the system does not re-invoke the frontier model. It runs the workflow deterministically, supplementing judgment only at local uncertainty nodes. Marginal cost approaches zero.

Phase 4: Evolve

Workflows are not one-time artifacts. Pages redesign, DOMs change, CAPTCHAs appear, A/B tests show different interfaces, sessions expire, permissions shift. All of these can break an existing workflow.

The system should not immediately invoke a frontier model for full re-exploration. It should follow an escalation gradient:

  1. Try existing fallback paths.
  2. If fallbacks also fail, trigger a limited-scope LLM re-judgment.
  3. If the failure mode is known, update the corresponding workflow branch directly.
  4. If the failure mode is novel, escalate to the frontier model for re-exploration.

The key variable across all four phases is confidence. A workflow is a set of judgment assets with confidence scores, not rigid rules. Each successful execution raises confidence. Each failure lowers it. When confidence drops below a threshold, the system re-invokes model exploration.

Combining the four phases:

The model opens the road. The system paves it.

The cost curve shifts from “linear growth per model call” to “growth per new scenario and exception.” The former gets more expensive over time. The latter gets cheaper.

The asset is not the answer

The asset is not that the model answered once. The asset is the absorbed judgment.

If the model’s output cannot be captured by the system, even an excellent answer is just an expensive one-time consumption. If the model’s judgment can be absorbed, even an expensive call is an asset investment — it becomes next time’s rule, workflow, skill, or memory, lowering the cost of the next hundred tasks.

  • A correct if becomes a rule.
  • A stable branch becomes a workflow.
  • A recurring judgment pattern becomes a skill.
  • A persistently useful user preference becomes memory.

The dividing line between chat products and Agent Runtimes:

Chat products optimize single-answer quality. Agent Runtimes optimize the conversion of judgment into reusable system assets.

The effectiveness × cost × efficiency formula translates into precise engineering:

  • Effectiveness: determined by the frontier model’s high-dimensional semantic judgment quality during first exploration.
  • Cost: determined by whether the system can absorb that judgment into a workflow.
  • Efficiency: determined by the stability of downstream foreach execution.

These three are multiplicative, not additive. Great effectiveness with uncontrolled cost cannot become commercially viable. Low cost with untrustworthy results creates no willingness to pay. High efficiency that only runs deterministic flows is just RPA.

The engineering discipline:

  • Put high-value ifs on the frontier model — protect effectiveness.
  • Absorb successful ifs into workflows — protect cost.
  • Put foreach on deterministic execution — protect efficiency.

All three are necessary.

5. A Schema Is a Boundary, Not a Form

The four-phase cycle leaves one critical question: what exactly is an if node inside a workflow?

Many builders, the first time they see a JSON workflow or structured schema, instinctively read it as “field filtering from traditional software engineering”:

if degree == "Bachelor's" and years_of_experience >= 5:
    pass
else:
    reject()

This reading immediately degrades the agent into “SQL queries wearing an AI costume.”

A mature agent if node is a boundary condition of a high-dimensional judgment space actively defined by the builder — not field filtering.

A schema is a directional constraint on LLM compute. An LLM without schema constraints is a high-dimensional hallucination field. A well-designed schema projects a precise decision mold into the LLM’s latent space. The builder designs that mold.

If a content-filtering agent’s output enum contains only LIKE, DISLIKE, SKIP, it structurally cannot express “this article creates cognitive friction, but it is important.”

If a research agent’s output enum contains only USEFUL and USELESS, it structurally cannot express “this material is not directly usable, but it provides a critical counter-example.”

If a recruiting agent’s rejection reasons include EDUCATION_BACKGROUND_TOO_LOW, the agent structurally inherits degree-based elimination. If that enum value is removed, the agent structurally cannot use “degree too low” as a final rejection reason.

The boundary of the enum is the boundary of the agent’s thought.

From field filtering to high-dimensional optimization

In a recruiting scenario, a recruiting agent’s schema should not default to a field filter of “degree, years of experience, tech-stack keywords.” It should be a judgment space with constraints, dynamic weights, and evidence chains.

Context includes: industry profile, real job requirements, reporting line, compensation budget, team structure, and candidate status. Dynamic weights can include: degree, big-company experience, project depth, technical capability, chaos tolerance, and output quality under extreme pressure. Hard constraints include: salary must not exceed budget ceiling, availability must not be later than project start date. Output structure includes: interview recommendation, rejection reason, hidden-potential flag, human-review escalation, and evidence chain.

The critical point is the rejection-reason enum. It may include: core skill gap, excessive job-hopping, budget overrun, availability mismatch, cultural fit risk. But it must not include EDUCATION_BACKGROUND_TOO_LOW.

First, the agent can treat education as a dynamic signal but cannot use it as a final rejection conclusion. Education may carry weight in stable organizations and approach zero in an early-stage startup. It is a variable, not a verdict.

Second, compensation budget is a hard constraint, not a dynamic weight. Hard constraints cannot be compensated by other dimensions. Even if a candidate is outstanding, the agent cannot bypass the budget limit — it must escalate to human review.

Third, the agent performs constrained high-dimensional optimization, not field matching. The LLM compresses the semantic world into optimization parameters — extracting dynamic weights w_i, candidate feature scores Feature_i, evidence chains, constraints, and uncertainty. Ranking, filtering, combinatorial selection, and budget-constraint solving are handled by deterministic algorithms.

The system does not solve:

if degree_ok and years_ok:
    interview()

It solves:

Find candidate c that maximizes Σ(w_i * Feature_i)

Subject to:
  Salary <= Budget
  Availability <= ProjectStartDate
  Irreversible risks escalate to human review
  Key conclusions require evidence_chain

The dynamic weights w_i are the critical lever. Education should not become an automatic elimination criterion — not because a prompt says ignore_degree = True, but because the schema forces the agent into a larger context for trade-off analysis: company stage, real role needs, team gap, budget rigidity, and whether the candidate’s strengths compensate for weaknesses.

The shift from field filtering to scenario-level judgment depends on structural constraints, not prompt instructions.

For 25 to 30 years, platforms across recruiting, e-commerce, content, healthcare, and investment have relied on low-resolution proxies — degrees, sales volume, ratings, rankings — not because they preferred these fields, but because they lacked scalable high-dimensional judgment capability.

A schema is the builder’s boundary definition of a high-dimensional judgment space. It is not a field table.

6. Every High-Value If Encodes a Value Function

The preceding sections solve “who judges” and “when to judge.” They do not yet solve “on what basis.”

If the builder only says “hand this to the frontier model,” a gap remains: what ordering does the model’s output obey? What matters more? What cannot be breached? When should the system stop and hand responsibility back to a human?

Every high-value if needs an explicit value function behind it. If you do not define the value function explicitly, the model’s default training biases, the platform’s default commercial interests, or random noise will define it for you.

By “value function,” I do not mean a narrow reinforcement-learning reward function. I mean an operational decision structure: objectives, dynamic weights, hard constraints, risk thresholds, rejection rules, human-approval conditions, and evidence requirements.

The if is the entry point of the value function

Every high-value if is a moment when the product makes a trade-off among multiple values: what matters more, what can be sacrificed, what must stop, what is worth recommending, what must be rejected.

In the old software era, value functions were hardcoded by PMs, algorithm engineers, and platform commercial objectives. Recommendation systems decided dwell-time weight, completion-rate weight, click-through-rate weight. Recruiting platforms decided how degree, company background, tenure, and keywords entered ranking. Users entered the system, provided data and clicks; rules were defined by the system.

The power shift in the agent era: from “system defines rules, user provides data” to “users express value-function parameters, preferences, constraints, and risk boundaries in natural language, and the agent compiles them into executable if/foreach structures that the runtime can run.”

  • A user says “screen suppliers, but prioritize eliminating delivery risk over low price” — injecting a procurement value function.
  • A user says “screen candidates, don’t use education as a rejection reason, focus on real output in chaotic environments” — rewriting the recruiting agent’s judgment boundary.
  • A user says “review this contract; the deal can move slowly, but liability transfer and data-usage boundaries need to be conservative” — defining the contract agent’s risk function.

The high-value if is the entry point through which the user’s value function enters the Runtime. The agent’s job is to compile these natural-language value orderings into schema, weights, hard constraints, human-review rules, audit fields, workflow branches, and executable tool calls. Natural language is not the endpoint. The Runtime is the endpoint. Expression is not the asset. A compiled, executed, and reviewable value function is the asset.

The intent compiler is not a shallow metaphor for “translating user speech into code.” What it truly compiles is value functions: pressing vague, implicit, trade-off-laden user intent into structures the system can execute, audit, roll back, and reuse.

No high-value if is neutral

There is no such thing as a neutral high-value if. What appears to be a “neutral tool” often simply hides its default value function.

Internet platforms make daily ifs. Who ranks first in search? What does the feed show next? Which product appears in e-commerce search? Which candidate gets exposure on the recruiting platform? These ifs look like algorithmic ranking. They are actually value ranking. The most common default value function for internet platforms has been maximizing dwell time, click-through rate, conversion rate, ad revenue, and GMV (gross merchandise volume).

Current mainstream LLMs have ifs too. When the user asks a question — give a complete answer, or admit uncertainty? When the user’s plan has problems — agree, or point it out? When the user is emotional — empathize, or encourage calm? These are not tone choices. They are value choices.

Mainstream models have established Provider-level Alignment: general behavioral norms, safety rules, preference alignment. But Provider-level Alignment cannot replace Builder-level, Domain-level, or User-level value functions. The model company defines the lowest-common-denominator behavioral boundary. Industrial agents need concrete value orderings for specific scenarios.

High-value ifs often have a trolley-problem structure: different value frameworks can be internally coherent while producing different decisions. The issue is not that the model is not smart enough. The issue is that the decision itself has no value-neutral answer.

Factual boundaries come before value functions. Factual errors are still errors. Violations of law are still violations. Safety incidents are still incidents. Facts, law, safety, and the responsibility floor cannot be rewritten by value functions. High-value ifs enter the choice space only above these floors.

A stronger model cannot define the value function for the builder

A common approach is a consultant-executor architecture: a cheaper model handles execution, consulting a stronger model at critical points. This reduces cost and improves task completion. But it solves the capability-and-cost problem, not the value-function-source problem.

The stronger model’s judgment still comes from the provider’s blended alignment and default value function. It does not automatically know what your product stands for, what your user’s authorization boundaries are, what your responsibility structure looks like, or which bottom lines you would rather lose short-term conversion to defend.

The builder’s responsibility is not to find a stronger model to make value judgments. It is to actively define: in this specific scenario, what value function governs the high-value ifs — and then ensure that regardless of which model tier is called, this value function is caught by schema, workflow, audit log, and human-approval boundaries.

Engineering solutions can optimize capability. Engineering solutions cannot assume the builder’s value-function definition authority.

An industrial agent must be delegable, auditable, reproducible, and accountable over time. This is why the LLM cannot be the final decision structure. It handles ambiguity; the runtime collapses ambiguity into schema, workflow, approval gates, and audit logs.

The engineering triad: schema, workflow, audit log

The builder cannot write a value function into an agent with slogans. Three instruments are needed:

Schema is the shape of the value function. It specifies which signals are usable, which are reference-only, which constraints are hard, which conclusions are allowed, and which judgments must escalate to human review.

Workflow is the path of the value function. If the product values long-term interest, the workflow must read a long time window. If the product opposes preference flattery, the workflow must surface opposing perspectives. If the product respects factual boundaries, the workflow must perform cross-source verification and explicitly label uncertainty. The LLM cannot skip risk enumeration because the user is in a hurry, omit alternatives because the answer sounds fluent, or pretend information is sufficient when it is not.

Audit log is the evidence of the value function. It records authorization scope, input data, model version, schema version, workflow path, human-review nodes, final action, and post-hoc remediation. An agent without audit logs cannot enter high-trust workflows: errors cannot be located, located errors cannot be explained, unexplained errors cannot be fixed, and unfixed errors cannot sustain long-term responsibility.

Schema gives the value function structure. Workflow makes it reproducible. Audit log makes it accountable.

The Value Function Spec

Every high-value if can be written as a one-page Value Function Spec: primary objective, hard boundaries, what may be sacrificed, what is never sacrificed, who receives escalation on conflict, and which output-schema fields express evidence, gaps, counter-examples, and rejection reasons. Without this spec, “intelligent judgment” is just model default bias.

Taking supplier screening as an example:

  1. Metadata: version, domain, responsible party, floor constraints. The system serves buyer procurement, not supplier exposure. Compliance, no fabricated evidence, and no hidden paid ranking are floor constraints.

  2. Objectives and dynamic weights: the primary objective is minimizing total procurement risk, not finding the cheapest supplier. Delivery reliability, quality-evidence strength, total cost of ownership, and compliance cleanliness outrank the quote. Low price is a weak signal. Buyer long-term health holds veto power.

  3. Prohibited decision factors: supplier paid exposure, platform ranking, and sales-pitch quality cannot serve as recommendation or elimination criteria.

  4. Hard constraints and escalation: high compliance risk requires human review or rejection. Missing core evidence requires supplementary materials. Amounts above the approval threshold enter Human-in-the-loop approval. Hard constraints cannot be compensated by other strengths.

  5. Output structure: finite decision enum, confidence score, evidence chain, counter-evidence, missing-information type, risk flags, next-step recommendations, and human-review flag. missing_information_type and counter_evidence must be in the output structure.

  6. Workflow and audit: the workflow enforces evidence collection, material normalization, dynamic-weight scoring, hard-constraint checking, counter-evidence generation, human-review routing, and audit writing. The audit log records value-function version, input source, model version, workflow version, overridden recommendations, missing-information types, confidence scores, and human-review records.

The engineering chain:

Thought → Schema → Workflow → Audit Log.

Thought that does not enter schema has no structure. Schema that does not enter workflow cannot be reproduced. Workflow that does not enter audit log cannot be held accountable.

A value function is not philosophical decoration. It is the judgment structure of the Agent Runtime.

Restraint as engineering discipline

A high-trust agent is defined less by what it can do than by what it refuses to do: actions it can automate but should not, revenue it can capture but should not, preferences it can flatter but should not, and ambiguity it can hide behind but should not.

Can act, but does not: capability restraint enters the workflow. A recruiting agent can auto-decide whether a candidate enters the final round, but senior positions should escalate to human review. An investment agent can auto-generate buy/sell recommendations, but decisions exceeding a percentage of user assets need human approval. A legal agent can assess contract risk, but major legal liability requires a professional’s signature. The implementation is physically inserting Human-in-the-loop approval nodes into the workflow. When contract amounts exceed the threshold, user asset exposure exceeds risk budget, or an action creates an external commitment, the process pauses and requests human approval — and this node cannot be bypassed by the model, user emotion, or commercial metrics.

Can profit, but does not: metrics restraint enters the schema’s dynamic weights. The product could add more aggressive recommendations, stronger emotional hooks, harder-to-cancel flows — all boosting short-term metrics. But a high-trust agent cannot turn user authorization into growth fuel. The implementation gives user_long_term_health, trust_preservation, and downside_risk weight or veto power that overrides short-term GMV in the schema. Once addiction risk, hidden costs, or irreversible financial loss triggers, the system stops the conversion path.

Can flatter, but does not: emotional restraint enters the workflow branch. The user wants their startup direction affirmed — the agent still points out major risks. The user wants to make an impulsive investment — the agent still opposes. The user is emotionally agitated and wants to decide immediately — the agent triggers a cooling-off period. Implementation means writing emotional-polarization detection into workflow branches. When panic, euphoria, or anger is detected and the current decision is irreversible, the system enters a cooling period, generates counter-arguments, and requires delayed confirmation.

Can obscure, but does not: responsibility restraint enters the audit log. Vague answers are safest: “both sides have a point,” “it depends,” “this is complex, consider everything.” These rarely err and rarely help. An industrial agent should give clear judgment when evidence is sufficient, explicitly acknowledge uncertainty when evidence is lacking, and explicitly escalate to human review when responsibility exceeds its boundary. Implementation means making “I don’t know” leave computational evidence: the system records decision state, missing-information type, confidence score, evidence-gap reason, and next-step action.

Restraint that stays in text gets swallowed by growth pressure. Restraint that enters schema, workflow, and audit log becomes systemic discipline.

7. The If/Foreach Ledger

Model placement ultimately needs to materialize as an if/foreach ledger.

Every agent MVP needs to maintain this ledger. It records at least eight categories:

  • Which nodes are high-value ifs, and why they cannot be handled by fields, rules, or low-trust models.
  • Which nodes are low-value ifs, and why they can be handed to programs, rules, small models, or caches.
  • Which steps are foreach, and whether they can be batched, parallelized, retried, replayed, and monitored.
  • Which ifs have already been absorbed by historical workflows and do not need re-exploration each time.
  • Which nodes need a frontier model to open the road, and which only need a mid-tier model to assist.
  • Which nodes need human approval, because the action is irreversible or responsibility cannot be automatically transferred.
  • Which successful judgments can be encoded as workflows, skills, memory, or evaluation samples.
  • Which downgrade conditions have been met, allowing expensive model calls to be moved off the critical path.

The ledger’s purpose is not documentation theater. It forces the builder to ask before every model call: is this truly incompressible uncertainty, or has the system lazily wrapped repetitive execution in an “intelligence” label?

How the ledger matures

The first time, the ledger records where the task genuinely requires judgment.

The second time, it records which judgments can be absorbed by workflows.

The third time, it records which processes have migrated from model calls to deterministic execution.

By the tenth time, the ledger starts exposing product boundaries: which judgments still need humans, which can be entrusted to models, and which actions should never be automated.

A mature Agent Runtime is not one that calls the strongest model everywhere. It is one whose ledger gets thicker over time: fewer unnecessary model calls, more hardened workflows, clearer approval gates, and a better understanding of which decisions should never be automated.

Once model placement is ledgered, value functions, low-resolution proxies, and responsibility redistribution all become engineerable problems.

Summary

The agent shift is not only a model shift. It redistributes computation, responsibility, and asset ownership.

The core concepts of this essay:

  • High-value if / low-value foreach: the model appears at judgment branches, not inside execution loops.
  • Model placement over model frequency: the key question is not how many times the model is called, but where it is placed.
  • The model opens the road, the system paves it: explore → prune → harden → evolve.
  • A schema is a boundary, not a form: the boundary of the enum is the boundary of the agent’s thought.
  • Every high-value if encodes a value function: no high-value if is neutral; someone always defines what matters more.
  • Schema / workflow / audit log: thought must enter schema to have structure, enter workflow to be reproducible, enter audit log to be accountable.
  • The if/foreach ledger: the engineering artifact that turns abstract discipline into daily practice.

An agent is, at its core, an intent compiler. The old internet compressed human intent into low-resolution SQL through forms and clicks. In the agent era, users express intent in natural language and ambiguous context. The agent’s entire job is to first identify where incompressible uncertainty exists, then compile the clarified portions into a tightly-fitted, responsibility-bounded foreach automation pipeline. The agent absorbs uncertainty at compile time. The system sprints on deterministic rails at runtime.

In the long run, whoever defines the high-value ifs controls the decision layer. Whoever controls the decision layer builds a practical form of digital sovereignty — not through owning the model, but through owning the judgment structure that the model serves.

The builder’s position comes down to this: in every specific scenario, write a clear, explainable, reproducible, and accountable value function into every high-value if.