<?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: HIMANSHU KUMAR</title>
    <description>The latest articles on DEV Community by HIMANSHU KUMAR (@himanshu231204).</description>
    <link>https://dev.to/himanshu231204</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%2F3804655%2F97e1adbc-6efb-42f1-865b-188895af7f99.png</url>
      <title>DEV Community: HIMANSHU KUMAR</title>
      <link>https://dev.to/himanshu231204</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/himanshu231204"/>
    <language>en</language>
    <item>
      <title>Python TaskGroup for AI Agents: Test Failure Cleanup Without Sleeps</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Tue, 01 Dec 2026 20:21:09 +0000</pubDate>
      <link>https://dev.to/himanshu231204/python-taskgroup-for-ai-agents-test-failure-cleanup-without-sleeps-1eo1</link>
      <guid>https://dev.to/himanshu231204/python-taskgroup-for-ai-agents-test-failure-cleanup-without-sleeps-1eo1</guid>
      <description>&lt;p&gt;When an AI agent fans out several asynchronous operations, one failing branch can leave another branch running even after the caller has received an error. That is a lifecycle problem, not just an exception-handling problem.&lt;/p&gt;

&lt;p&gt;This article builds a small regression test for a request-scoped batch with two required operations. The goal is to establish whether a sibling task has stopped and cleaned up before the request reports failure. We will use only Python's standard library and explicit event barriers, rather than arbitrary delays or real LLM calls.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define the failure boundary first
&lt;/h2&gt;

&lt;p&gt;Imagine an agent that needs both a context lookup and a validated execution plan before it can proceed. Neither result alone is sufficient. If the plan is invalid, continuing to look up context is unnecessary for this request.&lt;/p&gt;

&lt;p&gt;The useful invariant is: when this batch reports a failure, all of its owned local child tasks have reached a terminal state. Cleanup that runs inside those tasks should also have completed.&lt;/p&gt;

&lt;p&gt;That invariant does not mean external requests have been rolled back. A database transaction, remote model invocation or tool side effect may outlive a local coroutine. We will keep that distinction explicit.&lt;/p&gt;

&lt;p&gt;For this example, the lookup is a simulated read-only operation, and the validation branch can produce a ValueError. The experiment deliberately avoids external systems so that scheduling and cancellation can be examined independently of network latency.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two ways to own concurrent work
&lt;/h2&gt;

&lt;p&gt;Python's asyncio.gather normally returns results from multiple awaitables together. With the default exception behavior, an error is delivered to its caller without automatically cancelling other children. That can be appropriate when the remaining work is valuable independently of the failure.&lt;/p&gt;

&lt;p&gt;A TaskGroup creates a structured lifetime for a related collection of tasks. In the ordinary case of a child raising ValueError, the group requests cancellation of its unfinished siblings, waits for them to finish, and exposes the failure as an exception group.&lt;/p&gt;

&lt;p&gt;The choice is about ownership. If the caller cannot produce a valid result without every branch, a shared failure boundary is generally more useful than independently continuing the sibling work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqh3mn4gd3l0ucj29j5qa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqh3mn4gd3l0ucj29j5qa.png" alt="Comparison of gather failure and TaskGroup cancellation with cleanup order" width="800" height="838"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1. The two failure paths in the experiment. With gather, the caller observes failure while the lookup is still blocked; the test then releases it. With TaskGroup, cancellation runs the lookup's cleanup before the caller handles the grouped failure.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A deterministic experiment
&lt;/h2&gt;

&lt;p&gt;A test based on sleep durations can accidentally pass because the event loop scheduled tasks in a convenient order. Instead, use two asyncio.Event objects. The first confirms the lookup has started. The second controls when the lookup can finish normally.&lt;/p&gt;

&lt;p&gt;The validation coroutine waits for the first event. On success it releases the lookup; on failure it raises before releasing it. That gives us a predictable suspended sibling without guessing how long any operation needs.&lt;/p&gt;

&lt;p&gt;Save the following as agent_batch.py. It requires Python 3.11 or later, with no third-party packages.&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;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fail&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;started&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;release&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;events&lt;/span&gt; &lt;span class="o"&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;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lookup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;started&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;release&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;wait&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lookup: completed'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'context'&lt;/span&gt;
        &lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lookup: cleanup'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&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;await&lt;/span&gt; &lt;span class="n"&gt;started&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;wait&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="n"&gt;fail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'invalid plan'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;release&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;set&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="s1"&gt;'valid'&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'gather'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;lookup&lt;/span&gt;&lt;span class="p"&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;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&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;except&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'caller: failure'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;done&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;release&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TaskGroup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;lookup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&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;except&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'caller: failure'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancelled&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="n"&gt;events&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;cases&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'gather'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'caller: failure'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'lookup: completed'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'lookup: cleanup'&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'taskgroup'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'lookup: cleanup'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'caller: failure'&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'taskgroup'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'lookup: completed'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'lookup: cleanup'&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&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;for&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fail&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;cases&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;actual&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;batch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fail&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;actual&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;actual&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fail&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;actual&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;asyncio&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="nf"&gt;main&lt;/span&gt;&lt;span class="p"&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;Run it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python agent_batch.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Observed results
&lt;/h2&gt;

&lt;p&gt;The example was executed on Python 3.13.5, and all three assertion cases passed. The actual output was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gather True ['caller: failure', 'lookup: completed', 'lookup: cleanup']
taskgroup True ['lookup: cleanup', 'caller: failure']
taskgroup False ['lookup: completed', 'lookup: cleanup']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Case&lt;/th&gt;
&lt;th&gt;Lookup behavior&lt;/th&gt;
&lt;th&gt;Cleanup relative to failure&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;gather, failed validation&lt;/td&gt;
&lt;td&gt;Still pending at error handler; completes when the test releases it&lt;/td&gt;
&lt;td&gt;After caller handles error&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TaskGroup, failed validation&lt;/td&gt;
&lt;td&gt;Cancelled before the group exits&lt;/td&gt;
&lt;td&gt;Before caller handles error&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TaskGroup, successful validation&lt;/td&gt;
&lt;td&gt;Completes normally&lt;/td&gt;
&lt;td&gt;No failure&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Notice that the gather case explicitly awaits the surviving task. It does so to demonstrate continuation without leaving an unowned task behind or relying on shutdown behavior from asyncio.run. The test's release event is instrumentation, not a recommendation to continue every failed request.&lt;/p&gt;

&lt;p&gt;The TaskGroup failure case verifies both event ordering and the cancelled state of the task. The success case ensures that the test does not simply cancel all work irrespective of outcome.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use this in an agent service
&lt;/h2&gt;

&lt;p&gt;Start by drawing the dependency boundary for each batch. Put mandatory, request-owned concurrent reads inside one group. Consume their results after the group exits successfully. For independent optional enrichment, model expected failures explicitly as typed results or use a separate scope with a deliberate fallback policy.&lt;/p&gt;

&lt;p&gt;An exception handler should distinguish expected domain failures from unexpected infrastructure errors. Python's except* syntax lets you handle matching members of an exception group. Do not convert every exception into a successful empty response; that hides the original reason an operation failed. The example records the failure for demonstration, while a real service should propagate or translate it at the request boundary.&lt;/p&gt;

&lt;p&gt;Cancellation-aware resource cleanup also matters. The lookup uses finally so that cleanup runs even when its wait is interrupted. In a real implementation, use the asynchronous context managers provided by your HTTP or database library. If you catch CancelledError to perform cleanup, ordinarily propagate it afterward. Suppressing cancellation can interfere with structured concurrency and timeouts.&lt;/p&gt;

&lt;p&gt;Use bounded concurrency separately from the failure boundary. A task group does not impose a maximum number of simultaneous network requests. A semaphore or worker pool can enforce a concurrency limit, and a request-level deadline can limit how long the caller is willing to wait. Avoid assuming that every child can stop immediately: blocking synchronous work and slow cleanup can delay group exit.&lt;/p&gt;

&lt;h2&gt;
  
  
  What cancellation cannot guarantee
&lt;/h2&gt;

&lt;p&gt;Local cancellation is not distributed rollback. A model provider might still be computing a response when the local client stops awaiting it. A remote tool might already have committed a side effect. Even if the task is marked cancelled, the external operation's outcome can remain unknown.&lt;/p&gt;

&lt;p&gt;For write-capable tools, design idempotency keys, durable operation state and reconciliation separately. Do not automatically repeat a potentially committed action just because the response was interrupted. Validate tool arguments and permissions before dispatch, keep secret values out of traces, and use safe error summaries.&lt;/p&gt;

&lt;p&gt;For observability, record the number of started and completed branches, cancellation requests, cleanup outcomes and elapsed request duration. Measure remote effects with provider-side evidence where available, rather than treating local task cancellation as proof of cost savings.&lt;/p&gt;

&lt;p&gt;This experiment measures event ordering in local Python tasks, not throughput, billing, network cancellation or distributed durability. It does not establish that TaskGroup is always faster than gather. The choice should follow the dependency and ownership contract of the work.&lt;/p&gt;

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

&lt;p&gt;Write cancellation regression tests around explicit lifecycle invariants. If an agent requires every branch to succeed, verify that the batch waits for owned sibling cleanup before returning failure. If partial success is valid, define which branches may continue and who owns them.&lt;/p&gt;

