<?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: andrey-architect</title>
    <description>The latest articles on DEV Community by andrey-architect (@andreyarchitect).</description>
    <link>https://dev.to/andreyarchitect</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%2F4025380%2Fb7b5614a-552c-42fa-b96e-b3677c06053a.jpg</url>
      <title>DEV Community: andrey-architect</title>
      <link>https://dev.to/andreyarchitect</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andreyarchitect"/>
    <language>en</language>
    <item>
      <title>Deterministic serialization for multi-agent LLM sessions - 3.45x fewer tokens than JSON, up to 9.9x for non-English content</title>
      <dc:creator>andrey-architect</dc:creator>
      <pubDate>Sat, 18 Jul 2026 19:57:43 +0000</pubDate>
      <link>https://dev.to/andreyarchitect/deterministic-serialization-for-multi-agent-llm-sessions-345x-fewer-tokens-than-json-up-to-99x-3pl2</link>
      <guid>https://dev.to/andreyarchitect/deterministic-serialization-for-multi-agent-llm-sessions-345x-fewer-tokens-than-json-up-to-99x-3pl2</guid>
      <description>&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Multi-agent LLM systems -” several models exchanging messages within&lt;br&gt;
one session -” pay for context, not intelligence. Every round trip in&lt;br&gt;
natural language or verbose JSON burns tokens re-stating structured&lt;br&gt;
context that a fixed, external schema could carry in a fraction of&lt;br&gt;
the size.&lt;/p&gt;

&lt;p&gt;I got tired of watching this happen in my own pipelines, so I built a&lt;br&gt;
small serialization protocol to fix it. Sharing it here in case it's&lt;br&gt;
useful to others hitting the same wall.&lt;/p&gt;
&lt;h2&gt;
  
  
  The idea
&lt;/h2&gt;

&lt;p&gt;Move inter-agent messages from natural language / JSON to short,&lt;br&gt;
positional ASCII identifiers (&lt;code&gt;P1:A2:X0:V4&lt;/code&gt;), resolved against an&lt;br&gt;
external, versioned &lt;code&gt;dictionary.json&lt;/code&gt;. A deterministic Python layer&lt;br&gt;
handles encode/decode -” no model involved in reconstructing meaning,&lt;br&gt;
so there's no hallucination risk on the decode side.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;parts&lt;/span&gt; &lt;span class="o"&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;field_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;field_id&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fields&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;items&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;field_name&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;field_name&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="n"&gt;value_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;values&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;field_name&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;parts&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="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;field_id&lt;/span&gt;&lt;span class="si"&gt;}{&lt;/span&gt;&lt;span class="n"&gt;value_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unknown fields or values raise an explicit error instead of guessing -”&lt;br&gt;
the whole point of an external schema is that the model never has to&lt;br&gt;
improvise meaning on decode.&lt;/p&gt;

&lt;p&gt;Conceptually this is closer to &lt;strong&gt;Protocol Buffers&lt;/strong&gt; than to prompt&lt;br&gt;
engineering: a fixed contract, not a clever prompt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benchmark (real numbers, not estimates)
&lt;/h2&gt;

&lt;p&gt;Measured on &lt;code&gt;cl100k_base&lt;/code&gt; (industry-standard reference tokenizer):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Tokens&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Natural language (RU)&lt;/td&gt;
&lt;td&gt;49&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Standard JSON&lt;/td&gt;
&lt;td&gt;38&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SCP ASCII ID-stack&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3.45x fewer tokens than JSON.&lt;/strong&gt; Full reproducible benchmark script&lt;br&gt;
is in the repo -” run it yourself against your own tokenizer before&lt;br&gt;
trusting these numbers for a cost projection.&lt;/p&gt;

&lt;h2&gt;
  
  
  The finding I didn't expect
&lt;/h2&gt;

&lt;p&gt;Tokenizer vocabularies are trained predominantly on English text, so&lt;br&gt;
non-Latin scripts pay a real, measurable tax. Same sentence, same&lt;br&gt;
meaning, measured multiplier vs. the SCP ID-stack:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Multiplier vs. SCP&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;English&lt;/td&gt;
&lt;td&gt;1.89x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Russian&lt;/td&gt;
&lt;td&gt;5.11x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arabic&lt;/td&gt;
&lt;td&gt;5.56x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Japanese&lt;/td&gt;
&lt;td&gt;4.22x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hindi&lt;/td&gt;
&lt;td&gt;9.89x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Because the ID-stack costs the same regardless of source language (9&lt;br&gt;
tokens either way -” it's just ASCII after encoding), SCP's savings&lt;br&gt;
scale disproportionately for non-English multi-agent deployments.&lt;br&gt;
That's not a marketing angle, it's just what the tokenizer does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest limitations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Benchmarked on &lt;code&gt;cl100k_base&lt;/code&gt; as a common reference point. If you're
deploying against a different model family, re-run the benchmark
script against that tokenizer before relying on these numbers.&lt;/li&gt;
&lt;li&gt;Only works for structured, enumerable fields with a fixed value
space -” not open-ended free text. You still need to parse natural
language into fields first; this compresses the transport layer
between agents, not the initial NLU step.&lt;/li&gt;
&lt;li&gt;MVP, not battle-tested at scale. Looking for people to break it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Caching economics
&lt;/h2&gt;

&lt;p&gt;Anthropic and OpenAI both offer ~90% discounts on cached input tokens.&lt;br&gt;
Three conditions determine whether SCP's savings actually materialize&lt;br&gt;
in a caching setup:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;1,024-token minimum&lt;/strong&gt; -” a compact SCP dictionary alone won't
clear the cacheable threshold. Pack the schema together with the
full protocol spec into one system block.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TTL window&lt;/strong&gt; -” default cache lifetime is 5 minutes (1.25x write
cost); session rounds need to land inside that window, or use a
1-hour TTL (2x write cost) instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Byte-for-byte prefix matching&lt;/strong&gt; -” stable content (schema,
dictionary) must precede variable content (the current round), or
the cache prefix breaks on every request.&lt;/li&gt;
&lt;/ol&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python mvp/encoder_decoder.py encode &lt;span class="s1"&gt;'{"system": "Quantumoan", "version": "4", "action": "paradigm_shift", "target": "cognitive_profiles_alignment"}'&lt;/span&gt;
&lt;span class="c"&gt;# -&amp;gt; P1:V4:A2:X0&lt;/span&gt;

python mvp/encoder_decoder.py decode &lt;span class="s2"&gt;"P1:V4:A2:X0"&lt;/span&gt;
&lt;span class="c"&gt;# -&amp;gt; {"system": "Quantumoan", "version": "4", "action": "paradigm_shift", "target": "cognitive_profiles_alignment"}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Repo (AGPLv3): &lt;a href="https://github.com/andrey-architect/scp-protocol" rel="noopener noreferrer"&gt;https://github.com/andrey-architect/scp-protocol&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Would genuinely like to know where this breaks -” issues and PRs welcome.&lt;/p&gt;

</description>
      <category>agents</category>
      <category>llm</category>
      <category>performance</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
