<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Dilbagh’s Tech Blog]]></title><description><![CDATA[Dilbagh’s Tech Blog]]></description><link>https://dilbagh.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 24 Nov 2026 12:19:04 GMT</lastBuildDate><atom:link href="https://dilbagh.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The five correction layers]]></title><description><![CDATA[How I make AI agents write code and docs to my standard without reading every line.]]></description><link>https://dilbagh.hashnode.dev/the-five-correction-layers</link><guid isPermaLink="true">https://dilbagh.hashnode.dev/the-five-correction-layers</guid><category><![CDATA[AI]]></category><category><![CDATA[agents]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[documentation]]></category><dc:creator><![CDATA[Dilbagh Singh Bakshi]]></dc:creator><pubDate>Sat, 21 Nov 2026 17:52:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6accbb5c56b381afc40caa7e/b0d1aeaf-4ac3-47fc-acad-028d616527fb.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>A bug that became a lint rule</h2>
<p>On Sept 21<sup>st</sup> an agent was testing the Fork scenario on a deployed copy of the Playground, the example app that runs every karmi feature against a real model. A Fork copies a conversation (a Thread) so that it can go another way. Upload worked. The model's reply worked. Then "Fork the Thread" failed with an HTTP 500.</p>
<p>The cause was small. A Fork copied the Thread's whole event log in one SQL <code>INSERT</code>. A Durable Object refuses a statement with more than 100 bound values, and each event row binds five. So any log longer than 20 events could not be forked. A real model streams many small events, and the run that failed had 137 of them. The tests had only ever used short logs, so they all passed.</p>
<p>The fix was to write the log in batches. If the PR had stopped there, the same mistake would have been waiting in every other query that writes a list of unknown length. An agent copies what it sees in the codebase. One day it would write that query again.</p>
<p>So the same PR added a second commit. It put the limit in one helper, <code>boundBatches()</code>, and added a lint rule that refuses the risky shape. This is the rule, from the public repo:</p>
<pre><code class="language-js">const boundValues =
  "One SQL statement of a Durable Object binds at most 100 values. Split the list with boundBatches() from db/bound-values.ts.";

/** A list of unknown length must not reach one SQL statement, because each entry binds a value. */
export const boundValuesSyntax = [
  {
    selector:
      "CallExpression[callee.property.name='values'] &gt; :matches(ArrayExpression:has(SpreadElement), CallExpression[callee.property.name=/^(map|slice|filter|flatMap)$/]).arguments",
    message: boundValues,
  },
  // ...the same check for inArray() and notInArray()
];
</code></pre>
<p>The message is written for the next agent. It says what the limit is and where the fix lives. No one has to remember this bug, because ESLint remembers it.</p>
<h2>Five ways to correct an agent</h2>
<p>That bug touched three of the five places where I correct an agent. Lauren Tan describes these five correction layers in <a href="https://x.com/poteto/status/2102050467505430555">her talk on shipping with coding agents</a>. She ranks them by how little each one depends on someone reading a prompt. Here is how they look on karmi.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6accbb5c56b381afc40caa7e/3cc14566-c78f-44f5-8f98-ee7644487fea.png" alt="Five boxes in a row, strongest first: architecture, static analysis, rules, human review and verification. A dotted arrow runs from verification to a bug, &quot;A Fork of a long Thread fails on the deployed Playground&quot;. A thick arrow runs from the bug back to static analysis, labelled &quot;fix, then a lint rule so it cannot come back&quot;." style="display:block;margin:0 auto" />