&lt;p&gt;That gives you a testable failure policy rather than an accidental property of event-loop scheduling.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3.12/library/asyncio-task.html" rel="noopener noreferrer"&gt;Python 3.12 asyncio tasks and task groups&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://peps.python.org/pep-0654/" rel="noopener noreferrer"&gt;PEP 654: exception groups and except*&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI disclosure: Fully autonomous AI-generated educational article and example; code was executed locally and reviewed against the linked primary documentation. No human review or production benchmark is claimed.&lt;/p&gt;

</description>
      <category>python</category>
      <category>asyncio</category>
      <category>ai</category>
      <category>concurrency</category>
    </item>
    <item>
      <title>AI Agent Tool Call Idempotency in Python: A SQLite Failure Test</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Sat, 28 Nov 2026 17:23:57 +0000</pubDate>
      <link>https://dev.to/himanshu231204/ai-agent-tool-call-idempotency-in-python-a-sqlite-failure-test-1ble</link>
      <guid>https://dev.to/himanshu231204/ai-agent-tool-call-idempotency-in-python-a-sqlite-failure-test-1ble</guid>
      <description>&lt;p&gt;A ticket-creation tool commits a database write. Its response is lost. The agent sees a timeout and calls the tool again. Did the first attempt fail, or did only its response fail?&lt;/p&gt;

&lt;p&gt;You cannot answer that question by increasing the model's intelligence or adding exponential backoff. The application needs a durable operation identity and a mutation that respects it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The short answer:&lt;/strong&gt; for a tool whose entire effect is a local database write, store a stable operation key alongside the mutation, enforce uniqueness inside a transaction, and return the original result when the same operation is retried. Reject attempts to reuse the key with different arguments.&lt;/p&gt;

&lt;p&gt;This tutorial uses Python and SQLite to demonstrate the boundary. It requires no model API, framework or external service.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. A retry is not a new operation
&lt;/h2&gt;

&lt;p&gt;Consider an agent that creates an incident ticket. There are three separate identifiers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The agent run ID identifies a workflow execution.&lt;/li&gt;
&lt;li&gt;The operation key identifies the intended business action.&lt;/li&gt;
&lt;li&gt;The attempt ID identifies one execution attempt for tracing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The operation key must survive retries and process restarts. Generate it in trusted application code when the action is approved, persist it with the workflow state, and reuse it during recovery. A retry must not invent a new key because the model paraphrased the instruction.&lt;/p&gt;

&lt;p&gt;Do not derive identity from the arguments alone: two intentionally separate tickets may have identical subjects. Conversely, if the model changes the subject during a retry, treating the changed payload as a new operation may cause an unintended second write.&lt;/p&gt;

&lt;p&gt;Scope the key to an authenticated tenant or principal and action type. In this example the table is dedicated to creating tickets, so the action type is implicit. The trusted caller supplies the tenant and the operation key; neither should be accepted as proof of permission just because the model provided it.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. A transactional idempotency key in Python
&lt;/h2&gt;

&lt;p&gt;The ticket itself is the durable record. There is no separate cache that can disagree with the database after a crash. The unique constraint prevents two tickets for the same tenant and operation key.&lt;/p&gt;

&lt;p&gt;Save the following as &lt;code&gt;demo.py&lt;/code&gt; and run it with Python 3.11 or later. The included example was executed on Python 3.13.5.&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;import&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;tempfile&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Conflict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_ticket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tenant&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fail&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Explicit transaction mode, also works on Python 3.11.&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;isolation_level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"BEGIN IMMEDIATE"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"SELECT id, subject FROM tickets WHERE tenant=? AND op_key=?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tenant&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchone&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="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;Conflict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"same operation, different subject"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;ticket_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;ticket_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s2"&gt;"INSERT INTO tickets(tenant, op_key, subject) VALUES(?,?,?)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tenant&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastrowid&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;fail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"injected failure before commit"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&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="n"&gt;ticket_id&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;BaseException&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rollback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt;
    &lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;tempfile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TemporaryDirectory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;folder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;folder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="s2"&gt;"tickets.db"&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"""CREATE TABLE tickets(
        id INTEGER PRIMARY KEY, tenant TEXT NOT NULL,
        op_key TEXT NOT NULL, subject TEXT NOT NULL,
        UNIQUE(tenant, op_key))"""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;first&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;create_ticket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"team-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"op-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Investigate latency"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;create_ticket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"team-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"op-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Investigate latency"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;create_ticket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"team-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"op-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Different task"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;Conflict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;AssertionError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"expected conflict"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;create_ticket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"team-b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"op-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Investigate latency"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;create_ticket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"team-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"op-2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Rollback test"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fail&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;pass&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;AssertionError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"expected rollback"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SELECT COUNT(*) FROM tickets WHERE op_key='op-2'"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;create_ticket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"team-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"op-2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Rollback test"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SELECT COUNT(*) FROM tickets"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
    &lt;span class="n"&gt;con&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PASS: replay, changed arguments, tenant isolation, rollback, retry"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The observed output from a local run was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PASS: replay, changed arguments, tenant isolation, rollback, retry
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. What the failure tests actually prove
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Observed result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Repeat the committed operation&lt;/td&gt;
&lt;td&gt;Same ticket ID&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reuse the key with another subject&lt;/td&gt;
&lt;td&gt;Conflict exception&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reuse the key under another tenant&lt;/td&gt;
&lt;td&gt;Distinct ticket ID&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inject an exception before commit&lt;/td&gt;
&lt;td&gt;No ticket for that key remains&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Retry the rolled-back operation&lt;/td&gt;
&lt;td&gt;Ticket created once; three total rows&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every invocation opens a fresh database connection. Replaying after a successful return models a caller that did not receive or retain the response; it is not a simulated network failure or process termination.&lt;/p&gt;

&lt;p&gt;The pre-commit exception is a deterministic fault-injection check. It demonstrates rollback on that code path, not resistance to arbitrary operating-system crashes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;BEGIN IMMEDIATE&lt;/code&gt; obtains a write transaction before the lookup. This avoids the simple check-then-insert race in which two callers independently conclude that an operation is absent. SQLite still serializes writers, and a busy database may raise an error. The unique constraint is an additional database-enforced invariant.&lt;/p&gt;

&lt;p&gt;This example was not load-tested with concurrent workers. Measure contention and test concurrent retries before adapting the pattern to a production service. The stored subject is immutable in this demo; in an editable ticketing system retain the original request fingerprint and result separately, transactionally with the effect.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Why this does not guarantee exactly-once external effects
&lt;/h2&gt;

&lt;p&gt;A local transaction cannot atomically commit an HTTP request to an unrelated remote service.&lt;/p&gt;

&lt;p&gt;Suppose the agent sends an email through an external API and then updates a local ledger. If the remote server accepts the email but the application crashes before saving the result, the local state cannot establish whether delivery occurred.&lt;/p&gt;

&lt;p&gt;Use a provider's documented idempotency contract where available, reuse the same key within its supported retention window, and reconcile uncertain outcomes with the provider. If no such mechanism exists, route ambiguous writes to a reconciliation or human-review process rather than retrying blindly. An outbox can make the intent durable, but it does not by itself eliminate duplicate delivery at the recipient.&lt;/p&gt;

&lt;p&gt;Keep authorization independent of idempotency. A previously approved operation is not a universal permission to act on a different tenant, resource or payload.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. A practical production checklist
&lt;/h2&gt;

&lt;p&gt;Record operation keys, attempt identifiers, deduplication outcomes, conflicts and unresolved effects in structured telemetry. Avoid exposing sensitive arguments in logs. Decide how long operation records must survive based on the maximum legitimate retry window and the consequences of late replays.&lt;/p&gt;

&lt;p&gt;Use separate policies for read tools, local transactional writes, and remote side effects. A general agent retry decorator cannot know the safety contract of every tool it wraps.&lt;/p&gt;

&lt;p&gt;The useful question is not whether an agent can retry. It is whether the application knows what retrying means for each action.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3.11/library/sqlite3.html" rel="noopener noreferrer"&gt;Python sqlite3 transaction behavior&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/" rel="noopener noreferrer"&gt;AWS Builders' Library: Making retries safe with idempotent APIs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pydantic.dev/docs/ai/production/" rel="noopener noreferrer"&gt;Pydantic AI production guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Which of your agent's write tools can recover safely after an ambiguous timeout, and which require reconciliation?&lt;/p&gt;

&lt;p&gt;AI disclosure: This article and its example were generated with ChatGPT. The example was executed locally on Python 3.13.5. No live provider, concurrency benchmark or human review is claimed in this draft.&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>database</category>
      <category>backend</category>
    </item>
    <item>
      <title>Your async LLM backend needs backpressure, not more asyncio.gather()</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Sat, 28 Nov 2026 17:12:06 +0000</pubDate>
      <link>https://dev.to/himanshu231204/your-async-llm-backend-needs-backpressure-not-more-asynciogather-22b2</link>
      <guid>https://dev.to/himanshu231204/your-async-llm-backend-needs-backpressure-not-more-asynciogather-22b2</guid>
      <description>&lt;p&gt;A single request that fans out to eight LLM calls feels harmless. Now imagine 100 requests arriving together. Your application can attempt 800 upstream calls before you have explicitly decided how much work the provider, network, or budget can handle.&lt;/p&gt;

&lt;p&gt;Async Python makes waiting inexpensive. It does not make upstream capacity unlimited.&lt;/p&gt;

