<?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: Vladyslav Shapovalov</title>
    <description>The latest articles on DEV Community by Vladyslav Shapovalov (@keepalifeus).</description>
    <link>https://dev.to/keepalifeus</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3751118%2F2b479962-897e-4339-bf99-78b2b75b2ed8.jpeg</url>
      <title>DEV Community: Vladyslav Shapovalov</title>
      <link>https://dev.to/keepalifeus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/keepalifeus"/>
    <language>en</language>
    <item>
      <title>Stigmergy Pattern for Multi-Agent LLM Systems: Fewer Tokens, Lower Costs</title>
      <dc:creator>Vladyslav Shapovalov</dc:creator>
      <pubDate>Tue, 03 Feb 2026 17:30:28 +0000</pubDate>
      <link>https://dev.to/keepalifeus/stigmergy-pattern-for-multi-agent-llm-systems-80-token-reduction-2lc9</link>
      <guid>https://dev.to/keepalifeus/stigmergy-pattern-for-multi-agent-llm-systems-80-token-reduction-2lc9</guid>
      <description>&lt;p&gt;When I started building multi-agent LLM systems, I ran into a problem that seems obvious in hindsight: &lt;strong&gt;agents talking directly to each other is expensive&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Every agent-to-agent message means API calls on both sides. With 4+ agents coordinating on complex tasks, costs spiral quickly. I needed a different approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Stigmergy?
&lt;/h2&gt;

&lt;p&gt;Stigmergy is how ants coordinate without talking to each other. Instead of direct communication, they leave pheromone trails in the environment. Other ants read these trails and act accordingly.&lt;/p&gt;

&lt;p&gt;The term comes from Greek: &lt;em&gt;stigma&lt;/em&gt; (mark) + &lt;em&gt;ergon&lt;/em&gt; (work) = "work evoked by marks left in the environment."&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem with Direct Agent Communication
&lt;/h2&gt;

&lt;p&gt;In a typical multi-agent setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Agent A → message → Agent B → response → Agent A
           (API call)         (API call)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With 4 agents collaborating:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sales Agent qualifies leads&lt;/li&gt;
&lt;li&gt;Scheduler books appointments&lt;/li&gt;
&lt;li&gt;Analyst identifies patterns&lt;/li&gt;
&lt;li&gt;Coordinator orchestrates everything&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traditional approach: Coordinator asks each agent, waits for response, routes messages. &lt;strong&gt;Every interaction = 2+ API calls.&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;Instead of direct messaging, agents read and write to a &lt;strong&gt;shared environment&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;SharedState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;leads&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Lead&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;           &lt;span class="c1"&gt;// Sales writes, Scheduler reads&lt;/span&gt;
  &lt;span class="nl"&gt;appointments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Booking&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt; &lt;span class="c1"&gt;// Scheduler writes, Analyst reads&lt;/span&gt;
  &lt;span class="nl"&gt;insights&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Insight&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;     &lt;span class="c1"&gt;// Analyst writes, Coordinator reads&lt;/span&gt;
  &lt;span class="nl"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;           &lt;span class="c1"&gt;// Coordinator writes, everyone reads&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each agent:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reads only what it needs from shared state&lt;/li&gt;
&lt;li&gt;Does its work&lt;/li&gt;
&lt;li&gt;Writes results back to shared state&lt;/li&gt;
&lt;li&gt;Next agent picks up from there&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;No waiting. No back-and-forth. No routing logic.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation Pattern
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StigmergyAgent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SharedState&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;SharedState&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// 1. Read relevant data&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myInputs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;selectInputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// 2. Process (single LLM call)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myInputs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// 3. Write to shared state&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;updateState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result&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 coordinator only steps in for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conflict resolution&lt;/li&gt;
&lt;li&gt;Priority decisions&lt;/li&gt;
&lt;li&gt;Human escalation&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Results: Fewer Tokens, Lower Costs
&lt;/h2&gt;

&lt;p&gt;Before (direct communication):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Many API calls per workflow&lt;/li&gt;
&lt;li&gt;Heavy token usage on routing/coordination&lt;/li&gt;
&lt;li&gt;Bottleneck at coordinator&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After (stigmergy):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Significantly fewer API calls per workflow&lt;/li&gt;
&lt;li&gt;Tokens spent only on actual work&lt;/li&gt;
&lt;li&gt;Parallel execution possible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The reduction in token usage is substantial&lt;/strong&gt; — eliminating back-and-forth communication overhead means you're paying for actual agent work, not coordination chatter.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to Use This Pattern
&lt;/h2&gt;

&lt;p&gt;Stigmergy works best when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Agents have distinct responsibilities&lt;/li&gt;
&lt;li&gt;Work can be decomposed into stages&lt;/li&gt;
&lt;li&gt;Order of operations is somewhat flexible&lt;/li&gt;
&lt;li&gt;You need to optimize for cost&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's less suitable when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-time negotiation is required&lt;/li&gt;
&lt;li&gt;Agents need to debate/reach consensus&lt;/li&gt;
&lt;li&gt;Order of operations is strictly sequential&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Available
&lt;/h2&gt;

&lt;p&gt;I've open-sourced a production implementation using Claude API and TypeScript:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/KeepALifeUS/autonomous-agents" rel="noopener noreferrer"&gt;autonomous-agents on GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The repo includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;4 specialized agents (Sales, Scheduler, Analyst, Coordinator)&lt;/li&gt;
&lt;li&gt;Shared state management&lt;/li&gt;
&lt;li&gt;Full TypeScript implementation&lt;/li&gt;
&lt;li&gt;Production-ready architecture&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;I'm exploring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Persistent stigmergy&lt;/strong&gt;: State that survives across sessions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weighted signals&lt;/strong&gt;: Some "pheromones" matter more than others&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decay functions&lt;/strong&gt;: Old signals fade over time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Curious if others have experimented with indirect coordination patterns for LLM agents. What challenges have you faced with multi-agent systems?&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Building AI systems that actually work in production. Follow for more patterns and implementations.&lt;/em&gt;&lt;/p&gt;

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