<?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: Yamin</title>
    <description>The latest articles on DEV Community by Yamin (@yaminbinyoosuf).</description>
    <link>https://dev.to/yaminbinyoosuf</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%2F4108680%2Fa00447a9-d1d6-4145-9392-743b61e0671b.jpg</url>
      <title>DEV Community: Yamin</title>
      <link>https://dev.to/yaminbinyoosuf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yaminbinyoosuf"/>
    <language>en</language>
    <item>
      <title>I built a 12-state accountability layer for AI agents here's what I learned</title>
      <dc:creator>Yamin</dc:creator>
      <pubDate>Thu, 03 Sep 2026 20:49:01 +0000</pubDate>
      <link>https://dev.to/yaminbinyoosuf/i-built-a-12-state-accountability-layer-for-ai-agents-heres-what-i-learned-361i</link>
      <guid>https://dev.to/yaminbinyoosuf/i-built-a-12-state-accountability-layer-for-ai-agents-heres-what-i-learned-361i</guid>
      <description>&lt;p&gt;By the time you finish reading this, your AI agent will have made at least one promise it can't keep.&lt;/p&gt;

&lt;p&gt;That's not a dig at your code. It's a fundamental property of how we build AI systems today. Agents are brilliant at generating intent and terrible at tracking it. They'll promise to email a client, confirm an appointment, or deploy a fix and two conversations later, they've forgotten they said anything at all.&lt;/p&gt;

&lt;p&gt;The more I thought about this, the more I realized: &lt;strong&gt;commitments aren't a memory problem. They're a state machine problem.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So I built COGEXT — an accountability layer that sits between your agent and the outside world. You send it agent output, it extracts every commitment, and tracks each one until it's fulfilled, failed, or overdue.&lt;/p&gt;




&lt;h2&gt;
  
  
  The core idea: commitments have state
&lt;/h2&gt;

&lt;p&gt;Most systems treat agent output as text to be logged. We treat it as events to be tracked.&lt;/p&gt;

&lt;p&gt;Every extracted commitment moves through 12 states:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DETECTED
    ├──→ OPEN ──→ DUE ──→ OVERDUE ──→ FULFILLED ✓
    │                        ├──→ FAILED ✗
    │                        └──→ EXPIRED ✗
    ├──→ PENDING_REVIEW ──→ OPEN
    ├──→ CANCELLED ✗
    ├──→ CONTRADICTED ✗
    └──→ BLOCKED ──→ OPEN
                  └──→ FAILED ✗
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Terminal states: &lt;code&gt;fulfilled&lt;/code&gt;, &lt;code&gt;failed&lt;/code&gt;, &lt;code&gt;expired&lt;/code&gt;, &lt;code&gt;cancelled&lt;/code&gt;, &lt;code&gt;superseded&lt;/code&gt;, &lt;code&gt;contradicted&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;All state mutations go through a single PostgreSQL RPC function. Not direct UPDATEs from application code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="k"&gt;REPLACE&lt;/span&gt; &lt;span class="k"&gt;FUNCTION&lt;/span&gt; &lt;span class="n"&gt;cogext_transition_commitment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;p_commitment_id&lt;/span&gt; &lt;span class="n"&gt;UUID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;p_new_status&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;p_actor&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="s1"&gt;'system'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;p_data&lt;/span&gt; &lt;span class="n"&gt;JSONB&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="s1"&gt;'{}'&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;RETURNS&lt;/span&gt; &lt;span class="n"&gt;JSONB&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="err"&gt;$$&lt;/span&gt;
&lt;span class="k"&gt;BEGIN&lt;/span&gt;
    &lt;span class="c1"&gt;-- lock row → validate transition → update status → insert event → return&lt;/span&gt;
    &lt;span class="c1"&gt;-- single atomic operation: if any step fails, the whole thing rolls back&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;$$&lt;/span&gt; &lt;span class="k"&gt;LANGUAGE&lt;/span&gt; &lt;span class="n"&gt;plpgsql&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why? Because the state change and the event must be atomic. You should never have &lt;code&gt;status = 'fulfilled'&lt;/code&gt; without a corresponding fulfillment event in the audit log. That's the line between a logging system and an accountability system.&lt;/p&gt;




&lt;h2&gt;
  
  
  Extracting commitments from agent output
&lt;/h2&gt;