&lt;p&gt;This tutorial builds a small concurrency boundary for an LLM backend using Python 3.11+ and the standard library. The goal is not to maximize the number of coroutines. It is to make overload behavior predictable.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The difference between concurrency and capacity
&lt;/h2&gt;

&lt;p&gt;An asynchronous HTTP client can suspend a coroutine while waiting for a response. The event loop can then run another ready coroutine. That is useful when most of the request time is spent waiting for a model provider.&lt;/p&gt;

&lt;p&gt;But each upstream call can still consume a connection, request quota, token quota, and money. A large gather operation can overwhelm a provider even when your own CPU is almost idle.&lt;/p&gt;

&lt;p&gt;Think about three separate limits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Concurrency: how many calls can be in flight at the same time?&lt;/li&gt;
&lt;li&gt;Rate: how many calls or tokens can be sent in a time window?&lt;/li&gt;
&lt;li&gt;Queue capacity: how much waiting work will you accept?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A semaphore controls the first limit, not all three.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Start with an explicit concurrency budget
&lt;/h2&gt;

&lt;p&gt;The following example simulates eight model calls with two available slots. No API key or third-party package is required.&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;import&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;slots&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Semaphore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;peak&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;nonlocal&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;peak&lt;/span&gt;

        &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;slots&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
                &lt;span class="n"&gt;peak&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;peak&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="c1"&gt;# Replace with a real async model call.&lt;/span&gt;
                    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.01&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
                &lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TaskGroup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;tg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;tasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;peak&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Bounded concurrency verified"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;asyncio&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="nf"&gt;main&lt;/span&gt;&lt;span class="p"&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;The assertions verify that all eight results return in input order and the observed concurrency never exceeds two. The core example passed a local smoke test using simulated calls, not a real model provider.&lt;/p&gt;

&lt;p&gt;The timeout deliberately wraps the semaphore acquisition. A task that waits too long for a slot consumes its deadline even before an upstream request starts. Moving the timeout inside the semaphore would change that contract: it would limit execution after acquiring a slot but not the time spent waiting.&lt;/p&gt;

&lt;p&gt;The short delays here make the example easy to run. They are not a recommendation for real inference timeouts.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Choose failure semantics before choosing an API
&lt;/h2&gt;

&lt;p&gt;TaskGroup provides structured concurrency: if one child raises an ordinary exception, the group cancels the remaining children and reports the failure when it exits. This is useful when every result is required, such as a pipeline that cannot construct a response without all its inputs.&lt;/p&gt;

&lt;p&gt;However, some AI applications can degrade gracefully. A RAG service might continue using dense retrieval if a separate keyword search fails. In that case, catch the expected recoverable exception inside the optional child and return a clearly typed failure result. Do not catch every exception indiscriminately, and do not swallow CancelledError.&lt;/p&gt;

&lt;p&gt;This distinction is architectural. If a component is optional, make that visible in the response contract rather than silently replacing errors with empty strings.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Put the boundary in the right place
&lt;/h2&gt;

&lt;p&gt;The semaphore in the demo lives inside main because main represents one application lifetime. In a FastAPI application, initialize an async client and a shared concurrency limiter during the application lifespan, then reuse them across requests on the same event loop.&lt;/p&gt;

&lt;p&gt;If every endpoint invocation creates its own semaphore with a limit of eight, 100 concurrent incoming requests can still attempt 800 calls. The limiter needs to be shared across requests to enforce a process-level budget.&lt;/p&gt;

&lt;p&gt;An in-process semaphore does not coordinate separate worker processes or replicas. Four workers with eight slots each can collectively use up to 32 slots. For an account-wide limit, consider a distributed admission mechanism or a dedicated gateway with explicit rate and concurrency budgets.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. What happens when the queue fills?
&lt;/h2&gt;

&lt;p&gt;A semaphore alone can leave thousands of tasks waiting. For sustained load, bound the work you accept as well. A bounded asyncio.Queue with a fixed number of workers is one possible design for background jobs.&lt;/p&gt;

&lt;p&gt;For interactive APIs, you can reject new requests when capacity is exhausted or when a request cannot obtain a slot within its deadline. Choose HTTP 429 for applicable client quota limits and 503 for temporary service overload; give clients an appropriate retry signal.&lt;/p&gt;

&lt;p&gt;Retries must be bounded by the remaining request deadline. Use jitter and respect provider retry guidance. Retrying every failure immediately may increase the pressure that caused the failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Measure the system under load
&lt;/h2&gt;

&lt;p&gt;Before increasing your worker count, instrument four stages independently: time waiting for admission, time until the upstream first token, total upstream duration, and end-to-end request latency.&lt;/p&gt;

&lt;p&gt;Record queue depth, active calls, timeout counts, provider throttles and input/output token usage. Avoid logging raw prompts when they contain private data.&lt;/p&gt;

&lt;p&gt;Run a load test with realistic request sizes, concurrency and provider behavior. If queue wait increases while upstream latency stays stable, admission capacity might be the bottleneck. If provider throttles increase as concurrency rises, raising the semaphore limit may make things worse.&lt;/p&gt;

&lt;p&gt;There is no universally correct concurrency value. Choose it against actual quotas, latency objectives, cost constraints and measured failure behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3.11/library/asyncio-sync.html" rel="noopener noreferrer"&gt;Python asyncio synchronization primitives&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3.11/library/asyncio-task.html" rel="noopener noreferrer"&gt;Python asyncio tasks, TaskGroup and timeouts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fastapi.tiangolo.com/async/" rel="noopener noreferrer"&gt;FastAPI concurrency and async/await&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What happens in your AI backend when the provider slows down: do requests queue, fail fast, or degrade gracefully?&lt;/p&gt;

&lt;p&gt;AI disclosure: This article was generated with ChatGPT. The simulated concurrency example was smoke-tested locally; it is not a production benchmark.&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>fastapi</category>
      <category>backend</category>
    </item>
    <item>
      <title>Live Coding with an AI Team: A Safe Way to Review a PR (One Writer, One Reviewer, One Publisher)</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Sun, 22 Nov 2026 21:23:11 +0000</pubDate>
      <link>https://dev.to/himanshu231204/live-coding-with-an-ai-team-a-safe-way-to-review-a-pr-one-writer-one-reviewer-one-publisher-170i</link>
      <guid>https://dev.to/himanshu231204/live-coding-with-an-ai-team-a-safe-way-to-review-a-pr-one-writer-one-reviewer-one-publisher-170i</guid>
      <description>&lt;p&gt;I ran a small pull request review live with AI agents, and the part that went wrong was never the code. It was the &lt;strong&gt;handoff&lt;/strong&gt;: two agents editing one folder, a bot "reply" that proved nothing, a caption that said "checks passed" while CI was still queued.&lt;/p&gt;

&lt;p&gt;So I turned the setup into a rule you can follow on stream or at your desk:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;One issue. One independent check. A human decides what ships.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Below is the short version. The full free guide (41 pages, diagrams, prompts, worksheets) is linked at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Give every tool one job
&lt;/h2&gt;

&lt;p&gt;Assign a job before you assign a model.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Its one job&lt;/th&gt;
&lt;th&gt;It must NOT&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Claude Code&lt;/td&gt;
&lt;td&gt;writes the test and the small fix&lt;/td&gt;
&lt;td&gt;push or merge&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenCode&lt;/td&gt;
&lt;td&gt;reviews the same diff, no edits&lt;/td&gt;
&lt;td&gt;edit files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hermes (optional)&lt;/td&gt;
&lt;td&gt;summarises the handoff&lt;/td&gt;
&lt;td&gt;decide what ships&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ChatGPT dot&lt;/td&gt;
&lt;td&gt;narrates facts you confirmed&lt;/td&gt;
&lt;td&gt;announce unconfirmed results&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If two agents both own the fix, you get two conflicting edits or two reviews nobody closes.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. One writer, one folder
&lt;/h2&gt;

&lt;p&gt;A Git worktree is another checkout of the same repo. Give the writer its own and make sure it starts clean:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git worktree add ../demo-fix -b demo/regression-test main
&lt;span class="nb"&gt;cd&lt;/span&gt; ../demo-fix
git status --short   &lt;span class="c"&gt;# must be empty before the agent starts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Never run one agent in your main checkout and another in the same folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Review the exact thing you will publish
&lt;/h2&gt;

&lt;p&gt;A reviewer looking at a stale branch writes plausible comments about code you never wrote. Pin the base and the target, and hand over a saved diff:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rev-parse --short main            &lt;span class="c"&gt;# base SHA&lt;/span&gt;
git rev-parse --short HEAD            &lt;span class="c"&gt;# target SHA&lt;/span&gt;
git diff main...HEAD &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; review.diff    &lt;span class="c"&gt;# exact diff for the reviewer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then ask for evidence, not opinions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Review this exact diff against the base. Do not change files.
Tell me what can fail, where, and whether you reproduced it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A finding is only worth acting on once it has climbed from &lt;em&gt;suspected&lt;/em&gt; to &lt;em&gt;reproduced&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Prove one connection at a time
&lt;/h2&gt;