<h3>1. Architecture: make the wrong thing impossible</h3>
<p>The strongest correction is code where the bad pattern cannot be written at all.</p>
<p>karmi serves many customers from one deployment, and each customer's data lives under a Scope. If an agent could build a storage name by hand, a single typo could leak one customer's data into another's. So user code never builds a storage name. One internal <code>keys</code> module mints every Durable Object name and storage key, and you can reach it only through the <code>karmi.scope(id)</code> handle. <a href="https://github.com/dsblabs/karmi-oss/blob/main/docs/adr/0001-scope-name-based-isolation.md">ADR 0001</a> is blunt about the cost. A bug in <code>keys</code> is a cross-tenant bug, so the module gets tests of its own.</p>
<p>The same idea runs through the rest of the core. Every Durable Object reads and writes storage through a typed db layer built on Drizzle. A Thread's state comes from one event log, so there is one source of truth. An agent working inside these modules has one obvious path, and it is the right one.</p>
<h3>2. Static analysis: fail the build, not the reviewer</h3>
<p>Some rules cannot live in the architecture, so the build enforces them.</p>
<p>The first batch came from a review I asked for on Sept 11<sup>th</sup>, a week into coding. I asked an agent to read the whole TypeScript codebase and list the bad habits that repeated. It found twelve. There were 127 lines longer than 160 characters, 40 error codes typed as loose strings in mixed casing, and unchecked casts in many places. I asked for tooling that blocks whatever tooling can block, and short guidelines for the rest.</p>
<p>That PR added Prettier, shared ESLint rules (no non-null assertions, no double casts, no <code>JSON.parse(...) as T</code>, no function over 60 lines) and a typed union of error codes, so a made-up code fails the type check. The first version grandfathered the 54 existing violations. I asked for every one of them to be fixed before merge instead, and only one commented exception stayed. The header of the guardrails file still sets the terms for the next rule. Existing violations get grandfathered, and then they are fixed, never added to.</p>
<p>More rules followed. On Sept 14<sup>th</sup> JSDoc became required on every export, and the same PR wrote the 310 missing blocks. On Sept 19<sup>th</sup>, after storage moved to Drizzle, a rule started to block raw SQL outside the db modules.</p>
<h4>Docs are code too</h4>
<p>Agents wrote nearly all of karmi's docs too, and prose drifts the same way code does. So the docs go through the same layer.</p>
<p>The writing rules are based on the rules of ASD-STE100, a controlled English standard from aerospace maintenance manuals (not its dictionary). Sentences stay short, each word has one meaning, and verbs are active. Vale runs those rules in CI. The rule I like most is generated. karmi's glossary marks words to avoid for each domain term, and a script turns those marks into a Vale rule. If a doc says "background task", CI fails and asks for "Job". If it says "cron job", it asks for "Schedule". The docs cannot slowly invent a second vocabulary.</p>
<p>Getting there took some tuning. The first version also banned single words such as "run" and "function", and that gave 191 false hits in the live docs. Now the rule matches only multi-word phrases. Sentence length and passive voice are warnings, not errors, because "the Turn is parked" is the clearest way to name a state.</p>
<p>The rest of CI checks the docs as well. lychee checks every relative link and anchor. A script type-checks each of the 61 TypeScript samples in the guide against the built packages. A generated <code>llms.txt</code> index of the docs must match the guide, or CI fails.</p>
<h3>3. Rules: guidance an agent can skip</h3>
<p>Some standards are matters of judgement, and a linter cannot check them. Those go into written rules: a principles file for every contributor, plus guides for writing, comments and TypeScript. My favourite line in the principles file asks contributors to "fight for the smallest model that makes the correct behavior unsurprising".</p>
<p>I kept these files short and general. The first draft of the TypeScript guide was full of karmi's own type names and file paths. I had it rewritten as plain TypeScript practice with no project names in it.</p>
<p>Rules sit in the middle because an agent can skip them. A rule works only if the agent reads it and follows it. The 100-value limit from the Fork bug went into the TypeScript guide and into a lint rule. Only the lint rule is sure to be read.</p>
<h3>4. Human review: find the gaps</h3>
<p>Agent PRs were reviewed on two axes. Does it follow the repo's standards? Does it do what the ticket asked for? The review findings were fixed in follow-up commits on the same PR before merge, and commits titled "review fixes" appear all through the history.</p>
<p>Review does not scale, and I don't want it to be the thing that keeps the codebase clean. I think its real job is to find gaps in the layers above it. A finding that comes back twice belongs in a lint rule or a guide, not in a third review comment.</p>
<h3>5. Verification: prove it on the real thing</h3>
<p>The last layer proves the behaviour. The test kit runs the real runtime against a scripted model, so tests need no model and no credential. The Playground runs every feature against real providers, locally and in a temporary deployment.</p>
<p>The Fork bug shows why both are needed. The test kit was green, and the Playground still found the bug, because a real model sends more events than a test script does. Verification found it. A lint rule now prevents it.</p>
<h2>What it gave me</h2>
<p>My review time went to design, not to style. I did not have to point out a long line, a loose cast or a doc that said "cron job", because the build had already rejected them. When I read a PR, I read it for whether the idea was right.</p>
<p>It also made agent-written docs safe to publish without reading every line twice. The 16-page guide reads as if one careful person wrote it, because the same rules checked every page.</p>
<h2>What it cost</h2>
<p>The guardrails came late. For the first week of code nothing stopped a bad habit from spreading, and by Sept 11<sup>th</sup> twelve of them repeated across the codebase. One PR fixed them, but I would add a formatter and the strict lint rules on day one next time.</p>
<p>Not every check ran on every machine. The prose linter and the link checker were not installed where some agents worked, so for those PRs the checks ran only in CI. CI still enforced them before merge, but an agent found out later than it could have.</p>
<p>And the strong layers are code that I maintain. The term rule needed tuning, the move to Drizzle took two days of PRs, and every new lint rule needs a fix for each existing violation. That cost is worth it to me, because I pay it once. A correction in a chat window costs me again every session.</p>
<h2>Put the correction where the agent will meet it</h2>
<p>When an agent gets something wrong, ask where the correction should live. If you put it in the chat, it lasts one session. If you put it in a guide, the agent can skip it. If you put it in a lint rule, a type or the architecture, every later session meets it whether or not it reads anything. Start at the strongest layer that can hold it.</p>
<hr />
<p><strong>Code:</strong> <a href="https://github.com/dsblabs/karmi-oss">github.com/dsblabs/karmi-oss</a>. The guardrails file is <a href="https://github.com/dsblabs/karmi-oss/blob/main/eslint.guardrails.js"><code>eslint.guardrails.js</code></a>.</p>
<p><strong>Previous:</strong> <a href="https://dilbagh.hashnode.dev/trust-before-parallelism">Trust before parallelism</a>. <strong>Next:</strong> coming soon</p>
<p>What correction do you keep repeating to your agents? Tell me in the comments, and I'll tell you which layer I would put it in.</p>
]]></content:encoded></item><item><title><![CDATA[Trust before parallelism]]></title><description><![CDATA[Opening more AI agents didn't make me faster. Trusting them did.]]></description><link>https://dilbagh.hashnode.dev/trust-before-parallelism</link><guid isPermaLink="true">https://dilbagh.hashnode.dev/trust-before-parallelism</guid><category><![CDATA[AI]]></category><category><![CDATA[agents]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[Productivity]]></category><category><![CDATA[TypeScript]]></category><dc:creator><![CDATA[Dilbagh Singh Bakshi]]></dc:creator><pubDate>Mon, 16 Nov 2026 18:19:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6accbb5c56b381afc40caa7e/857d7969-c0d7-4d34-ac14-ba4c5cd950bd.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>One PR at a time</h2>
<p>Talk about AI coding agents often turns into a count. How many agents do you run at once? For karmi, the honest answer is one stream of work. From the first code on Sept 4<sup>th</sup>; to the end of the feature build on Sept 17<sup>th</sup>, at most one PR was open at any moment. Each one merged before the next one opened, one to five a day.</p>
<p>The count hides a plainer question. Would a second agent actually make me faster, or would it just give me twice as much output I did not yet trust? An agent whose work I had to check line by line, whose shortcuts I had to catch in review, and whose context I had to rebuild at the start of every session would not save me time. Two of them would make it worse. More junk PRs, more regressions to clean up, more of me in the middle.</p>
<p>Lauren Tan puts this as "trust before parallelism" in <a href="https://x.com/poteto/status/2102050467505430555">her talk</a>, and that ordering is what I followed on karmi. I spent my effort on making one agent trustworthy enough to take a ticket from "ready" to "merged" while I was away from the keyboard. Parallelism is the next step that trust allows. I have not taken it here yet, and this article does not pretend otherwise.</p>
<h2>Context could not live in my head</h2>
<p>karmi is too big for one agent session. A session forgets everything when it ends, and the next one starts empty. If the context lives in a chat window, or in my memory, then I become the only connection between sessions. I would copy an error from one session into the next. I would explain the same design decision for the third time because the new session had never heard it. I would remember why a ticket was blocked, and the agent would not.</p>
<p>I never did that relay work on karmi. From the start, the issue tracker was the relay, and it was also the shared memory. If a decision mattered, it went on a ticket as a comment. If it was not written there, it did not count as decided.</p>
<p>That rule sounds like overhead on a hobby project with one person in it. It paid off because the other reader was always a new agent session that knew nothing. Any session could rebuild the context by reading issues. If a session died halfway through a piece of work, the next one read the same comments and carried on. My place was outside that loop. I chose the destination, answered hard questions, and made the calls that were mine to make.</p>
<h2>A week of charting before code</h2>
<p>The first week produced no product code at all. Charting ran from Aug 28<sup>th</sup> to Sept 3<sup>rd</sup> in GitHub Issues. Matt Pocock's <a href="https://github.com/mattpocock/skills/tree/main/skills/engineering/wayfinder">wayfinder</a> skill drove the planning. The idea behind it is older than AI agents. Get to a shared understanding before you write code, and write that understanding down where everyone can read it.</p>
<p>The chart was one "map" issue naming the destination and listing the decisions made so far. Each open question became a child ticket. Research, a grilling session, a spike, a prototype: 38 tickets in all, with 20 research notes and the first architecture decision records behind them. An agent took one ticket, resolved it, and wrote the result back as a comment.</p>
<p>By the time code started, those tickets held 68 comments. They fall into a few clear shapes.</p>
<ul>
<li>Resolutions record what was decided and link the research note behind it. The scheduling ticket, for example, was grilled on Aug 30<sup>th</sup>. Its resolution decided that the scheduler is one internal module that shares the single alarm a Durable Object has. Then the map was updated.</li>
<li>Handoffs carry a decision to another open ticket it affects, as a comment that starts with a line such as "Input from". When the sub-agent design settled that a child conversation's approval request shows up on the parent, a comment on the approvals ticket said so, and said that the approvals ticket owns how it renders. There are 16 of these. Each one is a message I would otherwise have carried by hand.</li>
<li>Blockers are rarer. A few times an agent needed something only I could give, such as a credential with the right access. It did not guess. It wrote "Blocked on a human step", said what it needed, and stopped.</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/6accbb5c56b381afc40caa7e/22156681-4ab4-4393-8951-a7ed24f35777.png" alt="A loop on the issue tracker: a new agent session reads the map and its ticket, does the work, the guardrails check it, and the session writes a decision or handoff comment back to the ticket. The next session starts from that comment. The author sits outside the loop and does the charting, slicing and review." style="display:block;margin:0 auto" />

<p>The expensive thinking happened once, in the open, and every later session could reuse it. I never had to repeat a decision to make it real.</p>
<h2>Tickets outside the repo, decisions inside it</h2>
<p>The tickets never went into the repo. Only the decisions that outlived them did, as architecture decision records (ADRs) in <code>docs/adr</code>.</p>
<p>A ticket is working state: an open question, a debate, a handoff, a blocker. Once it closes, it is history, and some of it is no longer true. Agents treat whatever sits in the codebase as the pattern to follow. Put old tickets there, and an agent will read a superseded idea as current truth.</p>
<p>An ADR records a decision that lasts, and why it was made, next to the code it shapes. It is versioned and reviewed with that code. When the decision changes, a new ADR replaces it; nobody edits the old one away. <a href="https://github.com/dsblabs/karmi-oss/blob/main/docs/adr/0004-forks-copy-their-media.md">ADR 0004</a>, for example, explains why a Fork copies its media: deleting the original Thread used to turn a Fork's images and files into placeholders.</p>
<h2>Tickets an agent could finish without me</h2>
<p>On Sept 4<sup>th</sup> I sliced the spec into 29 tickets marked ready for an agent. Each ticket had the same shape: what to build, acceptance criteria as a checklist, and the tickets it was blocked by. The first one was a tracer bullet, a single text Turn of a conversation run end to end before any tool, provider or HTTP work. It merged the same day.</p>
<p>A ticket like that is a contract. The agent did not need to ask me what "done" meant, because the ticket said it. It did not need to ask what came before, because the blocking tickets were closed and their decisions were sitting in comments. I could read a ticket, decide it was clear, and walk away.</p>
<h2>Guardrails that corrected the agent before I did</h2>
<p>Clear tickets were not enough. An agent that knows what to build can still build it badly. It can reach for a shortcut, copy a pattern I wanted gone, or throw an error nobody can handle. If I had to catch all of that in review, I would be back in the middle again, this time as a relay for my own standards.</p>
<p>So I put the standards where the agent would meet them without me. On Sept 11<sup>th</sup> one PR added a formatter, lint guardrails, typed error codes and a set of TypeScript guidelines for agents. It fixed every existing violation in the same change. Here is part of the lint config, from the public repo:</p>
<pre><code class="language-js">// Lint guardrails shared by every package. A new rule that meets
// existing violations grandfathers them with `eslint --suppress-rule`; fix them, never add to them.

/** Rejects direct use of a Durable Object's raw SQL execution escape hatch. */
export const rawSqlExecSyntax = {
  selector:
    "CallExpression[callee.type='MemberExpression'][callee.property.name='exec'][callee.object.type='MemberExpression'][callee.object.property.name='sql']",
  message: "Use the owning db module instead of calling storage.sql.exec directly.",
};
</code></pre>
<p>The useful part is the <code>message</code>. It tells the agent where the right path is. When an agent wrote raw SQL, the lint run failed, the agent read the message and moved the query into the db module. I was not in that exchange at all. The correction happened between the agent and the codebase, and it happened the same way every time.</p>
<p>The typed error codes did the same for failures. An error that karmi gives to a caller is a <code>KarmiError</code> with a stable, dotted code such as <code>thread.busy</code> or <code>scope.destroyed</code>. A new failure adds its code to one list first, and the type checker rejects a code that is not on the list. An agent could not make up a new code on the spot, and a caller can switch on the code instead of parsing a message.</p>
<p>Four feature PRs merged the same day as the guardrails: offline delivery of replies and approvals, the AI SDK provider adapter, Compaction and Fork, and Skills with deferred tool loading. Most of the v0 tickets closed over the following week, and the last one closed on Sept 19<sup>th</sup>.</p>
<p>Lint is only one way to correct an agent. Rules, review and verification each do a share of the work, and a later article goes through all of them.</p>
<h2>What it gave me</h2>
<p>One person shipped the whole v0 ticket set without losing control of the quality. Over the life of the project that came to about 120 PRs. Nearly every commit was co-written with an AI coding agent. Most of the implementation happened while I did something else.</p>
<p>It also changed what my time went to. I did not spend it re-explaining decisions, copying output between sessions, or chasing style in review. I spent it on the work that was mine: charting the design, answering hard questions in grilling sessions, slicing the spec, and reviewing the result. I could get out of the agent's way because the context and the standards were written down where it could reach them.</p>
<h2>What it cost, and what is missing</h2>
<p>One PR at a time is slow in wall-clock terms. Some tickets on karmi had no dependency on each other and could have run side by side. They did not.</p>
<p>Writing everything down costs effort too. A comment for every decision only pays off if it gets read again. On karmi it was, by every session that started empty.</p>
<p>And I have not proven the parallel step here. I believe the same tracker, tickets and guardrails would carry several agents at once, because none of them depend on me being in the middle. But belief is not evidence, and I will only claim it once I have run it.</p>
<h2>Start with one agent you can trust</h2>
<p>If you want more output from coding agents, look first at where you sit in the loop. If every session needs you to restate the context, a second agent doubles that load. The same goes for every shortcut you catch in review.</p>
<p>On karmi I took myself out of the middle first. The context went on tickets, the tickets said what "done" meant, and the codebase corrected the agent before I had to. Only after one agent could finish without me would a second one be a small step.</p>
<hr />
<p><strong>Code:</strong> <a href="https://github.com/dsblabs/karmi-oss">github.com/dsblabs/karmi-oss</a></p>
<p><strong>Previous:</strong> <a href="https://dilbagh.hashnode.dev/why-i-built-a-serverless-agent-harness">Why I built a serverless agent harness</a>. <strong>Next:</strong> <a href="https://dilbagh.hashnode.dev/the-five-correction-layers">The five correction layers</a></p>
<p>If you work with coding agents, I'd like to know where you are still the relay. Tell me in the comments.</p>
]]></content:encoded></item><item><title><![CDATA[Why I built a serverless agent harness]]></title><description><![CDATA[What an agent harness looks like when an idle agent costs nothing]]></description><link>https://dilbagh.hashnode.dev/why-i-built-a-serverless-agent-harness</link><guid isPermaLink="true">https://dilbagh.hashnode.dev/why-i-built-a-serverless-agent-harness</guid><category><![CDATA[AI]]></category><category><![CDATA[agents]]></category><category><![CDATA[Cloudflare Workers]]></category><category><![CDATA[TypeScript]]></category><category><![CDATA[serverless]]></category><category><![CDATA[Open Source]]></category><dc:creator><![CDATA[Dilbagh Singh Bakshi]]></dc:creator><pubDate>Sat, 31 Oct 2026 17:58:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6accbb5c56b381afc40caa7e/87e0ae55-4677-41ec-b8f7-9f8efd7c5610.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>The question</h2>
<p>It started with a question. How could people who aren't technical use a full agent harness without installing anything on their computer?</p>
<p>By a full agent harness I mean the class of tool that Claude Code, Codex and pi belong to. The model gets tools, runs in a loop, asks a person before it does something risky, and keeps going until the work is done. These tools are very good. They also run as a process on one machine, and most of them expect a terminal. That rules out most people.</p>
<p>The obvious answer is to put the harness on a server. That works. But an always-on server costs money even when nobody uses it, and agents are idle most of the time. They wait for a person to reply, for an approval, or for a scheduled time. I had built serverless software before, so I wanted the serverless version. You pay for the seconds the agent works and nothing for the hours it waits.</p>
<p>So I looked for something that ran a full harness serverless. I didn't find anything I could rely on.</p>
<p>The closest I'd used was Mastra on AWS Lambda. Mastra is a good framework. It just wasn't built for this setting. In my experience the cold starts were slow, long runs hit Lambda timeouts or behaved in ways I could not trust, and many features were restricted when the storage was DynamoDB. Any flow Mastra did not support needed a lot of tinkering and a deep knowledge of the framework.</p>
<p>AWS Lambda has a hard limit of 15 minutes per invocation (<a href="https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html">AWS Lambda quotas</a>). An agent that waits a day for an approval does not fit in 15 minutes, so the loop has to move into another service, such as Step Functions, and you carry its state yourself. Mastra's docs say, as of October 2026, that its DynamoDB adapter cannot store observability traces, that items are capped at 400 KB (an image attachment can go over that), and that you must provision the table and its indexes yourself (<a href="https://mastra.ai/reference/storage/dynamodb">Mastra DynamoDB reference</a>). Observational Memory does not support DynamoDB at all (<a href="https://mastra.ai/docs/memory/observational-memory">Mastra Observational Memory</a>). The cold starts and the unreliable long runs are only my experience, so I won't put numbers on them.</p>
<p>The <a href="https://developers.cloudflare.com/agents/">Cloudflare Agents SDK</a> came closest. Durable Objects are a much better fit for agents than functions with a time limit. But when I looked in late August 2026, the SDK was pre-1.0 and had breaking changes inside minor versions. It created its own storage tables and stored the AI SDK's message types, so my data model would follow its choices. It also had no concept of separate customers, and I wanted isolation between customers to be part of the data model from the first line.</p>
<p>I decided to build beside it instead of on it, and to borrow its patterns where they fit.</p>
<h2>The second reason</h2>
<p>The first reason was curiosity. The second was simpler: I wanted to prove to myself that I could build it. Alone, as a hobby, working with AI coding agents.</p>
<p>An agent harness is not a small project. It has a model loop, tool calls, approvals, recovery after a crash, streaming to clients, sandboxed code and tests that do not need a real model. I wanted to know if one person who works carefully with agents could ship all of that without losing control of the quality. Later articles in this series answer that question.</p>
<h2>What karmi is, and what it isn't</h2>
<p>karmi is a TypeScript framework for agent products that serve many customers. You write Agents and Tools in code. karmi runs them on Cloudflare Workers, and you operate no servers.</p>
<p>karmi defines its own primitives. A <strong>Scope</strong> is one customer, or any boundary you want to keep data inside. Every Agent, conversation and secret belongs to exactly one Scope, and no operation crosses Scopes. A <strong>Thread</strong> is one conversation with one Agent. A <strong>Turn</strong> is one round of work inside a Thread: input arrives, the model thinks and calls tools, and the Turn ends with a reply.</p>
<p>This is the smallest karmi Worker:</p>
<pre><code class="language-ts">import { createKarmi, defineAgent, defineTool } from "@karmi/core";
import { z } from "zod";

