<?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: O-O1112</title>
    <description>The latest articles on DEV Community by O-O1112 (@o-o1112).</description>
    <link>https://dev.to/o-o1112</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%2F4076898%2Fd4838dcb-87c9-4707-8201-c726d84ae222.png</url>
      <title>DEV Community: O-O1112</title>
      <link>https://dev.to/o-o1112</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/o-o1112"/>
    <language>en</language>
    <item>
      <title>Block Engine 2.2.6: Design Notes, Runtime Boundaries, and Known Limitations</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Sun, 30 Aug 2026 01:07:47 +0000</pubDate>
      <link>https://dev.to/o-o1112/block-engine-226-design-notes-runtime-boundaries-and-known-limitations-28jo</link>
      <guid>https://dev.to/o-o1112/block-engine-226-design-notes-runtime-boundaries-and-known-limitations-28jo</guid>
      <description>&lt;h1&gt;
  
  
  Block Engine 2.2.6: Design Notes, Runtime Boundaries, and Known Limitations
&lt;/h1&gt;

&lt;p&gt;Block Engine is a Windows-oriented program that parses documents containing multiple language sections. It executes those sections sequentially and transfers selected serializable values between processes.&lt;/p&gt;

&lt;p&gt;The project does not implement Python, JavaScript, Lua, PHP, or SQL. Those sections are passed to locally installed runtimes. Block provides the document parser, execution order, state serialization, process control, and error reporting around them.&lt;/p&gt;

&lt;p&gt;This article describes the implementation in version 2.2.6. It focuses on the execution model, the changes made in this release, the security boundaries, and the limitations that remain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Execution model
&lt;/h2&gt;

&lt;p&gt;A Block document is divided into explicit language sections:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;py&amp;gt;
numbers = [1, 2, 3]
total = sum(numbers)
&amp;lt;/py&amp;gt;

&amp;lt;js&amp;gt;
console.log("total:", total)
&amp;lt;/js&amp;gt;

&amp;lt;json&amp;gt;
{
  "total": {{total}}
}
&amp;lt;/json&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The engine performs these stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Parse the document and identify language boundaries.&lt;/li&gt;
&lt;li&gt;Validate tags, imports, edition rules, paths, and configured limits.&lt;/li&gt;
&lt;li&gt;Execute each stage using the corresponding local runtime.&lt;/li&gt;
&lt;li&gt;Capture output and serializable state.&lt;/li&gt;
&lt;li&gt;Make the resulting state available to the next stage.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The runtimes do not share memory directly. State crosses the process boundary through a serialized representation. Primitive values, arrays, and dictionaries are the intended interchange types. Open file handles, sockets, callbacks, and live database connections cannot be transferred.&lt;/p&gt;

&lt;p&gt;This model makes the boundary visible, but it also makes the boundary real. A failure can belong to the Block parser, the process runner, the host runtime, or the user program inside that runtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  The native Block layer
&lt;/h2&gt;

&lt;p&gt;Block also contains a small native interpreter. It is separate from the embedded language sections and is used for orchestration logic.&lt;/p&gt;

&lt;p&gt;The native layer currently supports variables, expressions, strings, numbers, booleans, lists, maps, conditions, loops, functions, return values, and basic collection operations.&lt;br&gt;
&lt;/p&gt;

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

for value in range(1, 6):
    total = total + value
block

if total &amp;gt; 10:
    print("result:", total)
else:
    print("result is small")
block
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compound statements use an explicit &lt;code&gt;block&lt;/code&gt; terminator. Indentation is for readability; it is not the scope mechanism.&lt;/p&gt;

&lt;p&gt;This is enough for control flow around a pipeline, but it is not intended to reproduce the full syntax or standard library of another programming language.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed in 2.2.6
&lt;/h2&gt;

&lt;p&gt;Version 2.2.6 is primarily a stability and security release.&lt;/p&gt;

&lt;p&gt;Project discovery and relative imports were changed so that a script can be started from outside its project directory while retaining the project and sandbox boundaries. Imported files are checked for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allowed Block source extensions&lt;/li&gt;
&lt;li&gt;Project or configured sandbox membership&lt;/li&gt;
&lt;li&gt;Reparse-point escapes&lt;/li&gt;
&lt;li&gt;Circular imports&lt;/li&gt;
&lt;li&gt;Maximum import depth&lt;/li&gt;
&lt;li&gt;Maximum imported file count&lt;/li&gt;
&lt;li&gt;Aggregate size limits&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Process timeout handling was changed to wait on the actual child process and to terminate the process tree when the limit is exceeded. This is important for interpreters that create child processes of their own.&lt;/p&gt;

&lt;p&gt;The no-argument CLI path is now bounded. It displays an introduction and help information instead of entering an unbounded startup animation. Console cursor and color state are restored when startup encounters an exception or an unsupported console.&lt;/p&gt;

&lt;p&gt;Configuration, project manifests, custom-runtime definitions, and runtime state now have size limits. Writes use a safer replacement sequence and preserve the previous valid file when replacement is interrupted or unavailable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installer and supply-chain boundaries
&lt;/h2&gt;

&lt;p&gt;The 2.2.6 installer is a verified bootstrapper for the official GitHub release assets. It:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requires TLS 1.2 for GitHub communication&lt;/li&gt;
&lt;li&gt;Restricts download endpoints to the expected GitHub chain&lt;/li&gt;
&lt;li&gt;Checks the final response URI&lt;/li&gt;
&lt;li&gt;Enforces response and asset size limits&lt;/li&gt;
&lt;li&gt;Verifies SHA-256 values&lt;/li&gt;
&lt;li&gt;Rejects unsafe archive paths&lt;/li&gt;
&lt;li&gt;Installs files atomically&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The installer does not automatically run Winget, Chocolatey, PowerShell download scripts, or another package manager. Optional runtimes must be installed from their official publishers and made available on &lt;code&gt;PATH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This choice has a practical consequence: installing Block does not mean that PHP, Ruby, Dart, R, or other optional runtimes are installed. The installer can report that a runtime is missing, but it does not silently modify the host environment.&lt;/p&gt;

&lt;p&gt;The release includes checksums and GitHub build-provenance attestations. These provide evidence about artifact consistency and build origin. They do not replace an Authenticode publisher certificate, so an unsigned Windows executable may still receive a new-file reputation warning from Windows or a browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error reporting
&lt;/h2&gt;

&lt;p&gt;The engine uses structured diagnostics for many failures. Messages include an error code, an operation or context, a source location where available, and a repair hint.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mismatched or unclosed language tags&lt;/li&gt;
&lt;li&gt;Import paths outside the project boundary&lt;/li&gt;
&lt;li&gt;Circular imports&lt;/li&gt;
&lt;li&gt;Unknown language tags&lt;/li&gt;
&lt;li&gt;Disabled runtimes&lt;/li&gt;
&lt;li&gt;Missing host executables&lt;/li&gt;
&lt;li&gt;Invalid state output&lt;/li&gt;
&lt;li&gt;Runtime timeouts&lt;/li&gt;
&lt;li&gt;Oversized input or output&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The distinction between a missing host runtime and a Block syntax error is intentional. Block can report the former, but it cannot provide the runtime or its packages.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the release does not provide
&lt;/h2&gt;

&lt;p&gt;2.2.6 does not include a general-purpose compiler, an independent virtual machine, or a large standard library. Most language blocks still depend on tools installed on the host operating system.&lt;/p&gt;

&lt;p&gt;It also does not include the earlier third-party package marketplace or automatic package installation. Those parts were removed because a package system needs a separate trust model: publisher identity, immutable versioned artifacts, dependency rules, review policy, and a defined installation boundary.&lt;/p&gt;

&lt;p&gt;There is no claim here that arbitrary Block files are safe to execute. A language block can invoke a local interpreter, compiler, shell, or other executable. Users should review source files and dependencies before running them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verification
&lt;/h2&gt;

&lt;p&gt;The v2.2.6 release workflow builds the Windows artifacts in a clean runner and runs the engine, CLI, path, native-language, server, security, repository-integrity, and release-verification tests.&lt;/p&gt;

&lt;p&gt;The tests verify the behavior covered by the repository. They do not prove that every installed version of every external runtime behaves identically, and they do not replace review of the Block program being executed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Current position
&lt;/h2&gt;

&lt;p&gt;Block is best understood as a native orchestration language with polyglot execution support.&lt;/p&gt;