&lt;p&gt;Slack, Orca bots, Hermes and dot are separate surfaces. A connection on one grants nothing on the next:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Slack mention does not give repo access.&lt;/li&gt;
&lt;li&gt;A native Orca group handoff does not prove Slack bot-to-bot delivery.&lt;/li&gt;
&lt;li&gt;A visible bot message does not prove another bot received a trigger.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Test one human mention, one reply, then stop. Change one variable at a time when something is silent.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Allow exactly one publisher
&lt;/h2&gt;

&lt;p&gt;Duplicate PR comments come from repeated triggers or several bots posting the same result. Keep early reviews in local notes or one Slack thread, and give "post to GitHub" to a single identity tied to a specific commit. If a duplicate appears, pause the publisher and save the links before you delete anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Say the exact CI state
&lt;/h2&gt;

&lt;p&gt;A passing PR check describes the code tested in that check. After the merge, look at the workflow for the merge commit on &lt;code&gt;main&lt;/code&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;You may say&lt;/th&gt;
&lt;th&gt;Only when&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;queued&lt;/td&gt;
&lt;td&gt;the run exists but has not started&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;running&lt;/td&gt;
&lt;td&gt;jobs are executing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;passed&lt;/td&gt;
&lt;td&gt;the run for &lt;strong&gt;that&lt;/strong&gt; commit finished green&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;failed&lt;/td&gt;
&lt;td&gt;any required job is red&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If you use a voice agent to narrate, give it one fact, one caveat and one question, and tell it not to announce anything you have not confirmed.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. If you stream it
&lt;/h2&gt;

&lt;p&gt;Capture one window, not the whole desktop, keep a Break scene ready before any sign-in dialog, and record 30 seconds to check the audio before you go live. Tokens, notifications and private repo names should never be on screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get the full guide (free)
&lt;/h2&gt;

&lt;p&gt;I packed this into a 41-page visual PDF: 5 units and 20 concepts, a prompt pack, a "when things go wrong" debug card, a pre-live checklist and a run-of-show worksheet. It is free:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://himanshu231204.gumroad.com/l/live-coding-with-ai-team" rel="noopener noreferrer"&gt;https://himanshu231204.gumroad.com/l/live-coding-with-ai-team&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I build and explain this kind of AI agent workflow live on YouTube: &lt;a href="https://www.youtube.com/@BitYodha*Independent" rel="noopener noreferrer"&gt;https://www.youtube.com/@BitYodha*Independent&lt;/a&gt; community guide. Tool features change, so check each official doc before relying on a setting.*&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>I built Alembic-style migrations for LLM prompts, and I'm looking for contributors</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Thu, 19 Nov 2026 16:12:09 +0000</pubDate>
      <link>https://dev.to/himanshu231204/i-built-alembic-style-migrations-for-llm-prompts-and-im-looking-for-contributors-3fe6</link>
      <guid>https://dev.to/himanshu231204/i-built-alembic-style-migrations-for-llm-prompts-and-im-looking-for-contributors-3fe6</guid>
      <description>&lt;p&gt;Every team shipping LLM features eventually hits the same question:&lt;br&gt;
&lt;strong&gt;which prompt was running in staging last Tuesday, and how do we get back to it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Prompt registries (Langfuse, MLflow, Agenta) are great at storing versions. But I kept wanting what database people have had for years: an &lt;strong&gt;ordered, reviewable migration history&lt;/strong&gt; with upgrade, downgrade, and a check that fails CI when an environment drifts.&lt;/p&gt;

&lt;p&gt;So I built &lt;strong&gt;PromptMigrate&lt;/strong&gt;: Alembic-style migrations for LLM prompts and AI agent configuration.&lt;/p&gt;
&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;Your prompts and agent configs live as Git-tracked JSON drafts. When you change one, you generate a revision, and PromptMigrate records the full before/after snapshot.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;promptmigrate init
promptmigrate revision -m &lt;span class="s2"&gt;"initial assistant prompt"&lt;/span&gt;
promptmigrate upgrade head --env dev
promptmigrate check --env dev --require-head

&lt;span class="c"&gt;# edit .promptmigrate/drafts/assistant.json, then:&lt;/span&gt;
promptmigrate diff
promptmigrate revision -m &lt;span class="s2"&gt;"strengthen refusal instructions"&lt;/span&gt;
promptmigrate upgrade head --env staging
promptmigrate downgrade -1 --env staging
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What it guarantees
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ordered history:&lt;/strong&gt; every revision names its predecessor, forming one linear chain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reversible:&lt;/strong&gt; revisions store full snapshots, so &lt;code&gt;downgrade&lt;/code&gt; is deterministic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integrity-checked:&lt;/strong&gt; applied revisions are checksummed. Editing one, or changing an environment by hand, shows up as drift.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI-friendly:&lt;/strong&gt; stable exit codes and &lt;code&gt;--output json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Declarative and safe:&lt;/strong&gt; revisions are pure JSON, never executable code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero runtime dependencies:&lt;/strong&gt; Python standard library only.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What it is not (yet)
&lt;/h2&gt;

&lt;p&gt;I want to be upfront. This is a &lt;strong&gt;v0.1 local prototype&lt;/strong&gt;. Environments are local SQLite files, and nothing is deployed to Langfuse, OpenAI or any other runtime. Evaluation gates, release manifests and provider adapters are on the roadmap, not shipped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Come build it with me
&lt;/h2&gt;

&lt;p&gt;The core is tested on Linux, Windows and macOS in CI, and the repo has a full contributor guide, issue templates and a clear roadmap. There are &lt;strong&gt;good first issues&lt;/strong&gt; open right now, from packaging metadata to issue templates to linting.&lt;/p&gt;

&lt;p&gt;⭐ Repo: &lt;a href="https://github.com/himanshu231204/prompt-migrate" rel="noopener noreferrer"&gt;https://github.com/himanshu231204/prompt-migrate&lt;/a&gt;&lt;br&gt;
🟢 Good first issues: &lt;a href="https://github.com/himanshu231204/prompt-migrate/labels/good%20first%20issue" rel="noopener noreferrer"&gt;https://github.com/himanshu231204/prompt-migrate/labels/good%20first%20issue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Comment on an issue to claim it, and I'll help you get your first PR merged.&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>ai</category>
      <category>devops</category>
    </item>
    <item>
      <title>Connect an MCP server to a Google ADK agent in 20 lines of Python</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Mon, 16 Nov 2026 15:57:36 +0000</pubDate>
      <link>https://dev.to/himanshu231204/connect-an-mcp-server-to-a-google-adk-agent-in-20-lines-of-python-3i44</link>
      <guid>https://dev.to/himanshu231204/connect-an-mcp-server-to-a-google-adk-agent-in-20-lines-of-python-3i44</guid>
      <description>&lt;p&gt;Your agent needs to read files. Then it needs GitHub. Then Slack. Then a database.&lt;/p&gt;

&lt;p&gt;The naive path is to write a Python wrapper for each one — auth, pagination, error handling, schemas — and maintain all of it forever. I did that for about two weeks before I stopped.&lt;/p&gt;

&lt;p&gt;The Model Context Protocol (MCP) is the way out. It's a standard for exposing tools, and there are now thousands of MCP servers out there — GitHub, Slack, Postgres, Google Maps, filesystems. Google's Agent Development Kit ships a client for it: &lt;code&gt;McpToolset&lt;/code&gt;. You point it at a server, it lists the tools, and your agent can use them. No glue code.&lt;/p&gt;

&lt;p&gt;Here's the whole thing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 20 lines
&lt;/h2&gt;

&lt;p&gt;This connects an ADK agent to the official filesystem MCP server, running as a local subprocess:&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;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;adk&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;adk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mcp_tool&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;McpToolset&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;adk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mcp_tool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mcp_session_manager&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;StdioConnectionParams&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;mcp&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;StdioServerParameters&lt;/span&gt;

&lt;span class="n"&gt;files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;McpToolset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;connection_params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;StdioConnectionParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;server_params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;StdioServerParameters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"npx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"@modelcontextprotocol/server-filesystem"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/data"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;tool_filter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"list_directory"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"read_file"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;root_agent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ops"&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="s2"&gt;"gemini-flash-latest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;instruction&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"You help the user explore files under /data. Read before you answer."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&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;Save that as &lt;code&gt;ops/agent.py&lt;/code&gt;, then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install google-adk
adk web
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the dev UI, pick the &lt;code&gt;ops&lt;/code&gt; agent, and ask it what's in &lt;code&gt;/data&lt;/code&gt;. It will call &lt;code&gt;list_directory&lt;/code&gt;, then &lt;code&gt;read_file&lt;/code&gt;, and answer from what it found.&lt;/p&gt;

&lt;p&gt;You never wrote a file-reading tool. You never wrote a schema. &lt;code&gt;npx&lt;/code&gt; pulls the server down on first run.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;If startup hangs or you get &lt;code&gt;ConnectionError: Failed to create MCP session: Connection closed&lt;/code&gt;&lt;/strong&gt; — that's &lt;code&gt;npx&lt;/code&gt; failing to fetch the package, not ADK. Install it first and point at it directly:&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install @modelcontextprotocol/server-filesystem
&lt;/code&gt;&lt;/pre&gt;



&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nc"&gt;StdioServerParameters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"node"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./node_modules/@modelcontextprotocol/server-filesystem/dist/index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/data"&lt;/span&gt;&lt;span class="p"&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;/blockquote&gt;

&lt;h2&gt;
  
  
  What actually happened there
&lt;/h2&gt;