const weather = defineTool({
  name: "weather",
  description: "The current weather in a city",
  input: z.object({ city: z.string() }),
  annotations: { readOnlyHint: true, openWorldHint: true },
  execute: ({ city }) =&gt; `It is sunny in ${city}.`,
});

const concierge = defineAgent({
  agentId: "concierge",
  name: "Concierge",
  instructions: [{ text: "You are a hotel concierge." }],
  model: { id: "anthropic/claude-sonnet-5" },
  tools: ["weather"],
});

const karmi = createKarmi({ catalogue: { tools: [weather], agents: [concierge] } });

export const { ThreadDO, ScopeConfigDO, MemoryDO, KnowledgeDO } = karmi.durableObjects;
export default { queue: karmi.queueHandler };
</code></pre>
<p>One Tool with a typed input, one Agent that may call it, and <code>createKarmi</code> to put them together. The exports at the bottom are the Durable Object classes that hold Threads, Scope settings, Memory and Knowledge. Cloudflare creates and stops those objects for you.</p>
<p>What karmi isn't matters just as much:</p>
<ul>
<li>It isn't a hosted platform. You deploy it to your own Cloudflare account.</li>
<li>It runs only on Cloudflare Workers. Storage and execution sit behind interfaces, so a second runtime is possible, but I haven't built one.</li>
<li>It has no auth, sign-up, billing or channel integrations. Your app maps each request to a Scope and a user. karmi records usage per customer so you can bill, but the billing is yours.</li>
</ul>
<h2>From a process to a state machine</h2>
<p>A harness on a laptop is a long-running process. The conversation lives in memory, and if the process dies, you start again.</p>
<p>Serverless does not give you that. Cloudflare can stop a Durable Object at any time. So in karmi each Thread is one Durable Object, and its event log is the only source of truth. A Turn runs as a series of Steps, and each Step is written to the log before the next one starts. When a Turn must wait for a person to approve a tool call, it parks. A parked Turn uses no compute. When the answer arrives, the Thread wakes and reads its log to know where it was. After a restart it does the same thing, and an interrupted tool call runs again only if the Tool is marked safe to run twice.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6accbb5c56b381afc40caa7e/5d60d188-94a7-4962-ae77-3bc1a579eb7b.png" alt="A client talks to a Worker, which routes to a Thread Durable Object. The Thread appends to and replays an event log, calls the model provider one Step at a time, and parks with no compute while it waits for an Approval." style="display:block;margin:0 auto" />

