<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: CoderBuffer </title>
    <description>The latest articles on DEV Community by CoderBuffer  (@coderbuffer).</description>
    <link>https://dev.to/coderbuffer</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4137329%2F424d8476-eca8-4068-aa83-e3bd158006a0.png</url>
      <title>DEV Community: CoderBuffer </title>
      <link>https://dev.to/coderbuffer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/coderbuffer"/>
    <language>en</language>
    <item>
      <title>How to Build a Fast Decision Layer for AI Agents with TypeSafe Jev</title>
      <dc:creator>CoderBuffer </dc:creator>
      <pubDate>Tue, 22 Sep 2026 09:46:45 +0000</pubDate>
      <link>https://dev.to/coderbuffer/how-to-build-a-fast-decision-layer-for-ai-agents-with-typesafe-jev-1ggj</link>
      <guid>https://dev.to/coderbuffer/how-to-build-a-fast-decision-layer-for-ai-agents-with-typesafe-jev-1ggj</guid>
      <description>&lt;p&gt;Most AI agent architectures use the same large language model for every task: planning, writing, tool selection, relevance checks, risk scoring, and permission gates. That works for a prototype, but it creates an expensive and difficult-to-test control loop.&lt;/p&gt;

&lt;p&gt;A large part of an agent's workload is not generation. It is decision-making over a closed set of outcomes.&lt;/p&gt;

&lt;p&gt;TypeSafe Jev is designed for that narrower job. Instead of asking a generative model to produce prose and then parsing the answer, an application asks for one of three typed decision primitives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Choice&lt;/strong&gt; — select one option from a named set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Score&lt;/strong&gt; — place an item on an ordered scale.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Noul&lt;/strong&gt; — estimate the probability that a statement is true.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This article shows how to use those primitives as a fast decision layer inside an agent, while keeping permissions, irreversible side effects, and rollback in ordinary application code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Type safety constrains the output shape. It does not guarantee that the model selected the correct answer. Production systems still need calibration, fallbacks, and observability.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A layered agent architecture
&lt;/h2&gt;

&lt;p&gt;A useful agent can be separated into four layers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Deliberation:&lt;/strong&gt; a capable generative model plans, explains, and writes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast decisions:&lt;/strong&gt; Jev routes, filters, scores, and gates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic execution:&lt;/strong&gt; application code owns permissions, side effects, and rollback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fallback:&lt;/strong&gt; a human or a stronger model handles high-risk and low-confidence cases.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This boundary makes the model replaceable while keeping the decision protocol stable.&lt;/p&gt;

&lt;p&gt;The fast layer is not the agent's brain. It is closer to the agent's reflex system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which tasks belong in a fast decision layer?
&lt;/h2&gt;

&lt;p&gt;A task is a good fit when most of the following are true:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The possible outputs can be defined before the request.&lt;/li&gt;
&lt;li&gt;The decision happens frequently.&lt;/li&gt;
&lt;li&gt;A wrong answer can be detected or safely reversed.&lt;/li&gt;
&lt;li&gt;The task requires semantic understanding but not a long explanation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Common examples include tool routing, search-result relevance, quality scoring, moderation triage, permission requests, and human-review gates.&lt;/p&gt;

&lt;p&gt;Open-ended writing, multi-file planning, and exploration with unknown outputs should remain in the generative layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example: split a compound judgment into atomic questions
&lt;/h2&gt;

&lt;p&gt;Suppose a coding agent needs to compact its context. Summarizing every old tool result can damage paths, stack locations, error codes, and command arguments. A safer alternative is to preserve user and assistant messages and make retention decisions only for paired tool calls and results.&lt;/p&gt;

&lt;p&gt;Instead of one vague prompt such as “Can I remove this history?”, ask two atomic Noul questions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;questions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;call_t3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;noul&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;instructions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Is knowing this tool call still useful?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;result_t3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;noul&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;instructions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Must the full result remain available?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Application code can combine the two probabilities into three explicit actions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;keepResult&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;resultThreshold&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keep&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;keepCall&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;callThreshold&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;drop_result&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;drop_call&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model estimates semantic value. Deterministic code decides what the system actually does.&lt;/p&gt;

&lt;p&gt;That separation matters. It prevents a probabilistic component from silently owning destructive behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve structure before asking the model
&lt;/h2&gt;