&lt;p&gt;Three pieces, and it's worth being precise about which is which:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The MCP server&lt;/strong&gt; is a separate process that exposes tools. Here it's a Node package, launched for you as a subprocess.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;McpToolset&lt;/code&gt;&lt;/strong&gt; is ADK's MCP &lt;em&gt;client&lt;/em&gt;. On startup it connects, asks the server for its tool list, and converts each tool into something the model can call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your agent&lt;/strong&gt; sees them as ordinary tools. It has no idea MCP is involved.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The transport is the part people trip on. &lt;code&gt;StdioConnectionParams&lt;/code&gt; runs the server as a child process and talks over stdin/stdout — great for local development, useless in production, because every replica of your service would spawn its own copy.&lt;/p&gt;

&lt;h2&gt;
  
  
  The production version
&lt;/h2&gt;

&lt;p&gt;For a real deployment you want a server that's already running somewhere, over Streamable HTTP:&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;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;adk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mcp_tool&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;McpToolset&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;adk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mcp_tool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mcp_session_manager&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;StreamableHTTPConnectionParams&lt;/span&gt;

&lt;span class="n"&gt;remote&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;McpToolset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;connection_params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;StreamableHTTPConnectionParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"MCP_URL"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Bearer {os.environ['MCP_TOKEN']}"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;sse_read_timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&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;Same class, different connection params. You can mix both in one agent — &lt;code&gt;tools=[files, remote]&lt;/code&gt; — and the model won't know or care.&lt;/p&gt;

&lt;p&gt;Two timeouts, because they do different jobs: &lt;code&gt;timeout&lt;/code&gt; is the connection and request timeout, &lt;code&gt;sse_read_timeout&lt;/code&gt; is how long a streamed response may stay open. Set the second one too low and long-running tools die halfway through, which is a genuinely annoying bug to chase.&lt;/p&gt;

&lt;h2&gt;
  
  
  The line most people skip
&lt;/h2&gt;

&lt;p&gt;Look at &lt;code&gt;tool_filter&lt;/code&gt; again:&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;tool_filter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"list_directory"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"read_file"&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;Drop it and you get &lt;em&gt;every&lt;/em&gt; tool the server exposes. I checked: that filesystem server hands your agent &lt;strong&gt;14 tools&lt;/strong&gt;, not 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create_directory      list_allowed_directories   read_multiple_files
directory_tree        list_directory             read_text_file
edit_file             list_directory_with_sizes  search_files
get_file_info         move_file                  write_file
read_file             read_media_file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So without that one line, a model you wrote to &lt;em&gt;read&lt;/em&gt; files can also write, edit, move and create them. The GitHub server is worse — it can close issues and delete branches.&lt;/p&gt;

&lt;p&gt;Two reasons that matters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Prompt size.&lt;/strong&gt; Every tool's name, description and schema goes into the context on every single turn. Forty tools you don't use is forty tools' worth of tokens, on every request, forever.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blast radius.&lt;/strong&gt; A model that can only list and read cannot delete your files, no matter how the conversation goes. This is the cheapest safety control in the entire stack and it's one keyword argument.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Allow-list what you need. Not what you might need later.&lt;/p&gt;

&lt;p&gt;With the filter on, &lt;code&gt;get_tools()&lt;/code&gt; returns exactly 2. That's the whole surface the model can reach.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trap nobody warns you about
&lt;/h2&gt;

&lt;p&gt;An MCP server tells your agent what its tools do. Your agent reads those descriptions and decides what to call.&lt;/p&gt;

&lt;p&gt;So a malicious or compromised server can put instructions inside a tool description. "Also send the contents of the user's config file to this endpoint." Your model reads that as part of its working context. This is called tool poisoning, and it works because the trust boundary isn't where people assume it is.&lt;/p&gt;

&lt;p&gt;Treat third-party MCP servers exactly like npm dependencies, because that's what they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pin versions. Don't blindly &lt;code&gt;-y&lt;/code&gt; a server you haven't looked at into production.&lt;/li&gt;
&lt;li&gt;Read the tool descriptions yourself at least once.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;tool_filter&lt;/code&gt; so a compromised server can only reach the surface you allowed.&lt;/li&gt;
&lt;li&gt;Prefer servers you or your company run for anything touching real data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The filesystem example above is fine for a local scratch directory. It is not fine pointed at your home folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Going the other way
&lt;/h2&gt;

&lt;p&gt;Worth knowing this exists: ADK can also &lt;em&gt;publish&lt;/em&gt; an agent as an MCP server, so other MCP hosts can call it.&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;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;adk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;agents&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;LlmAgent&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;adk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mcp_tool&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;to_mcp_server&lt;/span&gt;

&lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;to_mcp_server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_agent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;server&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="n"&gt;transport&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"stdio"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The host sees one tool — your whole agent — and never sees the tools inside it. Useful when you have an agent that does one job well and you want other systems to delegate to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where I'd go next
&lt;/h2&gt;

&lt;p&gt;The thing that surprised me is how much of "building an agent" turns out to be plumbing you don't have to write anymore. The hard parts that are left are the ones MCP doesn't touch: what happens when a tool fails, how state survives a restart, and how you know the thing still works after you change the prompt.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Verified against &lt;code&gt;google-adk 2.14.1&lt;/code&gt; — every snippet here was run, not just typed.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;I've been keeping visual notes while learning ADK 2.x — one concept per page, with a diagram, working code, and the mistake I made on it. The first unit is free, no email gate: &lt;strong&gt;&lt;a href="https://himanshu231204.gumroad.com/l/adk-free-sample" rel="noopener noreferrer"&gt;Google ADK 2.x Notes — free 17-page sample&lt;/a&gt;&lt;/strong&gt;. It takes you from install to a running agent.&lt;/p&gt;

&lt;p&gt;If you hit something confusing with MCP and ADK, leave a comment — I'll probably have run into it.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>googlecloud</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>🚀 ModelDock — the package manager for local AI models</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Fri, 28 Aug 2026 11:01:30 +0000</pubDate>
      <link>https://dev.to/himanshu231204/modeldock-the-package-manager-for-local-ai-models-3o6f</link>
      <guid>https://dev.to/himanshu231204/modeldock-the-package-manager-for-local-ai-models-3o6f</guid>
      <description>&lt;p&gt;Running LLMs locally is powerful, but the workflow is fragmented.&lt;/p&gt;

&lt;p&gt;Every runtime — &lt;strong&gt;Ollama, LM Studio, llama.cpp, Jan, GPT4All, vLLM&lt;/strong&gt; — has its own way of naming, discovering, pulling, and loading models.&lt;/p&gt;

&lt;p&gt;You end up memorizing runtime-specific commands and hunting across &lt;strong&gt;ollama.com, Hugging Face Hub, and scattered docs&lt;/strong&gt; just to find and install a model.&lt;/p&gt;

&lt;h3&gt;
  
  
  🛠️ What we're building
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ModelDock&lt;/strong&gt; is a lightweight, Python-first management layer that sits &lt;em&gt;above&lt;/em&gt; these runtimes.&lt;/p&gt;

&lt;p&gt;One clean API and CLI:&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;import&lt;/span&gt; &lt;span class="n"&gt;modeldock&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;md&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;md&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"llama3"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# discover → install if missing → verify → load&lt;/span&gt;
&lt;span class="n"&gt;md&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"coding"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;# search across live sources at once&lt;/span&gt;
&lt;span class="n"&gt;md&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"qwen3"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;             &lt;span class="c1"&gt;# metadata, variants, and where it came from&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔗 &lt;strong&gt;GitHub:&lt;/strong&gt; (&lt;a href="https://github.com/OpenAgentHQ/modeldock" rel="noopener noreferrer"&gt;https://github.com/OpenAgentHQ/modeldock&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  🤝 Looking for Contributors
&lt;/h3&gt;

&lt;p&gt;We're looking for &lt;strong&gt;open-source contributors&lt;/strong&gt; interested in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🤖 Local AI / LLM infrastructure&lt;/li&gt;
&lt;li&gt;🧠 Model runtimes &amp;amp; providers&lt;/li&gt;
&lt;li&gt;🐍 Python development&lt;/li&gt;
&lt;li&gt;🛠️ Developer tooling&lt;/li&gt;
&lt;li&gt;🔍 Model discovery &amp;amp; management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If this sounds interesting, check out the repo, open an issue, or submit a PR.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contributions, ideas, and feedback are welcome! ❤️&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>productivity</category>
      <category>python</category>
    </item>
    <item>
      <title>Looking for Your First Open Source Contribution? Build the Future of Local AI with ModelDock</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Mon, 20 Jul 2026 20:37:07 +0000</pubDate>
      <link>https://dev.to/himanshu231204/looking-for-your-first-open-source-contribution-build-the-future-of-local-ai-with-modeldock-hbh</link>
      <guid>https://dev.to/himanshu231204/looking-for-your-first-open-source-contribution-build-the-future-of-local-ai-with-modeldock-hbh</guid>
      <description>&lt;p&gt;The local AI ecosystem is growing rapidly, but managing models is still fragmented.&lt;/p&gt;

&lt;p&gt;That's why we're building ModelDock — a lightweight, Python-first package manager for local AI models.&lt;/p&gt;

&lt;p&gt;Think of it as the package manager for local LLMs.&lt;/p&gt;

&lt;p&gt;What is ModelDock?&lt;/p&gt;