&lt;p&gt;The extraction pipeline has two stages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 1: Classification&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not everything an agent says is a commitment. We classify first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;genuine_commitment&lt;/code&gt; — "I will send the report by Friday."&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;intention&lt;/code&gt; — "I might send the report tomorrow."&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;suggestion&lt;/code&gt; — "We should send the report tomorrow."&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;hypothetical&lt;/code&gt; — "If we have time, I could send it."&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;quoted_statement&lt;/code&gt; — "John said he would send it."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Only &lt;code&gt;genuine_commitment&lt;/code&gt; with confidence ≥ 0.5 passes through.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stage 2: Structured extraction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We use Groq's llama-3.3-70b in JSON mode to extract fields:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;groq_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;llama-3.3-70b-versatile&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
    &lt;span class="n"&gt;response_format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;json_object&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is validated against a Pydantic schema. If the LLM returns garbage, we retry once. If it still fails, the commitment is dropped — not inserted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key decision:&lt;/strong&gt; We don't trust the LLM to interpret deadlines. We extract the raw expression ("Friday EOD") and pass it to a deterministic temporal normalizer. The LLM interprets; the code decides.&lt;/p&gt;




&lt;h2&gt;
  
  
  Evidence scoring: why 0.88 ≠ 0.92
&lt;/h2&gt;

&lt;p&gt;Evidence verification is where most systems fail. Binary matching — "does this email mention the report?" — generates too many false positives.&lt;/p&gt;

&lt;p&gt;We use a weighted field-coverage model:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Weight&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;action&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0.40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;recipient&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0.30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;object&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0.20&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;deadline&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0.10&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;When evidence arrives, we check which commitment fields it matches and sum the weights:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Evidence 1: confirms action ("I sent it")
    → 0.40

Evidence 2: confirms recipient + object ("sent to Sarah, deployment-report.pdf attached")
    → 0.30 + 0.20 = 0.50

Total = 0.90 → FULFILLED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The threshold is configurable (default 0.90). Multiple pieces of evidence can satisfy different fields — they aggregate.&lt;/p&gt;




&lt;h2&gt;
  
  
  The idempotency problem
&lt;/h2&gt;

&lt;p&gt;AI agents repeat themselves. An agent might say:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"I'll send the report by Friday."&lt;/li&gt;
&lt;li&gt;"Let me confirm: I'll send it by Friday."&lt;/li&gt;
&lt;li&gt;"Just to reiterate, I will send the report by Friday."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same commitment. Without idempotency, you'd track it three times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;compute_idempotency_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;agent_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;promise_text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;window&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;second&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;microsecond&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;agent_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;|&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;promise_text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;|&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nf"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same agent + same promise + same hour = same hash. The DB unique constraint rejects the duplicate silently.&lt;/p&gt;

&lt;p&gt;The hour window is deliberate: it deduplicates within a session while still allowing the same promise to be legitimately re-made days later.&lt;/p&gt;




&lt;h2&gt;
  
  
  The four lessons that cost us the most
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. LLM output is untrusted input.&lt;/strong&gt;&lt;br&gt;
We validate everything against Pydantic schemas before touching the database. No exceptions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Determinism over magic.&lt;/strong&gt;&lt;br&gt;
LLMs for interpretation. Deterministic code for everything else: state transitions, date normalization, deduplication, metrics. We don't call the LLM to check if a deadline is overdue. We run a database query.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Events are not logs.&lt;/strong&gt;&lt;br&gt;
A log is a record that can be ignored. An event is a fact that cannot be denied. We enforce this at the DB layer — a trigger rejects any UPDATE or DELETE on the events table. Historical events are immutable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Scope the user_id at the auth layer, never the request body.&lt;/strong&gt;&lt;br&gt;
Early version trusted &lt;code&gt;user_id&lt;/code&gt; from the request payload. Classic mistake. All scoping now comes from the API key's &lt;code&gt;account_id&lt;/code&gt;. The request body cannot claim to own data it doesn't own.&lt;/p&gt;


&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;The API is live and the SDK is on PyPI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;cogext
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;cogext&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;track&lt;/span&gt;

&lt;span class="n"&gt;agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;your_agent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cg_live_xxx&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;agent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ll send the report by Friday&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# commitment is tracked automatically
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Docs at &lt;strong&gt;docs.cogextai.com&lt;/strong&gt; — there's a quickstart that takes about 5 minutes.&lt;/p&gt;

&lt;p&gt;Would genuinely appreciate feedback from anyone who's hit this problem with their own agents. What does your current approach look like?&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>architecture</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Yamin</dc:creator>
      <pubDate>Thu, 03 Sep 2026 20:47:52 +0000</pubDate>
      <link>https://dev.to/yaminbinyoosuf/-p7b</link>
      <guid>https://dev.to/yaminbinyoosuf/-p7b</guid>
      <description></description>
    </item>
  </channel>
</rss>