&lt;p&gt;Its own language layer defines document structure and a limited control-flow vocabulary. The embedded sections retain the syntax and capabilities of their respective runtimes. The main design question is therefore not whether Block replaces each language, but whether a visible, bounded process and state boundary is useful for a given workflow.&lt;/p&gt;

&lt;p&gt;The source code, tests, release artifacts, and version history are available in the &lt;a href="https://github.com/O-O1112/Block_lang" rel="noopener noreferrer"&gt;Block_lang repository&lt;/a&gt;. The published v2.2.6 files are listed in the &lt;a href="https://github.com/O-O1112/Block_lang/releases/tag/v2.2.6" rel="noopener noreferrer"&gt;GitHub release&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>opensource</category>
      <category>python</category>
    </item>
    <item>
      <title>[Python/JS/C#] Block Language 2.2.0: Run Polyglot Workflows in One Document</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Sat, 22 Aug 2026 04:39:12 +0000</pubDate>
      <link>https://dev.to/o-o1112/pythonjsc-block-language-220-run-polyglot-workflows-in-one-document-1e80</link>
      <guid>https://dev.to/o-o1112/pythonjsc-block-language-220-run-polyglot-workflows-in-one-document-1e80</guid>
      <description>&lt;p&gt;I got tired of writing small glue programs around otherwise simple workflows.&lt;/p&gt;

&lt;p&gt;Python was the right tool for data preparation. JavaScript was the right tool for formatting and application logic. Sometimes Lua, PHP, SQLite, or a systems language was the right tool for another stage.&lt;/p&gt;

&lt;p&gt;The annoying part was not using multiple languages.&lt;/p&gt;

&lt;p&gt;The annoying part was keeping all the boundaries between them alive:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;temporary JSON files;&lt;/li&gt;
&lt;li&gt;local HTTP endpoints;&lt;/li&gt;
&lt;li&gt;duplicated serialization code;&lt;/li&gt;
&lt;li&gt;shell scripts that quietly became the real application;&lt;/li&gt;
&lt;li&gt;and several files that had to be opened just to understand one workflow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Coming from a visual block-coding mindset, I kept thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Why can’t I write the native blocks in one document and let the variables flow through an explicit pipeline?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I built &lt;strong&gt;Block Language&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 The Problem: Glue Code Becomes the Project
&lt;/h2&gt;

&lt;p&gt;A small data workflow can require a surprising amount of ceremony:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;prepare values in Python;&lt;/li&gt;
&lt;li&gt;serialize them to disk;&lt;/li&gt;
&lt;li&gt;start another process;&lt;/li&gt;
&lt;li&gt;parse the file in JavaScript;&lt;/li&gt;
&lt;li&gt;format the result somewhere else;&lt;/li&gt;
&lt;li&gt;remember which file is the current source of truth.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Block keeps the runtime boundary visible while making the execution plan a single readable file.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡ How Block Works
&lt;/h2&gt;

&lt;p&gt;A Block file is a sequence of native language blocks. The C# orchestrator parses the file, runs each stage through its local runtime, and prepares compatible state for the next stage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;py&amp;gt;
name = "Block"
values = [2, 4, 6, 8]
total = sum(values)
&amp;lt;/py&amp;gt;

&amp;lt;js&amp;gt;
const average = total / values.length;
console.log(`[Node.js] ${name}: total=${total}, average=${average}`);
&amp;lt;/js&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;h1&amp;gt;{{name}} result&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;Total: {{total}}&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Average: {{average}}&amp;lt;/p&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python still runs through Python. JavaScript still runs through Node.js. Block coordinates the order and the state transfer; it does not try to emulate either language.&lt;/p&gt;

&lt;h2&gt;
  
  
  💻 Running the Example
&lt;/h2&gt;

&lt;p&gt;Save the file as &lt;code&gt;demo.blk&lt;/code&gt; and run it with the Standard engine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;demo.blk&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The corresponding host runtimes must be installed locally. Block is an orchestrator, not a bundle containing every language runtime.&lt;/p&gt;

&lt;p&gt;The console output is intentionally simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Node.js] Block: total=20, average=5
[HTML] Output written to -&amp;gt; ...\block_output.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same model works with Lite (&lt;code&gt;.blkl&lt;/code&gt;) and Plus (&lt;code&gt;.blkp&lt;/code&gt;) when the project needs a smaller or broader runtime surface.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔗 Native Syntax Is Also Available
&lt;/h2&gt;

&lt;p&gt;Not every workflow needs a second runtime. Standard Block files can use native variables and control flow directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;score = 80
if score &amp;gt;= 60:
    result = "pass"
else:
    result = "retry"
block
print(result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





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

&lt;/div&gt;



&lt;p&gt;This makes Block useful for small scripts as well as polyglot pipelines.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Key Features in 2.2.0
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One readable entry point:&lt;/strong&gt; keep the execution plan in one &lt;code&gt;.blkl&lt;/code&gt;, &lt;code&gt;.blk&lt;/code&gt;, or &lt;code&gt;.blkp&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shared state pipeline:&lt;/strong&gt; serializable values can move from one runtime stage to the next.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Progressive editions:&lt;/strong&gt; start with Lite, use Standard for everyday workflows, or choose Block+ for expanded runtime support.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Native ecosystem access:&lt;/strong&gt; use the Python packages, Node modules, PHP libraries, and other tools already installed on the host.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Visible boundaries:&lt;/strong&gt; runtime startup, state transfer, and errors remain inspectable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MIT licensed:&lt;/strong&gt; the engine, website, and editor integrations are available in the repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🔒 A Security Note
&lt;/h2&gt;

&lt;p&gt;Block invokes host runtimes. That is the point, and it is also the reason you should never execute an untrusted &lt;code&gt;.blk&lt;/code&gt;, &lt;code&gt;.blkl&lt;/code&gt;, or &lt;code&gt;.blkp&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;The engine includes import limits, path checks, runtime policy controls, and validation for malformed blocks, but those controls do not turn arbitrary code into safe code. Review the script and its dependencies before running it.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔗 Links &amp;amp; Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/O-O1112/Block_lang" rel="noopener noreferrer"&gt;https://github.com/O-O1112/Block_lang&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documentation:&lt;/strong&gt; &lt;a href="https://block-io.blockengine.workers.dev/wiki.html" rel="noopener noreferrer"&gt;https://block-io.blockengine.workers.dev/wiki.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Downloads:&lt;/strong&gt; &lt;a href="https://block-io.blockengine.workers.dev/downloads.html" rel="noopener noreferrer"&gt;https://block-io.blockengine.workers.dev/downloads.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Examples:&lt;/strong&gt; &lt;a href="https://github.com/O-O1112/Block_lang/tree/main/examples" rel="noopener noreferrer"&gt;https://github.com/O-O1112/Block_lang/tree/main/examples&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I would love to hear what you would build with a visible Python-to-JavaScript or Python-to-Lua state pipeline. Which runtime should Block support next?&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>osdc</category>
      <category>python</category>
      <category>javascript</category>
    </item>
    <item>
      <title>The Smallest Useful RAG Prototype Is the One You Can Debug</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Sat, 22 Aug 2026 04:38:55 +0000</pubDate>
      <link>https://dev.to/o-o1112/the-smallest-useful-rag-prototype-is-the-one-you-can-debug-1n57</link>
      <guid>https://dev.to/o-o1112/the-smallest-useful-rag-prototype-is-the-one-you-can-debug-1n57</guid>
      <description>&lt;p&gt;Retrieval-augmented generation is often introduced with a long list of components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an embedding model;&lt;/li&gt;
&lt;li&gt;a vector database;&lt;/li&gt;
&lt;li&gt;a chunking framework;&lt;/li&gt;
&lt;li&gt;a reranker;&lt;/li&gt;
&lt;li&gt;a prompt template;&lt;/li&gt;
&lt;li&gt;and finally a chat model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of those tools can be useful. They can also make it difficult to answer the first practical question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Did the system retrieve the right context?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before adding a vector database, I like to build a small retrieval loop that exposes every decision. If the tiny version cannot find the right document, a more expensive stack will only hide the problem behind more infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 The Problem: Retrieval Errors Look Like Model Errors
&lt;/h2&gt;

&lt;p&gt;Suppose a user asks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How do I run the Standard Block edition?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the answer is wrong, there are at least two possibilities:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the retriever returned the wrong context;&lt;/li&gt;
&lt;li&gt;the model saw the right context but generated a poor answer.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Those failures need different fixes. The first prototype should make the difference visible.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚙️ Stage 1: Normalize and Score Documents in Python
&lt;/h2&gt;

&lt;p&gt;This example uses token overlap instead of embeddings. It is not a replacement for semantic retrieval. It is a transparent baseline that can be tested with a few lines of code.&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="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;


&lt;span class="n"&gt;DOCUMENTS&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;install-standard&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Install Block Standard and run a .blk file with: block example.blk&lt;/span&gt;&lt;span class="sh"&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;install-plus&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Block+ runs .blkp files and adds expanded runtime and tooling support.&lt;/span&gt;&lt;span class="sh"&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;security&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Do not execute untrusted Block files because language blocks call host runtimes.&lt;/span&gt;&lt;span class="sh"&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;def&lt;/span&gt; &lt;span class="nf"&gt;tokens&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="nb"&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="nb"&gt;set&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[a-z0-9]+&lt;/span&gt;&lt;span class="sh"&gt;"&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="nf"&gt;lower&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;retrieve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&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;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&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;list&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;scored&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;document&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;DOCUMENTS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;overlap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;overlap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;scored&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;score&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;matched_terms&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;overlap&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="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scored&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;score&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;reverse&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)[:&lt;/span&gt;&lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="n"&gt;question&lt;/span&gt; &lt;span class="o"&gt;=&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;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&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="ow"&gt;or&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;How do I run Standard?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;question&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;matches&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;retrieve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)}))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prototype gives us three things that are easy to inspect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the retrieved document IDs;&lt;/li&gt;
&lt;li&gt;the numeric score;&lt;/li&gt;
&lt;li&gt;the exact terms that caused the match.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  💻 Stage 2: Prepare a Model Context in JavaScript
&lt;/h2&gt;