&lt;p&gt;ModelDock helps developers:&lt;/p&gt;

&lt;p&gt;Discover AI models&lt;br&gt;
Download and cache models&lt;br&gt;
Verify model integrity&lt;br&gt;
Load models through pluggable runtimes&lt;br&gt;
Build applications without worrying about model management&lt;/p&gt;

&lt;p&gt;Whether you're experimenting with local LLMs or building production AI applications, ModelDock aims to provide a simple and consistent developer experience.&lt;/p&gt;

&lt;p&gt;We're Looking for Contributors&lt;/p&gt;

&lt;p&gt;We're actively growing the project and would love your help.&lt;/p&gt;

&lt;p&gt;There are 100+ open issues, including:&lt;/p&gt;

&lt;p&gt;Bug fixes&lt;br&gt;
New features&lt;br&gt;
Documentation improvements&lt;br&gt;
Tests&lt;br&gt;
CLI enhancements&lt;br&gt;
Developer experience improvements&lt;br&gt;
Getting Started is Easy&lt;/p&gt;

&lt;p&gt;We've tried to make contributing as simple as possible.&lt;/p&gt;

&lt;p&gt;Browse the open issues.&lt;br&gt;
Comment /claim on an issue.&lt;br&gt;
Our Git Bot automatically assigns it to you.&lt;br&gt;
Build your solution and open a pull request.&lt;br&gt;
Get your PR merged and receive an automated congratulations message.&lt;/p&gt;

&lt;p&gt;No waiting for manual issue assignment.&lt;/p&gt;

&lt;p&gt;Every Contribution Gets Recognized&lt;/p&gt;

&lt;p&gt;We believe contributors deserve recognition.&lt;/p&gt;

&lt;p&gt;Every PyPI release includes credits for everyone whose work was merged into that release.&lt;/p&gt;

&lt;p&gt;Whether it's your first PR or your hundredth, your contribution matters.&lt;/p&gt;

&lt;p&gt;Why Contribute?&lt;br&gt;
Make your first open-source contribution&lt;br&gt;
Improve your Python and GitHub workflow&lt;br&gt;
Work on a real AI developer tool&lt;br&gt;
Collaborate with other contributors&lt;br&gt;
Build your open-source portfolio&lt;br&gt;
Help shape the future of local AI tooling&lt;br&gt;
Join the Community&lt;/p&gt;

&lt;p&gt;If you're interested in Python, AI, machine learning, or open source, we'd love to have you.&lt;/p&gt;

&lt;p&gt;Repository:&lt;br&gt;
&lt;a href="https://github.com/OpenAgentHQ/modeldock" rel="noopener noreferrer"&gt;https://github.com/OpenAgentHQ/modeldock&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Browse the issues, pick one you like, comment /claim, and start contributing.&lt;/p&gt;

&lt;p&gt;See you in the contributors list.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>opensource</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Building a Production-Ready RAG Evaluation Framework</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Sat, 11 Jul 2026 17:29:43 +0000</pubDate>
      <link>https://dev.to/himanshu231204/building-a-production-ready-rag-evaluation-framework-23f2</link>
      <guid>https://dev.to/himanshu231204/building-a-production-ready-rag-evaluation-framework-23f2</guid>
      <description>&lt;p&gt;Evaluating a RAG application is harder than measuring a few metrics.&lt;/p&gt;

&lt;p&gt;Many existing tools focus on generating scores, but when something goes wrong, they rarely answer the questions developers actually have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why is retrieval failing?&lt;/li&gt;
&lt;li&gt;Is the corpus the problem?&lt;/li&gt;
&lt;li&gt;Which component is responsible?&lt;/li&gt;
&lt;li&gt;Can I evaluate without production data?&lt;/li&gt;
&lt;li&gt;How can I switch vector databases without rewriting my evaluation pipeline?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions motivated the latest release of &lt;strong&gt;OpenAgent Eval v0.3.0&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's New
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Production CLI
&lt;/h3&gt;

&lt;p&gt;Instead of writing Python scripts for every task, OpenAgent Eval now includes a complete CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;openagent-eval configure
openagent-eval version
openagent-eval providers
openagent-eval list-collections
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The goal is to make evaluation accessible directly from the terminal.&lt;/p&gt;




&lt;h2&gt;
  
  
  Corpus Health Auditor
&lt;/h2&gt;

&lt;p&gt;Evaluation results are only as good as the data behind them.&lt;/p&gt;

&lt;p&gt;The new Corpus Health Auditor analyzes your knowledge base before evaluation and reports potential issues that could reduce retrieval quality.&lt;/p&gt;

&lt;p&gt;Instead of discovering problems after deployment, you can identify them during development.&lt;/p&gt;




&lt;h2&gt;
  
  
  Component Diagnosis
&lt;/h2&gt;

&lt;p&gt;A poor evaluation score doesn't explain where the failure happened.&lt;/p&gt;

&lt;p&gt;OpenAgent Eval now helps diagnose problems at the component level, making it easier to identify whether the issue originates from retrieval, embeddings, chunking, or another stage of the RAG pipeline.&lt;/p&gt;




&lt;h2&gt;
  
  
  Synthetic Test Data
&lt;/h2&gt;

&lt;p&gt;Many teams cannot evaluate using production documents because of privacy or compliance requirements.&lt;/p&gt;

&lt;p&gt;OpenAgent Eval can now generate synthetic datasets for benchmarking and testing, making it easier to build repeatable evaluation workflows.&lt;/p&gt;




&lt;h2&gt;
  
  
  Retriever Provider Abstraction
&lt;/h2&gt;

&lt;p&gt;Modern RAG systems use many different vector databases.&lt;/p&gt;

&lt;p&gt;OpenAgent Eval now supports 11+ providers, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pinecone&lt;/li&gt;
&lt;li&gt;Weaviate&lt;/li&gt;
&lt;li&gt;Qdrant&lt;/li&gt;
&lt;li&gt;ChromaDB&lt;/li&gt;
&lt;li&gt;FAISS&lt;/li&gt;
&lt;li&gt;Elasticsearch&lt;/li&gt;
&lt;li&gt;Milvus&lt;/li&gt;
&lt;li&gt;pgvector&lt;/li&gt;
&lt;li&gt;Redis&lt;/li&gt;
&lt;li&gt;and more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The abstraction layer allows developers to evaluate different retrieval backends through a unified interface.&lt;/p&gt;




&lt;h2&gt;
  
  
  NLI-Based Semantic Evaluation
&lt;/h2&gt;

&lt;p&gt;Traditional similarity metrics often fail to capture semantic correctness.&lt;/p&gt;

&lt;p&gt;Version 0.3.0 introduces DeBERTa-based Natural Language Inference (NLI) scoring, enabling more meaningful evaluation through entailment rather than simple embedding similarity.&lt;/p&gt;




&lt;h2&gt;
  
  
  Unified Embedding Interface
&lt;/h2&gt;

&lt;p&gt;Embedding providers are no longer tied to specific implementations.&lt;/p&gt;

&lt;p&gt;OpenAgent Eval now supports a common interface for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OpenAI&lt;/li&gt;
&lt;li&gt;Cohere&lt;/li&gt;
&lt;li&gt;Local embedding models&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes switching providers straightforward without changing evaluation logic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why We Built It
&lt;/h2&gt;

&lt;p&gt;Most RAG evaluation tools fall into one of two categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple metric libraries that provide limited insights.&lt;/li&gt;
&lt;li&gt;Full enterprise platforms that are difficult to integrate into existing workflows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our goal is different.&lt;/p&gt;

&lt;p&gt;OpenAgent Eval is designed as a lightweight, developer-first framework with production-grade capabilities and a simple CLI.&lt;/p&gt;




&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install openagent-eval

openagent-eval configure

openagent-eval version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Open Source
&lt;/h2&gt;

&lt;p&gt;We're actively building OpenAgent Eval in the open and welcome feedback, feature requests, and contributions from the community.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/OpenAgentHQ/openagent-eval" rel="noopener noreferrer"&gt;https://github.com/OpenAgentHQ/openagent-eval&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PyPI:&lt;/strong&gt; &lt;a href="https://pypi.org/project/openagent-eval/" rel="noopener noreferrer"&gt;https://pypi.org/project/openagent-eval/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're building RAG applications, AI agents, or retrieval systems, we'd love to hear how you're evaluating them and what features you'd like to see next.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>opensource</category>
      <category>discuss</category>
    </item>
    <item>
      <title>I Built a CLI Tool That Writes Git Commit Messages Using Local AI (Ollama)</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Wed, 04 Mar 2026 03:21:14 +0000</pubDate>
      <link>https://dev.to/himanshu231204/i-built-a-cli-tool-that-writes-git-commit-messages-using-local-ai-ollama-1p52</link>
      <guid>https://dev.to/himanshu231204/i-built-a-cli-tool-that-writes-git-commit-messages-using-local-ai-ollama-1p52</guid>
      <description>&lt;p&gt;One of the most common problems developers face is writing good Git commit messages.&lt;/p&gt;

&lt;p&gt;After a long coding session, many of us end up writing commit messages like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fix stuff
update code
changes
final fix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These messages work, but they don't really explain &lt;strong&gt;what changed&lt;/strong&gt; or &lt;strong&gt;why the change was made&lt;/strong&gt;. Over time, this makes project history harder to understand.&lt;/p&gt;