<p>So the harness is a state machine, and its state is the log. This is also what makes "an idle agent costs nothing" true. A later article goes deep on how it works and what was hard.</p>
<h2>Seven weeks, in phases</h2>
<p>These are the phases, taken from the repo history.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6accbb5c56b381afc40caa7e/0853e7d2-8e83-431b-bfdf-133c0c8a4c48.png" alt="Timeline from repo creation on 2026-08-21 to open source on 2026-10-11: a week of charting, spec and tracer bullet on 2026-09-04, feature build, guardrails, timing races fixed, docs, Playground, live acceptance on 2026-09-24, fixes on 2026-10-04." style="display:block;margin:0 auto" />

<p>Two things stand out to me when I look at it.</p>
<p>First, a full week of charting with no product code. From Aug 28<sup>th</sup> to Sept 3<sup>rd</sup>, I worked through 38 tickets of research, design questions and small spikes. I wrote a glossary of domain terms, the first architecture decision records and research notes. The choice to build beside the Cloudflare Agents SDK came out of that week.</p>
<p>Second, what happened on Sept 4<sup>th</sup>, the first day of code. The spec was sliced into 29 small tickets. The same day, a tracer bullet worked: one text Turn, end to end, through the real Thread, before any Tool, provider adapter or HTTP route existed. Everything after that was added to a path that already worked.</p>
<p>The way I work rests on Matt Pocock's agent skills, and on the older ideas those skills encode: shared understanding before code, a ubiquitous language, tracer bullets and thin slices, feedback loops and deep modules. Later articles explain that process, one idea at a time.</p>
<h2>The scale</h2>
<table>
<thead>
<tr>
<th>Item</th>
<th>Count</th>
</tr>
</thead>
<tbody><tr>
<td>Packages</td>
<td>6, plus the Playground example app</td>
</tr>
<tr>
<td>TypeScript source, not tests</td>
<td>about 23,000 lines</td>
</tr>
<tr>
<td>Test code</td>
<td>about 19,000 lines</td>
</tr>
<tr>
<td>User guide pages</td>
<td>16</td>
</tr>
<tr>
<td>Architecture decision records</td>
<td>7</td>
</tr>
</tbody></table>
<p>Nearly every commit was co-written with AI coding agents. My job was the charting, the slicing, the review and the decisions. Their job was to implement one ticket at a time and prove it worked. How I made that safe is the subject of a future article.</p>
<h2>What it costs</h2>
<p>karmi runs only on Cloudflare. I chose that on purpose. A Durable Object is one single-threaded object per Thread with its own storage, which is exactly the shape a conversation needs. But if Cloudflare isn't an option for you, karmi isn't either.</p>
<h2>What comes next</h2>
<p>The rest of this series goes into both halves of the story. Some articles go deeper into karmi itself: how a Thread survives a restart, and how it keeps customers apart. The others are about how I work with AI coding agents: why I didn't run many agents at once until I could trust their output, how I keep agent-written code and docs to my standard, and how I check that the result works.</p>
<hr />
<p><strong>Code:</strong> <a href="https://github.com/dsblabs/karmi-oss">github.com/dsblabs/karmi-oss</a></p>
<p><strong>Previous:</strong> none, this is the first article. <strong>Next:</strong> <a href="https://dilbagh.hashnode.dev/trust-before-parallelism">Trust before parallelism</a></p>
]]></content:encoded></item></channel></rss>