&lt;p&gt;The next stage does not pretend that retrieval is the final answer. It turns the selected documents into a bounded context and prints the prompt that would be sent to a model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setEncoding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;end&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt; &lt;span class="o"&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;matches&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;] &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Answer only from the supplied context.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;`Question: &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;question&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Context:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;context&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No matching context was found.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prompt&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 model call can be added after this point. More importantly, it can be tested separately from retrieval.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡ Output: Make the Retrieval Decision Visible
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question: How do I run Standard?
Context:
[install-standard] Install Block Standard and run a .blk file with: block example.blk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the output contains only &lt;code&gt;No matching context was found&lt;/code&gt;, changing the prompt will not fix the pipeline. The retrieval stage needs better tokenization, chunking, metadata, or a semantic index.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start with a transparent baseline:&lt;/strong&gt; you need to see why a document was selected.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separate retrieval from generation:&lt;/strong&gt; each stage should have its own input, output, and test.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep context bounded:&lt;/strong&gt; more documents do not automatically mean better answers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure the failure mode:&lt;/strong&gt; wrong retrieval and wrong generation are different bugs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upgrade one layer at a time:&lt;/strong&gt; add embeddings only after the baseline has taught you what it misses.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;RAG becomes easier to improve when it stops being one large “AI answer” function and becomes a sequence of observable stages.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧪 Evaluate Retrieval Before You Tune Prompts
&lt;/h2&gt;

&lt;p&gt;Before adding embeddings, I would create a tiny evaluation set:&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;EVALUATION&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;question&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;How do I run Standard?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;install-standard&lt;/span&gt;&lt;span class="sh"&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;question&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Which edition supports .blkp files?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;install-plus&lt;/span&gt;&lt;span class="sh"&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;question&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Can I execute an unknown script safely?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;security&lt;/span&gt;&lt;span class="sh"&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;def&lt;/span&gt; &lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;passed&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;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;EVALUATION&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="nf"&gt;retrieve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;question&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;selected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&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;result&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
        &lt;span class="n"&gt;passed&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;selected&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;question&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;question&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;selected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;selected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ok&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;selected&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expected&lt;/span&gt;&lt;span class="sh"&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;print&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="s"&gt;retrieval accuracy: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;passed&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EVALUATION&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The point is not to win a benchmark. The point is to know whether a change improved the behavior you care about. If a new chunking rule lowers the score from &lt;code&gt;3/3&lt;/code&gt; to &lt;code&gt;2/3&lt;/code&gt;, that is more useful than a vague feeling that the answers became worse.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧱 Chunking and Metadata Come Before More Infrastructure
&lt;/h2&gt;

&lt;p&gt;The small baseline also shows what information is missing. If two documents have the same words but different editions, metadata can make the distinction explicit:&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="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;install-standard&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;edition&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;standard&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;topic&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;installation&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Install Block Standard and run a .blk file with: block example.blk&lt;/span&gt;&lt;span class="sh"&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;A retriever can then filter by edition or topic before scoring text. That is often a better first improvement than immediately adding a larger model.&lt;/p&gt;

&lt;p&gt;The same principle applies to chunk size. A chunk that is too large contains distracting instructions. A chunk that is too small loses the relationship between a command and its explanation. There is no universal number; the evaluation questions should guide the choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔍 Know When to Upgrade to Embeddings
&lt;/h2&gt;

&lt;p&gt;Token overlap is a useful baseline, but it has predictable limits. It will miss relationships such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“run the regular edition” and “execute a &lt;code&gt;.blk&lt;/code&gt; file”;&lt;/li&gt;
&lt;li&gt;“do not trust the script” and “review code before execution”;&lt;/li&gt;
&lt;li&gt;“load a module” and “import a local Block file”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When those misses matter, semantic embeddings are a sensible next step. The baseline still pays off because it gives you a reference point. You can compare the embedding retriever against the simple one instead of comparing it against intuition.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔒 Keep the Generation Prompt Honest
&lt;/h2&gt;

&lt;p&gt;The final prompt should tell the model what to do when retrieval fails:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Answer only from the supplied context.
If the context does not contain the answer, say that no matching documentation was found.
Do not invent commands, versions, or security guarantees.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That instruction cannot make a model perfectly reliable, but it makes the desired failure mode explicit. A useful RAG system is not one that always answers. It is one that can say when its evidence is insufficient.&lt;/p&gt;

&lt;p&gt;The same stage-by-stage approach is useful for polyglot workflows too. I am building &lt;a href="https://github.com/O-O1112/Block_lang" rel="noopener noreferrer"&gt;Block Language&lt;/a&gt; around that idea: each runtime stays native while the execution and state boundaries remain visible.&lt;/p&gt;

&lt;p&gt;What is the first retrieval failure you would want your RAG prototype to explain?&lt;/p&gt;

</description>
      <category>aiops</category>
      <category>python</category>
      <category>beginners</category>
      <category>oop</category>
    </item>
    <item>
      <title>An AI Agent Is Only as Safe as Its Tool Boundary</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Sat, 22 Aug 2026 04:38:37 +0000</pubDate>
      <link>https://dev.to/o-o1112/an-ai-agent-is-only-as-safe-as-its-tool-boundary-2l5o</link>
      <guid>https://dev.to/o-o1112/an-ai-agent-is-only-as-safe-as-its-tool-boundary-2l5o</guid>
      <description>&lt;p&gt;When people talk about AI agents, the conversation often starts with the model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which model should choose the action?&lt;/li&gt;
&lt;li&gt;How large should the context window be?&lt;/li&gt;
&lt;li&gt;Should the agent plan in one step or five?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those questions matter, but the most important boundary is usually outside the model.&lt;/p&gt;

&lt;p&gt;It is the tool boundary.&lt;/p&gt;

&lt;p&gt;If a model can call a function that deletes files, runs shell commands, sends messages, or changes production data, that function is part of the security model. A prompt saying “be careful” is not an access-control system.&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 The Problem: Tool Calling Hides Authority
&lt;/h2&gt;

&lt;p&gt;A naive agent often looks like this:&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;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_request&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="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is convenient, but it gives a text generator authority over the host shell. The model output is now both data and executable instruction.&lt;/p&gt;

&lt;p&gt;The safer pattern is the opposite:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the model requests a named tool;&lt;/li&gt;
&lt;li&gt;the application checks the tool name;&lt;/li&gt;
&lt;li&gt;the application validates the arguments;&lt;/li&gt;
&lt;li&gt;the application executes a narrow implementation;&lt;/li&gt;
&lt;li&gt;the result is recorded and returned as data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The model can propose. The application decides.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚙️ Build a Small Allowlisted Registry
&lt;/h2&gt;

&lt;p&gt;Here is a deliberately small registry. It can read a project status file and count lines in a known source file. It cannot execute arbitrary commands.&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="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Callable&lt;/span&gt;


&lt;span class="n"&gt;ROOT&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="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;resolve&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;resolve_project_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;relative_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&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="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;candidate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ROOT&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;relative_name&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;resolve&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;ROOT&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;candidate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parents&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Path escapes the project root&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_file&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;FileNotFoundError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;relative_name&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;candidate&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arguments&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&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;dict&lt;/span&gt;&lt;span class="p"&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;Any&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;resolve_project_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;STATUS.md&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="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;path&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&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;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;relative_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ROOT&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&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;count_lines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arguments&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&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;dict&lt;/span&gt;&lt;span class="p"&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;Any&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;resolve_project_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;file&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="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;file&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;file&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;lines&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;splitlines&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="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&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;Callable&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;read_status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;read_status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;count_lines&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;count_lines&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 registry is intentionally boring. Boring is good when it is holding authority.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔒 Validate the Model Request Before Execution
&lt;/h2&gt;

&lt;p&gt;The model should return structured data, not a shell command.&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;run_tool_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&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;dict&lt;/span&gt;&lt;span class="p"&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;Any&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="n"&gt;request&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;arguments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;arguments&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;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;TOOLS&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Tool is not allowlisted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arguments&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="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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Tool arguments must be an object&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&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;name&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ok&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;result&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;result&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;For &lt;code&gt;count_lines&lt;/code&gt;, I would also validate the exact argument shape before calling the function. In a larger project, a schema library can do this, but the rule stays the same: validation belongs to the application, not to the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧾 Keep an Audit Record
&lt;/h2&gt;

&lt;p&gt;Every tool call should leave behind a safe, useful record:&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;audit_record&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;response&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Any&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;dict&lt;/span&gt;&lt;span class="p"&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;Any&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;request&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&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;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ok&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&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;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ok&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;argument_keys&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;arguments&lt;/span&gt;&lt;span class="sh"&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;keys&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;Do not put passwords, tokens, or full private documents into the log. The audit record should explain what happened without becoming a second data leak.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡ Example Request and Output
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"request_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"agent-014"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tool"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"count_lines"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"arguments"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"src/Parser.cs"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tool"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"count_lines"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"ok"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"src/Parser.cs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"lines"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;218&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model never receives a raw shell. It receives a small result that can be checked, displayed, or passed to the next stage.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Treat tools as capabilities:&lt;/strong&gt; every tool should have a narrow purpose and a clear owner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use allowlists:&lt;/strong&gt; unknown names must fail closed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resolve paths safely:&lt;/strong&gt; normalize paths and enforce a project boundary.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate twice when needed:&lt;/strong&gt; schema validation protects the application; business rules protect the operation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Audit the decision:&lt;/strong&gt; a useful log makes agent behavior explainable after the fact.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is not to make an agent powerless. The goal is to make its power visible, bounded, and testable.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧭 Make Permissions Explicit
&lt;/h2&gt;

&lt;p&gt;As the registry grows, I like to document each tool as a capability with a small permission matrix:&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;Reads files&lt;/th&gt;
&lt;th&gt;Writes files&lt;/th&gt;
&lt;th&gt;Network&lt;/th&gt;
&lt;th&gt;Destructive&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;read_status&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;STATUS.md&lt;/code&gt; only&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;count_lines&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;One project file&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;search_docs&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;docs/&lt;/code&gt; only&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;apply_patch&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Selected files&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Potentially&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The table is not a replacement for code checks. It is a fast way for a reviewer to see that a new tool has more authority than the old ones.&lt;/p&gt;

&lt;p&gt;I would also separate read-only tools from mutating tools in the registry:&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;READ_ONLY_TOOLS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;read_status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;read_status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;count_lines&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;count_lines&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;MUTATING_TOOLS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;# A future write tool belongs here and needs an additional approval step.
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That distinction makes it possible to run an agent in a safe inspection mode. A user can ask the agent to analyze a repository without accidentally granting it write access.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧪 Test Malformed and Hostile Requests
&lt;/h2&gt;

&lt;p&gt;A tool registry is incomplete until it has tests for the requests that should fail.&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;test_unknown_tool_is_rejected&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="nf"&gt;run_tool_request&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;run_shell&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;arguments&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cmd&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dir&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}})&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;ValueError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;allowlisted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;in&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;error&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="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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Unknown tool was accepted&lt;/span&gt;&lt;span class="sh"&gt;"&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;test_path_escape_is_rejected&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="nf"&gt;run_tool_request&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;count_lines&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;arguments&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;file&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;..&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;secrets.txt&lt;/span&gt;&lt;span class="sh"&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="nb"&gt;ValueError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;escapes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;in&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;error&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="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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Escaping path was accepted&lt;/span&gt;&lt;span class="sh"&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 exact error text can change, but the behavior should not: unknown capabilities and out-of-bound paths must fail closed.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⏱️ Add Approval for High-Impact Actions
&lt;/h2&gt;

&lt;p&gt;Some tools are safe to run automatically. Others should pause and ask for approval. Sending an email, deleting data, changing permissions, or deploying code should not be treated like reading a file.&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;requires_approval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tool_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&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="nb"&gt;bool&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;tool_name&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;send_message&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;delete_record&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;deploy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not about distrusting every model response. It is about recognizing that an agent can be wrong in a perfectly confident way. A human approval step is a useful boundary when the consequence is external or difficult to reverse.&lt;/p&gt;

&lt;p&gt;How do you currently decide which tools an AI agent is allowed to call?&lt;/p&gt;

</description>
      <category>python</category>
      <category>security</category>
      <category>oop</category>
    </item>
    <item>
      <title>I Stopped Treating AI Pipelines Like Magic: Designing Explicit State Boundaries</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Sat, 22 Aug 2026 04:38:00 +0000</pubDate>
      <link>https://dev.to/o-o1112/i-stopped-treating-ai-pipelines-like-magic-designing-explicit-state-boundaries-170k</link>
      <guid>https://dev.to/o-o1112/i-stopped-treating-ai-pipelines-like-magic-designing-explicit-state-boundaries-170k</guid>
      <description>&lt;p&gt;I was practicing a small AI workflow recently: prepare text in Python, send it through a model step, and format the result in JavaScript.&lt;/p&gt;

&lt;p&gt;The model was not the hardest part.&lt;/p&gt;

&lt;p&gt;The difficult part was the boundary around it.&lt;/p&gt;

&lt;p&gt;Normally, I would end up with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a temporary JSON file;&lt;/li&gt;
&lt;li&gt;a hidden environment variable carrying state;&lt;/li&gt;
&lt;li&gt;a second script that knows too much about the first script;&lt;/li&gt;
&lt;li&gt;and no obvious place to inspect what the model actually received.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is how a five-line experiment quietly becomes a small integration project.&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 The Problem: AI State Gets Lost Between Stages
&lt;/h2&gt;

&lt;p&gt;An AI pipeline usually has at least three different responsibilities:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Preparation:&lt;/strong&gt; normalize text, remove noise, and compute metadata.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inference:&lt;/strong&gt; send a small, well-defined input to a model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Presentation:&lt;/strong&gt; turn the model result into something a person or another program can use.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If those stages share an implicit global object, debugging becomes guesswork. If they share a temporary file, the file becomes both a coupling point and a leak surface.&lt;/p&gt;

&lt;p&gt;The first improvement is to define the state contract before choosing a model.&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="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"request_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"demo-001"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Block coordinates multiple native runtimes in one file."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"language"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"features"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"characters"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"words"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"model_input"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Classify this developer documentation sentence."&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The contract answers a simple question: what exactly crosses the boundary?&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚙️ Stage 1: Prepare a Stable Input in Python
&lt;/h2&gt;

&lt;p&gt;The preparation stage should be deterministic. It should be possible to run it without an AI provider and inspect the result.&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="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;build_state&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_id&lt;/span&gt;&lt;span class="p"&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;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&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="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[A-Za-z0-9_&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="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;request_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;language&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;en&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;features&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;characters&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;words&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;model_input&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Classify this developer documentation sentence as &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;technical, product, or general: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;build_state&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;demo-001&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Block coordinates multiple native runtimes in one file.&lt;/span&gt;&lt;span class="sh"&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;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ensure_ascii&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This stage does not call a model. That is intentional. A pipeline that cannot produce a valid input without the model is difficult to test.&lt;/p&gt;

&lt;h2&gt;
  
  
  💻 Stage 2: Consume the Contract in JavaScript
&lt;/h2&gt;

&lt;p&gt;The next stage reads one JSON document from standard input. In production, this is where I would call a local model or a hosted inference API. For the first test, I use a deterministic classifier so the transport and validation can be checked without credentials.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setEncoding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utf8&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;end&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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;request_id&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&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;text&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&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;features&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid AI pipeline state&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/runtime|python|javascript|code/i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&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;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;technical&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;general&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;request_id&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;request_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;confidence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;label&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;technical&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mf"&gt;0.98&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.61&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;words_seen&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;features&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;words&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important detail is not the classifier. It is the explicit input and output shape.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚡ Output You Can Actually Debug
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"request_id":"demo-001","label":"technical","confidence":0.98,"words_seen":9}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the real model is added, the output can be compared against this same contract. A provider change should not require rewriting the preparation and presentation stages.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;State is an interface:&lt;/strong&gt; treat model input and output like an API, not an accidental dictionary.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic stages come first:&lt;/strong&gt; test preparation and validation before adding model variability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the model boundary narrow:&lt;/strong&gt; send only the fields the model needs, and validate what comes back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make failures visible:&lt;/strong&gt; include a request ID, stage name, and safe summary in logs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model is only one stage in an AI program. The reliability of the whole program depends on the boundaries around it.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧪 Test the Pipeline Without a Model
&lt;/h2&gt;

&lt;p&gt;The most useful test is a boring one: send a known state through the pipeline and compare the result with a known output.&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;test_state_contract&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;build_state&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;test-001&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Python sends structured state to JavaScript.&lt;/span&gt;&lt;span class="sh"&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;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;test-001&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;features&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;words&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Classify&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;model_input&lt;/span&gt;&lt;span class="sh"&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 JavaScript stage should have the same kind of test. It should reject missing fields instead of silently inventing defaults:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;validateState&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="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;required&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;request_id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;features&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;model_input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;missing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;required&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Missing state fields: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;missing&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&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;This is especially important when the model is nondeterministic. If a result changes, I want to know whether the input changed, the model changed, or the transport broke.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔁 Adding a Real Model Later
&lt;/h2&gt;

&lt;p&gt;Once the contract is stable, the deterministic classifier can be replaced with a model call. I would still keep the provider-specific code behind one function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;classifyWithModel&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;client&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;input&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;model_input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;request_id&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;request_id&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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;request_id&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;request_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;confidence&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;confidence&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;words_seen&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;features&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;words&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 rest of the pipeline should not need to know whether the model is local, hosted, small, or large. That decision belongs inside the inference stage.&lt;/p&gt;

&lt;p&gt;There is another practical reason to keep the contract small: retries. If a provider times out, the pipeline can retry the inference stage with the same &lt;code&gt;request_id&lt;/code&gt; and the same prepared input. It does not need to repeat text normalization or rebuild the entire workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔒 Do Not Put Secrets in the Shared State
&lt;/h2&gt;

&lt;p&gt;State synchronization is not a reason to copy every variable between stages. API keys, access tokens, cookies, and private source documents should stay in the narrowest possible scope.&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;safe_state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;features&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;features&lt;/span&gt;&lt;span class="sh"&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 model only needs the fields required for the task. Smaller state is easier to inspect, easier to redact, and less likely to appear in a log by accident.&lt;/p&gt;

&lt;p&gt;I am exploring the same idea in &lt;a href="https://github.com/O-O1112/Block_lang" rel="noopener noreferrer"&gt;Block Language&lt;/a&gt;, where native runtime blocks can share a visible state pipeline in one readable file.&lt;/p&gt;

&lt;p&gt;What is the first state boundary you make explicit in your AI projects?&lt;/p&gt;

</description>
      <category>python</category>
      <category>javascript</category>
      <category>ai</category>
      <category>programming</category>
    </item>
    <item>
      <title>Zero-Overhead Polyglot Crypto: Streaming Hashes from Python to Node.js in One Script</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Fri, 21 Aug 2026 23:52:09 +0000</pubDate>
      <link>https://dev.to/o-o1112/zero-overhead-polyglot-crypto-streaming-hashes-from-python-to-nodejs-in-one-script-43oc</link>
      <guid>https://dev.to/o-o1112/zero-overhead-polyglot-crypto-streaming-hashes-from-python-to-nodejs-in-one-script-43oc</guid>
      <description>&lt;h2&gt;
  
  
  💡 Why Polyglot Cryptographic Pipelines?
&lt;/h2&gt;

&lt;p&gt;In modern backend workflows, cryptographic workloads often require specialized libraries:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Python&lt;/strong&gt;: Unmatched for rapid entropy generation, HMAC token signing, and security prototyping (&lt;code&gt;hashlib&lt;/code&gt;, &lt;code&gt;secrets&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js&lt;/strong&gt;: Industry-standard for fast asynchronous payload packing, WebSocket dispatching, and buffer encoding.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Normally, piping security tokens between these two environments requires:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Writing to a temporary state file on disk (creating a security leak surface).&lt;/li&gt;
&lt;li&gt;Hosting an internal HTTP microservice (adding 10–50ms network round-trip overhead).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With &lt;strong&gt;Block Engine&lt;/strong&gt;, the entire pipeline executes sequentially in-memory with automatic variable synchronization.&lt;/p&gt;




&lt;h2&gt;
  
  
  💻 Today's Showcase: &lt;code&gt;crypto_pipeline.blkp&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;py&amp;gt;&lt;/span&gt;
import hashlib
import time

payload = "Block-Engine-Polyglot-Token-2026"
timestamp = int(time.time())

# Compute SHA-256 Digest in Python
raw_input = f"{payload}:{timestamp}".encode('utf-8')
sha256_hash = hashlib.sha256(raw_input).hexdigest()

print(f"[Python] Generated SHA-256 Digest: {sha256_hash}")
print(f"[Python] Payload length: {len(raw_input)} bytes")
&lt;span class="nt"&gt;&amp;lt;/py&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;js&amp;gt;&lt;/span&gt;
// Stage 2: Node.js instantly receives sha256_hash and timestamp variables
const crypto = require('crypto');

// Generate verification HMAC in JavaScript using Python's state
const secretKey = 'block-engine-production-secret';
const hmacSignature = crypto.createHmac('sha256', secretKey)
                            .update(sha256_hash)
                            .digest('hex');

console.log("[Node.js] Generated HMAC Signature: " + hmacSignature);
console.log("[Node.js] Pipeline Verified at Timestamp: " + timestamp);
&lt;span class="nt"&gt;&amp;lt;/js&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⚡ Execution with Zero Dependencies
&lt;/h2&gt;

&lt;p&gt;Run it natively with the official zero-install runner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx block-engine-runner crypto_pipeline.blkp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Real-Time Output:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Python] Generated SHA-256 Digest: d6f5847e9262bc69b329ad4efd5f57e6cba7b561c28c897f2597ffc885dc2ea7
[Python] Payload length: 43 bytes
[Node.js] Generated HMAC Signature: 3e0b2308f237bf414c1e096dfac985cfd2d3a3d240ca4e6e66e2c4cb1ea2cb61
[Node.js] Pipeline Verified at Timestamp: 1787385112

✔ State Pipeline synchronized across all runtimes.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🚀 Key Advantages
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Zero Intermediate Disk I/O&lt;/strong&gt;: Eliminates plaintext token leakage in temporary directories.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Instant Cross-Language Variables&lt;/strong&gt;: Python strings and timestamps are automatically cast to JavaScript primitives in-process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pure Productivity&lt;/strong&gt;: Write multi-stage microservices in a single, maintainable file.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href="https://github.com/O-O1112/Block_io" rel="noopener noreferrer"&gt;https://github.com/O-O1112/Block_io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discord Community&lt;/strong&gt;: &lt;a href="https://discord.gg/VeB44CD5y3" rel="noopener noreferrer"&gt;https://discord.gg/VeB44CD5y3&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NPM Package&lt;/strong&gt;: &lt;a href="https://www.npmjs.com/package/block-engine-runner" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/block-engine-runner&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>javascript</category>
      <category>security</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Generating Dynamic SVG Vector Charts from Python Data in a Single Polyglot Script</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Thu, 20 Aug 2026 23:29:50 +0000</pubDate>
      <link>https://dev.to/o-o1112/generating-dynamic-svg-vector-charts-from-python-data-in-a-single-polyglot-script-2jfg</link>
      <guid>https://dev.to/o-o1112/generating-dynamic-svg-vector-charts-from-python-data-in-a-single-polyglot-script-2jfg</guid>
      <description>&lt;h2&gt;
  
  
  💡 The Problem: Connecting Backend Data Math to Frontend Vector Graphics
&lt;/h2&gt;

&lt;p&gt;In traditional development, if you want Python to analyze a data series and generate dynamic SVG graphics via Node.js, you have to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Save the processed numbers to an intermediate JSON file or database.&lt;/li&gt;
&lt;li&gt;Spin up an Express / FastAPI endpoint.&lt;/li&gt;
&lt;li&gt;Write boilerplate code to parse and map the coordinates.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With &lt;strong&gt;Block Engine&lt;/strong&gt;, you can write native &lt;code&gt;&amp;lt;py&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;js&amp;gt;&lt;/code&gt; blocks in a single &lt;code&gt;.blkp&lt;/code&gt; document and let variables flow naturally through the in-memory &lt;strong&gt;State Pipeline&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  💻 Today's Code Snippet: &lt;code&gt;chart_generator.blkp&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;py&amp;gt;&lt;/span&gt;
# Stage 1: Python calculates statistical trend points
data_points = [15, 28, 42, 65, 80, 95, 110, 140]
max_val = max(data_points)
min_val = min(data_points)
points_count = len(data_points)
print(f"[Python] Prepared {points_count} points. Range: [{min_val}, {max_val}]")
&lt;span class="nt"&gt;&amp;lt;/py&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;js&amp;gt;&lt;/span&gt;
// Stage 2: Node.js receives Python variables and computes SVG polygon paths
const width = 500;
const height = 200;
const step = width / (points_count - 1);

const coordinates = data_points.map((val, idx) =&amp;gt; {
    const x = idx * step;
    const y = height - ((val - min_val) / (max_val - min_val)) * (height - 30) - 15;
    return `${x},${y}`;
}).join(' ');

console.log("[Node.js] Generated SVG Polyline Coordinates: " + coordinates);
var svg_output = `&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"${width}"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"${height}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;polyline&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"none"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#38bdf8"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt; &lt;span class="na"&gt;points=&lt;/span&gt;&lt;span class="s"&gt;"${coordinates}"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;`;
&lt;span class="nt"&gt;&amp;lt;/js&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⚡ Running it (Zero-Install):
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx block-engine-runner chart_generator.blkp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Python] Prepared 8 points. Range: [15, 140]
[Node.js] Generated SVG Polyline Coordinates: 0,185 71.42,169.4 142.85,152.6 ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🚀 Key Takeaways
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Zero Microservice Overhead&lt;/strong&gt;: Python handles math and array analysis; Node.js handles string templating and vector math without network sockets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In-Memory IPC&lt;/strong&gt;: Data is passed directly across runtime processes without disk I/O bottlenecks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single-File Simplicity&lt;/strong&gt;: The entire pipeline lives in one structured, readable file.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href="https://github.com/O-O1112/Block_io" rel="noopener noreferrer"&gt;https://github.com/O-O1112/Block_io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discord Community&lt;/strong&gt;: &lt;a href="https://discord.gg/VeB44CD5y3" rel="noopener noreferrer"&gt;https://discord.gg/VeB44CD5y3&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NPM Package&lt;/strong&gt;: &lt;a href="https://www.npmjs.com/package/block-engine-runner" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/block-engine-runner&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>javascript</category>
      <category>svg</category>
      <category>showdev</category>
    </item>
    <item>
      <title>I got tired of writing boilerplate imports, so I built Block: Run Python, JS, and Lua in a single file</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Thu, 20 Aug 2026 12:03:33 +0000</pubDate>
      <link>https://dev.to/o-o1112/i-got-tired-of-writing-boilerplate-imports-so-i-built-block-run-python-js-and-lua-in-a-single-gph</link>
      <guid>https://dev.to/o-o1112/i-got-tired-of-writing-boilerplate-imports-so-i-built-block-run-python-js-and-lua-in-a-single-gph</guid>
      <description>&lt;h2&gt;
  
  
  💡 The Problem: The Import / Glue Code Headache
&lt;/h2&gt;

&lt;p&gt;A while ago, I was practicing importing modules across different projects. I wanted to use &lt;strong&gt;Python&lt;/strong&gt; for its rich data science libraries and &lt;strong&gt;Node.js&lt;/strong&gt; for its async web performance.&lt;/p&gt;

&lt;p&gt;Normally, if you want Python to pass a simple calculated array or dictionary to JavaScript, you have to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Spin up a local FastAPI / Flask server or write to a temporary JSON file.&lt;/li&gt;
&lt;li&gt;Setup &lt;code&gt;fetch()&lt;/code&gt; in Node.js, handle ports, serialization, and CORS.&lt;/li&gt;
&lt;li&gt;Write 50+ lines of glue code just to share a single variable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Coming from a visual block-coding mindset (where you snap blocks together and data flows naturally), I thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Why can't I just write &lt;code&gt;&amp;lt;py&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;js&amp;gt;&lt;/code&gt; in the exact same file, and let the variables flow automatically?"&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I built &lt;strong&gt;Block Engine&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚡ How Block Works
&lt;/h2&gt;

&lt;p&gt;In Block, you write native language blocks separated by tags (&lt;code&gt;&amp;lt;py&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;js&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;lua&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;php&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;server&amp;gt;&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;The underlying orchestrator (built with high-performance C# / .NET) automatically serializes and injects variables across runtime boundaries via an in-memory &lt;strong&gt;State Pipeline&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;py&amp;gt;&lt;/span&gt;
# Python stage: Prepare initial dataset
user = "O-O1112"
dataset = [10, 20, 30, 40, 50]
print(f"[Python] Loaded {len(dataset)} items for {user}")
&lt;span class="nt"&gt;&amp;lt;/py&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;js&amp;gt;&lt;/span&gt;
// Node.js stage: High-performance aggregation
const avg = dataset.reduce((a, b) =&amp;gt; a + b, 0) / dataset.length;
console.log(`[Node.js] Computed average: ${avg}`);
var bonus = 50;
&lt;span class="nt"&gt;&amp;lt;/js&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;lua&amp;gt;&lt;/span&gt;
-- Lua stage: Lightning-fast validation
final_score = avg + bonus
print("[Lua] Final Computed Score: " .. tostring(final_score))
&lt;span class="nt"&gt;&amp;lt;/lua&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🎯 Running it:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;block demo.blkp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Python] Loaded 5 items for O-O1112
[Node.js] Computed average: 30
[Lua] Final Computed Score: 80.0
✔ State Pipeline synchronized across 3 runtimes in 320ms.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🚀 Key Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zero-Glue State Pipeline&lt;/strong&gt;: Variables declared in Python are instantly accessible in JS and Lua without manual JSON parsing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Native Ecosystem Compatibility&lt;/strong&gt;: Direct access to your existing host &lt;code&gt;pip&lt;/code&gt;, &lt;code&gt;npm&lt;/code&gt;, and &lt;code&gt;luarocks&lt;/code&gt; libraries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero-Install NPX Execution&lt;/strong&gt;: You can run any &lt;code&gt;.blkp&lt;/code&gt; file directly in terminal without manual installer setup:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  npx block-engine-runner demo.blkp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Modular Imports&lt;/strong&gt;: Supports &lt;code&gt;&amp;lt;import src="modules/data.blk" /&amp;gt;&lt;/code&gt; and custom runtime definitions with &lt;code&gt;&amp;lt;define lang="sim" cmd="node" /&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open Source&lt;/strong&gt;: Released under the MIT license.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔗 Links &amp;amp; Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href="https://github.com/O-O1112/Block_io" rel="noopener noreferrer"&gt;https://github.com/O-O1112/Block_io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NPM Package&lt;/strong&gt;: &lt;a href="https://www.npmjs.com/package/block-engine-runner" rel="noopener noreferrer"&gt;&lt;code&gt;block-engine-runner&lt;/code&gt;&lt;/a&gt; / &lt;a href="https://www.npmjs.com/package/block-installer-ui" rel="noopener noreferrer"&gt;&lt;code&gt;block-installer-ui&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Official Discord Community&lt;/strong&gt;: &lt;a href="https://discord.gg/VeB44CD5y3" rel="noopener noreferrer"&gt;https://discord.gg/VeB44CD5y3&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I would love to hear feedback and thoughts from the DEV community on this state-pipeline approach! What languages would you like to see chained next?&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>opensource</category>
      <category>python</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Beyond Bigger Models: The Practical Blueprint to Making AI Smarter (And Why It Matters)</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Fri, 14 Aug 2026 23:41:55 +0000</pubDate>
      <link>https://dev.to/o-o1112/beyond-bigger-models-the-practical-blueprint-to-making-ai-smarter-and-why-it-matters-4aei</link>
      <guid>https://dev.to/o-o1112/beyond-bigger-models-the-practical-blueprint-to-making-ai-smarter-and-why-it-matters-4aei</guid>
      <description>&lt;p&gt;For the past few years, the prevailing narrative across the machine learning landscape has been straightforward: &lt;strong&gt;Scale is all you need.&lt;/strong&gt; Add more layers, ingest trillions of tokens, burn more compute, and artificial general intelligence will naturally emerge.&lt;/p&gt;

&lt;p&gt;While scaling laws have undeniably produced remarkable conversational fluency, anyone who has deployed Large Language Models (LLMs) in real-world workflows knows the reality: &lt;strong&gt;Bigger models are not necessarily smarter—they are often just more eloquently wrong.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A model with hundreds of billions of parameters can still fail at basic deterministic logic, hallucinate non-existent API endpoints, or produce generic, templated responses when confronted with complex domain problems.&lt;/p&gt;

&lt;p&gt;To build genuinely intelligent software systems—and to shape AI into a tool tailored to an individual’s exact workflow—we must shift our focus from brute-force scale to &lt;strong&gt;architectural reasoning, verification loops, parameter tuning, and dynamic context grounding&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Deconstructing "Smart": What Does Intelligence Mean in Software?
&lt;/h2&gt;

&lt;p&gt;In cognitive science, human thought is often categorized into two modes (popularized by Daniel Kahneman’s dual-process theory):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;System 1 (Fast, Intuitive, Pattern-Based):&lt;/strong&gt; Recognizing a face, driving along an empty highway, completing common idioms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;System 2 (Slow, Deliberate, Logical):&lt;/strong&gt; Solving complex differential equations, debugging memory leaks, refactoring monolithic codebases.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Standard Transformer models are fundamentally &lt;strong&gt;System 1 engines&lt;/strong&gt;. They allocate an identical amount of feed-forward compute per token regardless of whether the prompt is &lt;em&gt;"What is the capital of France?"&lt;/em&gt; or &lt;em&gt;"Optimize this distributed consensus algorithm under high network partition risk."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Making AI "smarter" means equipping it with &lt;strong&gt;System 2 capabilities&lt;/strong&gt;: the capacity to pause, explore multiple logical branches, verify intermediate steps against reality, and self-correct prior to returning an answer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Standard Inference (System 1):
[User Prompt] ───────────────&amp;gt; [Fixed-Depth Forward Pass] ───────────────&amp;gt; [Greedy Output]

Reasoning-Centric Inference (System 2):
            ┌────────────────────────────────────────┐
            ▼                                        │
[User Prompt] ───&amp;gt; [Path Exploration] ───&amp;gt; [Verification Loop] ───&amp;gt; [Grounded Output]

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  2. The Implementation Ladder: How Users &amp;amp; Developers Can Shape Custom Intelligence
&lt;/h2&gt;

&lt;p&gt;Transforming an AI from an unpredictable text generator into a precise, customized cognitive partner requires a phased approach across four distinct levels:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Stage 1: Prompt Engineering] ──► [Stage 2: Decoding Parameters] ──► [Stage 3: Memory / RAG] ──► [Stage 4: PEFT / LoRA]
     (Zero-Barrier Logic)            (Entropy &amp;amp; Focus Tuning)            (Dynamic Context Injection)     (Style &amp;amp; Logic Baking)

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Stage 1: Beyond Casual Chat — Structured Prompt Engineering
&lt;/h3&gt;

&lt;p&gt;Everyday users often treat LLMs like search engines or mind readers. Achieving reliable, high-density outputs requires embedding explicit &lt;strong&gt;roles, cognitive boundaries, and self-reflection constraints&lt;/strong&gt; into the prompt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Role &amp;amp; Boundary Anchoring:&lt;/strong&gt; Define the operational persona and scope directly (e.g., &lt;em&gt;"You are a senior systems architect. Maintain an analytical tone. Skip introductory pleasantries and provide structural trade-off evaluations directly."&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Few-Shot Chain-of-Thought (CoT):&lt;/strong&gt; Force the model to externalize intermediate reasoning steps before arriving at conclusions (e.g., &lt;em&gt;"Identify three potential architectural bottlenecks in this design and evaluate each constraint before proposing the final implementation."&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Negative Constraints:&lt;/strong&gt; Explicitly prune filler and generic commentary (e.g., &lt;em&gt;"Avoid clichés like 'In conclusion', 'It is worth noting that', or repetitive boilerplate summaries."&lt;/em&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Stage 2: Decoding Parameters — Controlling Cognitive Entropy
&lt;/h3&gt;

&lt;p&gt;When accessing models via APIs or local WebUIs (such as Ollama or vLLM), developers and power users can directly modulate generation dynamics through core hyperparameters:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Operational Impact&lt;/th&gt;
&lt;th&gt;Recommended Setting&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Temperature&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Controls output entropy and randomness&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;0.1 – 0.3&lt;/code&gt; for deterministic logic, math, and code refactoring; &lt;code&gt;0.7 – 0.9&lt;/code&gt; for open-ended ideation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Top_P (Nucleus Sampling)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Truncates candidate token distribution&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;&amp;lt;= 0.8&lt;/code&gt; for analytical rigor, preventing the selection of low-probability, outlier tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Presence / Frequency Penalty&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Penalizes token repetition&lt;/td&gt;
&lt;td&gt;Increased values prevent recursive looping, repetitive phrasing, and conversational tics&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Stage 3: Dynamic Memory &amp;amp; Grounding (RAG &amp;amp; Context Injection)
&lt;/h3&gt;

&lt;p&gt;Teaching a model personal notes, private repositories, or specialized domain documentation does not require retraining the base model; it requires &lt;strong&gt;Retrieval-Augmented Generation (RAG)&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local Vector Stores:&lt;/strong&gt; Utilize lightweight embedded vector databases (such as Chroma or Qdrant) to chunk and embed personal Markdown notes, codebase files, or reference materials.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Context Injection:&lt;/strong&gt; During query execution, the orchestrator retrieves the top relevant context snippets and dynamically embeds them into the system prompt, grounding the model’s answers in verifiable data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Stage 4: Lightweight Fine-Tuning (LoRA / QLoRA)
&lt;/h3&gt;

&lt;p&gt;When you need the model to internalize an architectural pattern, custom programming syntax, or writing voice, Parameter-Efficient Fine-Tuning (PEFT) can be executed on consumer-grade GPUs (e.g., a single RTX 3060 or 4090):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Dataset Curation:&lt;/strong&gt; Build a clean dataset of hundreds to thousands of verified &lt;code&gt;{"instruction": "...", "input": "...", "output": "..."}&lt;/code&gt; examples demonstrating the target reasoning style.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Low-Rank Adaptation (LoRA):&lt;/strong&gt; Freeze 99%+ of the base model’s core weights and train only small rank-decomposition adapter matrices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deployment:&lt;/strong&gt; The resulting adapter file (often under 100 MB) can be loaded dynamically on top of open-weights foundation models (e.g., Llama, Mistral) to permanently adopt specific cognitive styles.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  3. Engineering Advanced Autonomy: Closed-Loop Agentic Execution
&lt;/h2&gt;

&lt;p&gt;For software engineers, true machine intelligence is demonstrated not by answering questions, but by &lt;strong&gt;acting within an environment, evaluating runtime feedback, and self-correcting&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The following minimal Python implementation illustrates an autonomous agent with a deterministic verification and recovery loop:&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;class&lt;/span&gt; &lt;span class="nc"&gt;AutonomousAgent&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="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model_client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_retries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&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;model_client&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;max_retries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;max_retries&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;execute_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user_goal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;history&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;system&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;You are an autonomous engineering agent with code execution and self-debugging capabilities.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user_goal&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;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;max_retries&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;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="c1"&gt;# Evaluate whether the model initiated a deterministic tool call
&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;has_tool_call&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;execution_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run_in_sandbox&lt;/span&gt;&lt;span class="p"&gt;(&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;tool_call&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

                &lt;span class="c1"&gt;# Append execution state directly back into the context window
&lt;/span&gt;                &lt;span class="n"&gt;history&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;assistant&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
                &lt;span class="n"&gt;history&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;execution_result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;

                &lt;span class="c1"&gt;# If deterministic verification succeeds, generate final response
&lt;/span&gt;                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;execution_result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_success&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;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;
                &lt;span class="c1"&gt;# If execution fails, the next loop iteration forces the model to debug its error
&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;return&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;text&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;Task could not be verified within maximum execution iterations.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run_in_sandbox&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tool_call&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Execute code, run linters, or parse syntax inside an isolated container
&lt;/span&gt;        &lt;span class="k"&gt;pass&lt;/span&gt;

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  4. Why Does This Matter? (The Real-World Stakes)
&lt;/h2&gt;

&lt;p&gt;Understanding this architectural evolution transforms AI from a novel text generator into dependable software infrastructure:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Key Dimension&lt;/th&gt;
&lt;th&gt;Relying Solely on Massive Cloud Models&lt;/th&gt;
&lt;th&gt;Building Purpose-Driven AI Architectures&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Output Reliability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Prone to silent hallucinations and generic responses&lt;/td&gt;
&lt;td&gt;Auditable, step-by-step logic grounded in verifiable context&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Data Privacy&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sensitive internal logic and trade secrets must be sent to public clouds&lt;/td&gt;
&lt;td&gt;Local small models + custom LoRA keep sensitive data fully on-device&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Operational Cost&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;High per-token API costs and latency at scale&lt;/td&gt;
&lt;td&gt;High reasoning density with near-zero marginal inference cost locally&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Autonomy&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Fragile input-output pipelines that break on edge cases&lt;/td&gt;
&lt;td&gt;Self-healing agents capable of catching and repairing exceptions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  1. Eliminating the Cost of Hallucinations
&lt;/h3&gt;

&lt;p&gt;In casual consumer applications, a hallucination is a minor oddity. In fintech, aerospace, medical infrastructure, or core software development, &lt;strong&gt;a hallucination is an outage or an unmitigated liability&lt;/strong&gt;. Enforcing verification loops ensures the model validates facts against deterministic engines before delivery.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Democratization via Compact, Dense Models
&lt;/h3&gt;

&lt;p&gt;If intelligence were strictly proportional to parameter count, frontier AI would remain an oligopoly controlled by a handful of hyperscalers. By pairing smaller, high-quality models (e.g., 7B to 14B parameters) with robust reasoning scaffolding, RAG, and tool use, high-precision intelligence can run on personal workstations and edge hardware.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;p&gt;Making artificial intelligence smarter is no longer about blindly scaling pre-training datasets. The actual frontier lies in how we engineer the systems, feedback loops, and cognitive constraints around the model:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Engineer for System 2 Deliberation:&lt;/strong&gt; Use structured prompting and test-time compute to force multi-step verification.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calibrate Decoding Parameters:&lt;/strong&gt; Align entropy and sampling settings with the deterministic requirements of the task.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anchor with Dynamic Context and LoRA:&lt;/strong&gt; Inject private knowledge via RAG and solidify specialized workflows with lightweight adapters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enclose Models in Feedback Loops:&lt;/strong&gt; Let models inspect execution errors in sandboxes so they can learn to self-correct in real time.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The future of software belongs to developers who build robust cognitive scaffolding, not just those who query the largest black box.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;How are you structuring your verification pipelines, local models, or prompt architectures to eliminate hallucinations in your current projects? Share your setups and workflows in the comments below.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>machinelearning</category>
      <category>architecture</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Fri, 14 Aug 2026 00:52:39 +0000</pubDate>
      <link>https://dev.to/o-o1112/-412i</link>
      <guid>https://dev.to/o-o1112/-412i</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/o-o1112/pythonjsc-block-engine-v220-run-python-nodejs-lua-php-in-a-single-document-with-4hlb" class="crayons-story__hidden-navigation-link"&gt;[Python/JS/C#] Block Engine v2.2.0: Run Python, Node.js, Lua &amp;amp; PHP in a single document with zero-config state pipeline&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/o-o1112" class="crayons-avatar  crayons-avatar--l  "&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%2Fuser%2Fprofile_image%2F4076898%2Fd4838dcb-87c9-4707-8201-c726d84ae222.png" alt="o-o1112 profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/o-o1112" class="crayons-story__secondary fw-medium m:hidden"&gt;
              O-O1112
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                O-O1112
                
                
              
              &lt;div id="story-author-preview-content-4391991" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/o-o1112" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&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%2Fuser%2Fprofile_image%2F4076898%2Fd4838dcb-87c9-4707-8201-c726d84ae222.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;O-O1112&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/o-o1112/pythonjsc-block-engine-v220-run-python-nodejs-lua-php-in-a-single-document-with-4hlb" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Aug 14&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/o-o1112/pythonjsc-block-engine-v220-run-python-nodejs-lua-php-in-a-single-document-with-4hlb" id="article-link-4391991"&gt;
          [Python/JS/C#] Block Engine v2.2.0: Run Python, Node.js, Lua &amp;amp; PHP in a single document with zero-config state pipeline
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/python"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;python&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/opensource"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;opensource&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/o-o1112/pythonjsc-block-engine-v220-run-python-nodejs-lua-php-in-a-single-document-with-4hlb" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;5&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/o-o1112/pythonjsc-block-engine-v220-run-python-nodejs-lua-php-in-a-single-document-with-4hlb#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              1&lt;span class="hidden s:inline"&gt;&amp;nbsp;comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            1 min read
          &lt;/small&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>[Python/JS/C#] Block Engine v2.2.0: Run Python, Node.js, Lua &amp; PHP in a single document with zero-config state pipeline</title>
      <dc:creator>O-O1112</dc:creator>
      <pubDate>Fri, 14 Aug 2026 00:36:32 +0000</pubDate>
      <link>https://dev.to/o-o1112/pythonjsc-block-engine-v220-run-python-nodejs-lua-php-in-a-single-document-with-4hlb</link>
      <guid>https://dev.to/o-o1112/pythonjsc-block-engine-v220-run-python-nodejs-lua-php-in-a-single-document-with-4hlb</guid>
      <description>&lt;p&gt;Hi everyone,&lt;/p&gt;

&lt;p&gt;I want to share &lt;strong&gt;Block Engine v2.2.0&lt;/strong&gt;, an open-source polyglot multi-runtime execution engine designed to eliminate the friction of combining multiple programming languages in software development.&lt;/p&gt;

&lt;h3&gt;
  
  
  💡 Why Block Engine?
&lt;/h3&gt;

&lt;p&gt;Modern applications often leverage different languages for their unique strengths:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Python&lt;/strong&gt; for machine learning, data science, and analytics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js&lt;/strong&gt; for async Web APIs and NPM packages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lua&lt;/strong&gt; for ultra-fast, lightweight embedded calculations (&amp;lt; 300KB RAM footprint).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PHP&lt;/strong&gt; for web string formatting and cryptographic hashing (&lt;code&gt;hash&lt;/code&gt;, &lt;code&gt;openssl&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traditionally, orchestrating these runtimes requires setting up microservices, gRPC, Docker containers, or manual JSON IPC file reading/writing. &lt;/p&gt;

&lt;p&gt;Block Engine solves this by introducing a &lt;strong&gt;Zero-Dependency Polyglot Pipeline&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚡ How It Works (.blkp Polyglot Document)
&lt;/h3&gt;

&lt;p&gt;You write native code blocks (&lt;code&gt;&amp;lt;py&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;js&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;lua&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;php&amp;gt;&lt;/code&gt;) inside a single &lt;code&gt;.blkp&lt;/code&gt; document. Block Engine parses the AST, executes each runtime in isolated subprocesses, and &lt;strong&gt;automatically serializes and transfers state variables&lt;/strong&gt; from one language to the next.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
html
&amp;lt;py&amp;gt;
# Python Stage: Compute analytics data
raw_prices = [100.5, 102.1, 101.8, 105.4, 108.0]
ma5 = sum(raw_prices) / len(raw_prices)
user_name = "Gemini Master"
&amp;lt;/py&amp;gt;

&amp;lt;js&amp;gt;
// Node.js Stage: Automatically receives Python variables (user_name, ma5)
console.log(`[Node.js] Received user: ${user_name}, MA5: ${ma5.toFixed(2)}`);
var final_score = Math.round(ma5);
&amp;lt;/js&amp;gt;

&amp;lt;lua&amp;gt;
-- Lua 5.4 Stage: High-speed recursive computation
function fib(n)
    if n &amp;lt;= 1 then return n end
    return fib(n-1) + fib(n-2)
end
lua_result = fib(10)
&amp;lt;/lua&amp;gt;

&amp;lt;php&amp;gt;
// PHP 8 Stage: Cryptographic SHA-256 Signature
$signature = hash('sha256', $user_name . '|' . $final_score);
echo "[PHP] Audit SHA-256: " . $signature . "\n";
&amp;lt;/php&amp;gt;
This is the link: https://block-io.blockengine.workers.dev/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ai</category>
      <category>javascript</category>
      <category>python</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