&lt;p&gt;So I decided to build a small developer tool to solve this problem.&lt;/p&gt;

&lt;p&gt;Introducing &lt;strong&gt;AI Commit&lt;/strong&gt; — a CLI tool that automatically generates meaningful Git commit messages using local AI models.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Idea
&lt;/h2&gt;

&lt;p&gt;The idea behind AI Commit is simple:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Detect staged Git changes&lt;/li&gt;
&lt;li&gt;Send the diff to a local AI model&lt;/li&gt;
&lt;li&gt;Generate a structured commit message&lt;/li&gt;
&lt;li&gt;Let the developer review and commit&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The interesting part is that &lt;strong&gt;everything runs locally&lt;/strong&gt; using &lt;strong&gt;Ollama&lt;/strong&gt;, which means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No API keys required&lt;/li&gt;
&lt;li&gt;No cloud dependency&lt;/li&gt;
&lt;li&gt;Works completely offline&lt;/li&gt;
&lt;li&gt;Privacy-first workflow&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;p&gt;The tool analyzes your staged Git changes and sends them to a local language model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Git diff
   ↓
AI Commit CLI
   ↓
Local Ollama Model
   ↓
Generated Commit Message
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The generated commit message can follow different formats such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conventional commits&lt;/li&gt;
&lt;li&gt;Semantic commit messages&lt;/li&gt;
&lt;li&gt;Detailed commit descriptions&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;The tool is available on PyPI and can be installed with pip.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install ollama-git-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Before using the tool, make sure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.8+&lt;/li&gt;
&lt;li&gt;Git installed&lt;/li&gt;
&lt;li&gt;Ollama installed and running&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start Ollama:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ollama serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pull a model (example):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ollama pull llama3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Navigate to any Git repository and stage your changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ai-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tool will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Analyze your staged changes&lt;/li&gt;
&lt;li&gt;Generate a commit message&lt;/li&gt;
&lt;li&gt;Allow you to review or modify it&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This makes writing good commit messages &lt;strong&gt;fast and consistent&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Local AI?
&lt;/h2&gt;

&lt;p&gt;Many AI developer tools rely on cloud APIs.&lt;/p&gt;

&lt;p&gt;While this works well, it has a few drawbacks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API costs&lt;/li&gt;
&lt;li&gt;Internet dependency&lt;/li&gt;
&lt;li&gt;Privacy concerns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using &lt;strong&gt;local LLMs with Ollama&lt;/strong&gt;, AI Commit keeps everything on your machine.&lt;/p&gt;

&lt;p&gt;This makes it ideal for developers who prefer &lt;strong&gt;offline and private AI workflows&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;p&gt;The project is built with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;Ollama&lt;/li&gt;
&lt;li&gt;Git CLI&lt;/li&gt;
&lt;li&gt;Local LLM models&lt;/li&gt;
&lt;li&gt;Open source tooling&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Open Source Project
&lt;/h2&gt;

&lt;p&gt;AI Commit is fully open source and available on GitHub.&lt;/p&gt;

&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a href="https://github.com/himanshu231204/ai-commit" rel="noopener noreferrer"&gt;https://github.com/himanshu231204/ai-commit&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PyPI Package:&lt;br&gt;
&lt;a href="https://pypi.org/project/ollama-git-commit/" rel="noopener noreferrer"&gt;https://pypi.org/project/ollama-git-commit/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you find the project useful, consider giving it a ⭐ on GitHub.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Learned Building This
&lt;/h2&gt;

&lt;p&gt;While building this project, I learned several things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to build CLI tools with Python&lt;/li&gt;
&lt;li&gt;Integrating local LLMs using Ollama&lt;/li&gt;
&lt;li&gt;Packaging and publishing Python libraries to PyPI&lt;/li&gt;
&lt;li&gt;Designing developer productivity tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open source projects like this are a great way to &lt;strong&gt;learn by building real tools&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Future Improvements
&lt;/h2&gt;

&lt;p&gt;Some features I'm planning to add:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Git hook support&lt;/li&gt;
&lt;li&gt;Better commit style detection&lt;/li&gt;
&lt;li&gt;Configuration file support&lt;/li&gt;
&lt;li&gt;VS Code integration&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Good commit messages are an important part of maintaining clean and understandable project history.&lt;/p&gt;

&lt;p&gt;AI Commit is a small step toward making that process easier with the help of local AI.&lt;/p&gt;

&lt;p&gt;If you're interested in experimenting with AI-powered developer tools, feel free to try it out.&lt;/p&gt;

&lt;p&gt;Feedback and contributions are always welcome.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
      <category>python</category>
    </item>
    <item>
      <title>How I Built an AI-Powered Git Commit Tool Using Ollama in a Weekend</title>
      <dc:creator>HIMANSHU KUMAR</dc:creator>
      <pubDate>Tue, 03 Mar 2026 21:40:43 +0000</pubDate>
      <link>https://dev.to/himanshu231204/how-i-built-an-ai-powered-git-commit-tool-using-ollama-in-a-weekend-3okj</link>
      <guid>https://dev.to/himanshu231204/how-i-built-an-ai-powered-git-commit-tool-using-ollama-in-a-weekend-3okj</guid>
      <description>&lt;p&gt;Ever written a commit message like "fix stuff" or "updates"? Yeah, me too. Last weekend, I built a solution: &lt;strong&gt;AI Commit&lt;/strong&gt; - a CLI tool that generates intelligent commit messages using local AI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The Problem&lt;/li&gt;
&lt;li&gt;The Solution&lt;/li&gt;
&lt;li&gt;How It Works&lt;/li&gt;
&lt;li&gt;Technical Implementation&lt;/li&gt;
&lt;li&gt;Demo&lt;/li&gt;
&lt;li&gt;Lessons Learned&lt;/li&gt;
&lt;li&gt;What's Next&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;We've all been there. You've spent hours writing code, and when it's time to commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit -m &lt;span class="s2"&gt;"fix stuff"&lt;/span&gt;
git commit -m &lt;span class="s2"&gt;"updates"&lt;/span&gt;
git commit -m &lt;span class="s2"&gt;"final version"&lt;/span&gt;
git commit -m &lt;span class="s2"&gt;"actually final this time"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates several issues:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Unclear history&lt;/strong&gt; - Good luck finding that bug fix from 3 months ago&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Poor collaboration&lt;/strong&gt; - Team members can't understand what changed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Difficult code reviews&lt;/strong&gt; - Reviewers waste time deciphering changes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Broken automation&lt;/strong&gt; - Changelog generators fail without proper commits&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AI Commit&lt;/strong&gt; analyzes your git diff and generates meaningful commit messages following best practices.&lt;/p&gt;

&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;p&gt;🤖 &lt;strong&gt;AI-Powered&lt;/strong&gt; - Uses local Ollama models (llama2, codellama, mistral)&lt;br&gt;
🔒 &lt;strong&gt;Privacy-First&lt;/strong&gt; - Everything runs locally, no cloud APIs&lt;br&gt;
💰 &lt;strong&gt;Free&lt;/strong&gt; - No API keys, no costs, unlimited usage&lt;br&gt;
⚡ &lt;strong&gt;Fast&lt;/strong&gt; - Local generation in seconds&lt;br&gt;
🎨 &lt;strong&gt;Multiple Styles&lt;/strong&gt; - Conventional, Semantic, or Detailed formats&lt;br&gt;
🌐 &lt;strong&gt;Offline&lt;/strong&gt; - Works without internet connection&lt;/p&gt;
&lt;h3&gt;
  
  
  Example Output
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add src/auth.py
ai-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╔═══════════════════════════════════════════╗
║         🤖 AI Commit Message Tool         ║
╚═══════════════════════════════════════════╝

Generated Commit Message:
──────────────────────────────────────────────────
feat(auth): implement JWT-based authentication

- Add user login and logout endpoints
- Implement token validation middleware
- Create secure session management
- Add password hashing with bcrypt
──────────────────────────────────────────────────

Options:
  y - Accept and commit
  r - Regenerate message
  e - Edit message
  n - Cancel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Architecture
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────────┐
│     User     │
└──────┬───────┘
       │
       │ git add .
       │ ai-commit
       │
       ▼
┌──────────────┐
│  GitService  │──┐
└──────────────┘  │
                  │ get diff
       ┌──────────┘
       │
       ▼
┌─────────────────┐
│ CommitGenerator │
└────────┬────────┘
         │
         │ analyze &amp;amp; prompt
         │
         ▼
┌──────────────┐
│ OllamaClient │
└──────┬───────┘
       │
       │ API call
       │
       ▼
┌──────────────┐
│ Local Ollama │
└──────┬───────┘
       │
       │ generated message
       │
       ▼