&lt;p&gt;Before sending anything to Jev, structure the agent history in code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pair each tool call with its result by ID.&lt;/li&gt;
&lt;li&gt;Pin the first message and the most recent messages.&lt;/li&gt;
&lt;li&gt;Build only the state needed for the current judgment.&lt;/li&gt;
&lt;li&gt;Batch independent decisions when the state budget is limited.&lt;/li&gt;
&lt;li&gt;Remove calls and results as a pair so the transcript never contains orphaned entries.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This also reduces the amount of context sent to the decision model. A fast decision layer should not receive the full agent transcript by default.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use progressive degradation, not random deletion
&lt;/h2&gt;

&lt;p&gt;When the decision state exceeds its token budget, degrade it in a predictable order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Shorten long tool arguments.&lt;/li&gt;
&lt;li&gt;Keep the head and tail of long text values.&lt;/li&gt;
&lt;li&gt;Replace old messages with explicit omission markers.&lt;/li&gt;
&lt;li&gt;Merge consecutive old calls only as a last resort.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Every degradation stage should emit metrics. If the system has to collapse old messages on 70% of requests, the state builder—not the model—may be the real bottleneck.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calibrate confidence with your own data
&lt;/h2&gt;

&lt;p&gt;Example thresholds such as 0.5 or 0.8 explain control flow; they are not production defaults.&lt;/p&gt;

&lt;p&gt;A better rollout process is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run the Jev decision in &lt;strong&gt;shadow mode&lt;/strong&gt; without changing behavior.&lt;/li&gt;
&lt;li&gt;Store the question version, model version, probability, proposed action, and actual outcome.&lt;/li&gt;
&lt;li&gt;Label a representative sample.&lt;/li&gt;
&lt;li&gt;Measure observed accuracy by probability band.&lt;/li&gt;
&lt;li&gt;Select thresholds based on error cost and reversibility.&lt;/li&gt;
&lt;li&gt;Fall back to the original path on timeouts, malformed responses, or low confidence.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For read-only actions, automation may be acceptable after validation. For reversible actions, uncertainty should usually preserve the original state. For deletion, payments, access revocation, or other irreversible effects, Jev should never be the only authority.&lt;/p&gt;

&lt;h2&gt;
  
  
  Jev vs structured output, tool calling, and classifiers
&lt;/h2&gt;

&lt;p&gt;These techniques overlap, but they solve different problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LLM + JSON Schema&lt;/strong&gt; is useful for infrequent, complex judgments that require explanation. It still pays the cost and latency of a full generation path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tool calling&lt;/strong&gt; is a good fit for actions in the main agent loop, but the choice is still made by a generative model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Traditional classifiers&lt;/strong&gt; are excellent for stable labels with enough training data. They can be cheap and local.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Jev&lt;/strong&gt; fits frequent, closed, semantically rich, and recoverable decisions where you want typed outcomes and probabilities without a prose-generation step.&lt;/p&gt;

&lt;p&gt;The right architecture may use all four.&lt;/p&gt;

&lt;h2&gt;
  
  
  The reusable pattern
&lt;/h2&gt;

&lt;p&gt;The most important lesson is not a specific threshold or compaction algorithm. It is the interface between probabilistic judgment and deterministic control:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Generation expresses → judgment routes → code executes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Structure the object first. Split compound judgments into atomic questions. Combine probabilities in code. Keep side effects behind deterministic policy. Preserve a complete fallback.&lt;/p&gt;

&lt;p&gt;That pattern applies far beyond context compaction: tool routing, content moderation, search reranking, permission gates, quality checks, and escalation decisions can all use the same boundary.&lt;/p&gt;

&lt;p&gt;For the complete architecture diagram, rollout checklist, and a deeper context-compaction case study, read the full guide: &lt;a href="https://www.jev-tutorial.org/guides/agent-decision-layer" rel="noopener noreferrer"&gt;Build an Agent Decision Layer with Jev&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Further reading:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.jev-tutorial.org/tutorials" rel="noopener noreferrer"&gt;TypeSafe Jev learning path&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jev-tutorial.org/guides/choice-score-noul" rel="noopener noreferrer"&gt;Choice, Score, and Noul guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jev-tutorial.org/guides/confidence-thresholds" rel="noopener noreferrer"&gt;Confidence threshold guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Disclosure: AI-assisted editing was used to adapt and condense the original engineering guide. The structure, examples, links, and technical claims were reviewed before publication.&lt;/em&gt;&lt;/p&gt;

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