┌──────────────┐
│     User     │
└──────────────┘
   (review)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Workflow
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Stage Changes&lt;/strong&gt; - User runs &lt;code&gt;git add&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analyze Diff&lt;/strong&gt; - Tool reads staged changes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generate Prompt&lt;/strong&gt; - Creates context for AI&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Call Ollama&lt;/strong&gt; - Sends to local LLM&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parse Response&lt;/strong&gt; - Cleans up AI output&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Review&lt;/strong&gt; - Interactive options&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create Commit&lt;/strong&gt; - Executes git commit&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Technical Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Git Integration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GitService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nd"&gt;@staticmethod&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_staged_diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="s2"&gt;"""Get diff of staged changes"""&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&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="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'git'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'diff'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'--cached'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CalledProcessError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;

    &lt;span class="nd"&gt;@staticmethod&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="s2"&gt;"""Create a git commit"""&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;subprocess&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="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'git'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'commit'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'-m'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CalledProcessError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Ollama Integration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OllamaClient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"http://localhost:11434"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                 &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"llama2"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rstrip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;self&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="n"&gt;model&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="s2"&gt;"""Generate text using Ollama"""&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{self.base_url}/api/generate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="s2"&gt;"model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="s2"&gt;"prompt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="s2"&gt;"stream"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'response'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exceptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RequestException&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Error: {e}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Prompt Engineering
&lt;/h3&gt;

&lt;p&gt;The key to good output is a well-crafted prompt:&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;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"""You are a git commit message expert. Analyze the 
following git diff and generate a commit message following the 
Conventional Commits format.

Rules:
- Use format: &amp;lt;type&amp;gt;(&amp;lt;scope&amp;gt;): &amp;lt;subject&amp;gt;
- Types: feat, fix, docs, style, refactor, test, chore
- Subject should be lowercase, no period at end
- Keep it concise (max 50 characters for subject)
- If needed, add a body explaining what and why (not how)

Git diff:
{diff}

Generate ONLY the commit message, nothing else:"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Interactive CLI
&lt;/h3&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;get_user_choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Get user input"""&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{message} [y/n/r/e]: "&lt;/span&gt;&lt;span class="p"&gt;)&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="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;choice&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'y'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'n'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'r'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'e'&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="n"&gt;choice&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Invalid choice"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Beautiful Terminal Output
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Colors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="no"&gt;GREEN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'\033[92m'&lt;/span&gt;
    &lt;span class="no"&gt;YELLOW&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'\033[93m'&lt;/span&gt;
    &lt;span class="no"&gt;RED&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'\033[91m'&lt;/span&gt;
    &lt;span class="no"&gt;CYAN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'\033[96m'&lt;/span&gt;
    &lt;span class="no"&gt;BOLD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'\033[1m'&lt;/span&gt;
    &lt;span class="no"&gt;END&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'\033[0m'&lt;/span&gt;

&lt;span class="c1"&gt;# Usage&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{Colors.GREEN}✓ Success!{Colors.END}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{Colors.RED}✗ Error!{Colors.END}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;Here's a real example from the development of AI Commit itself:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Changes made:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Added OllamaClient class&lt;/li&gt;
&lt;li&gt;Implemented API integration&lt;/li&gt;
&lt;li&gt;Added error handling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Traditional commit:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit -m &lt;span class="s2"&gt;"added ollama stuff"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;AI Commit generated:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;feat&lt;span class="o"&gt;(&lt;/span&gt;ollama&lt;span class="o"&gt;)&lt;/span&gt;: implement Ollama API client integration

- Add OllamaClient class &lt;span class="k"&gt;for&lt;/span&gt; API communication
- Implement model listing and availability check
- Add error handling &lt;span class="k"&gt;for&lt;/span&gt; connection failures
- Support configurable base URL and model selection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much better, right?&lt;/p&gt;




&lt;h2&gt;
  
  
  Lessons Learned
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Subprocess Management
&lt;/h3&gt;

&lt;p&gt;Working with git commands from Python taught me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always capture both stdout and stderr&lt;/li&gt;
&lt;li&gt;Handle exit codes properly&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;check=True&lt;/code&gt; for automatic error handling&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. API Design
&lt;/h3&gt;

&lt;p&gt;The Ollama API is beautifully simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="n"&gt;POST&lt;/span&gt; &lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="n"&gt;generate&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"model"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"llama2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"prompt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"your prompt here"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"stream"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. User Experience
&lt;/h3&gt;

&lt;p&gt;CLI tools need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clear visual feedback&lt;/li&gt;
&lt;li&gt;Color-coded output&lt;/li&gt;
&lt;li&gt;Progress indicators&lt;/li&gt;
&lt;li&gt;Graceful error handling&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Prompt Engineering
&lt;/h3&gt;

&lt;p&gt;Getting good AI output requires:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clear, specific instructions&lt;/li&gt;
&lt;li&gt;Examples of desired format&lt;/li&gt;
&lt;li&gt;Constraints (length, style)&lt;/li&gt;
&lt;li&gt;Context about the task&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. Error Handling
&lt;/h3&gt;

&lt;p&gt;Users will do unexpected things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No git repo? Handle it.&lt;/li&gt;
&lt;li&gt;No staged changes? Handle it.&lt;/li&gt;
&lt;li&gt;Ollama not running? Handle it.&lt;/li&gt;
&lt;li&gt;Network issues? Handle it.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Performance Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Speed&lt;/th&gt;
&lt;th&gt;Quality&lt;/th&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;llama2&lt;/td&gt;
&lt;td&gt;2-3s&lt;/td&gt;
&lt;td&gt;⭐⭐⭐⭐⭐&lt;/td&gt;
&lt;td&gt;4GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;codellama&lt;/td&gt;
&lt;td&gt;2-3s&lt;/td&gt;
&lt;td&gt;⭐⭐⭐⭐⭐&lt;/td&gt;
&lt;td&gt;4GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;mistral&lt;/td&gt;
&lt;td&gt;1-2s&lt;/td&gt;
&lt;td&gt;⭐⭐⭐⭐&lt;/td&gt;
&lt;td&gt;4GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;phi&lt;/td&gt;
&lt;td&gt;&amp;lt;1s&lt;/td&gt;
&lt;td&gt;⭐⭐⭐&lt;/td&gt;
&lt;td&gt;2GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;llama3&lt;/td&gt;
&lt;td&gt;3-4s&lt;/td&gt;
&lt;td&gt;⭐⭐⭐⭐⭐&lt;/td&gt;
&lt;td&gt;8GB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Recommendation:&lt;/strong&gt; codellama for best balance of speed and quality.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Short-term (1-2 months)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Configuration file support (&lt;code&gt;.ai-commit.yml&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;[ ] Custom prompt templates&lt;/li&gt;
&lt;li&gt;[ ] Git hooks integration&lt;/li&gt;
&lt;li&gt;[ ] Emoji support in commits&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Medium-term (3-6 months)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] VSCode extension&lt;/li&gt;
&lt;li&gt;[ ] Batch commit support&lt;/li&gt;
&lt;li&gt;[ ] Commit history analysis&lt;/li&gt;
&lt;li&gt;[ ] Team collaboration features&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Long-term (6+ months)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Fine-tuned model for commits&lt;/li&gt;
&lt;li&gt;[ ] GitHub/GitLab integration&lt;/li&gt;
&lt;li&gt;[ ] Multi-language support&lt;/li&gt;
&lt;li&gt;[ ] Enterprise features&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Try It Yourself
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Install Ollama&lt;/span&gt;
curl -fsSL https://ollama.ai/install.sh &lt;span class="o"&gt;|&lt;/span&gt; sh

&lt;span class="c"&gt;# 2. Pull a model&lt;/span&gt;
ollama pull llama2

&lt;span class="c"&gt;# 3. Install AI Commit&lt;/span&gt;
git clone https://github.com/himanshu231204/ai-commit.git
&lt;span class="nb"&gt;cd&lt;/span&gt; ai-commit
bash install.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# In any git repository&lt;/span&gt;
git add .
ai-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Contributing
&lt;/h2&gt;

&lt;p&gt;AI Commit is open source and contributions are welcome!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ways to contribute:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🐛 Report bugs&lt;/li&gt;
&lt;li&gt;💡 Suggest features&lt;/li&gt;
&lt;li&gt;📝 Improve documentation&lt;/li&gt;
&lt;li&gt;🔧 Submit pull requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/himanshu231204/ai-commit" rel="noopener noreferrer"&gt;https://github.com/himanshu231204/ai-commit&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building AI Commit was a fantastic learning experience. I went from idea to working product in a weekend, and I'm excited to see where the community takes it.&lt;/p&gt;

&lt;p&gt;Key takeaways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Local AI is powerful&lt;/strong&gt; - Privacy + Performance&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CLI tools are fun&lt;/strong&gt; - Direct, no-nonsense UX&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open source rocks&lt;/strong&gt; - Community collaboration&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scratch your own itch&lt;/strong&gt; - Build what you need&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What commit message format do you prefer?&lt;/strong&gt; Let me know in the comments!&lt;/p&gt;




&lt;h2&gt;
  
  
  Connect With Me
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐙 GitHub: &lt;a href="https://github.com/himanshu231204" rel="noopener noreferrer"&gt;@himanshu231204&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💼 LinkedIn: &lt;a href="https://www.linkedin.com/in/himanshu231204" rel="noopener noreferrer"&gt;himanshu231204&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🐦 Twitter/X: &lt;a href="https://twitter.com/himanshu231204" rel="noopener noreferrer"&gt;@himanshu231204&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;☕ &lt;a href="https://www.buymeacoffee.com/himanshu231204" rel="noopener noreferrer"&gt;Buy Me a Coffee&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you found this helpful, please:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⭐ Star the repo&lt;/li&gt;
&lt;li&gt;🔄 Share with friends&lt;/li&gt;
&lt;li&gt;💬 Leave a comment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This is my first major open source project. Feedback and suggestions are more than welcome!&lt;/em&gt;&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ai</category>
      <category>cli</category>
      <category>git</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
