What is KML? Deep Dive into Kyronix Markup Language & Deterministic Tool Parsing
# What is KML? Deep Dive into Kyronix Markup Language & Deterministic Tool Parsing
Building production-grade autonomous coding agents requires executing thousands of code edits, terminal commands, and file operations per hour. However, developers relying on standard JSON tool calling frequently encounter subtle, infuriating failure modes: malformed string escaping, unclosed brackets, and syntax errors that break agent execution loops.
To solve this fundamentally, we built **Kyronix Markup Language (KML)**—a proprietary XML-based tool execution specification engineered for deterministic AST parsing, streaming validation, and zero-error client tool dispatch.
---
The Core Problem: Why JSON Tool Calling Fails at Scale
Standard LLM tool calling platforms force models to serialize structured tool calls into JSON objects. When an agent is asked to write multi-line code files or raw shell scripts, the output looks like this:
1{2 "name": "write_file",3 "arguments": "{\"path\": \"src/utils.ts\", \"content\": \"export const quote = \"hello\";\nconsole.log(\"test\");\"}"4}
This approach breaks down rapidly in real-world software engineering tasks due to five structural flaws:
1. Escape Sequence Decay When an LLM writes code that contains quotes (`"`), backslashes (`\`), or string interpolation (`` ${val} ``), it must double-escape every special character. Small model context drift leads to unescaped quotes, corrupting the JSON payload and throwing `SyntaxError: Unexpected token` during `JSON.parse()`.
2. Lack of Streaming Execution (Blocking Overhead) Standard JSON parsers require the entire JSON payload to arrive before it can be parsed. If an agent generates a 500-line source file inside a JSON field, the client executer must sit idle until the closing brace `}` is emitted.
3. Nested Code-in-Code Failure If an agent writes a python script that generates a bash script that outputs JSON, nested escaping requirements grow exponentially. The model inevitably miscounts backslashes, aborting the workflow.
---
The KML Architecture: XML AST & Deterministic Parsing
KML replaces ambiguous JSON strings with explicit XML tags for tool names and child elements for arguments.
1<kyronix>2 <plan>3 I will create the Express server entrypoint and install the required dependencies.4 </plan>5 <tool name="write_file" executionId="exec_99201">6 <path>src/server.ts</path>7 <content>8import express from 'express';
dotenv.config(); const app = express(); app.use(express.json());
app.get('/health', (req, res) => { res.json({ status: 'ok', timestamp: Date.now() }); });
app.listen(3000, () => { console.log('Kyronix Server running on http://localhost:3000'); }); </content> </tool> <tool name="terminal" executionId="exec_99202"> <command>pnpm add express dotenv</command> <cwd>/app/project</cwd> </tool> <summary>Created src/server.ts and installed express dependencies.</summary> <status>complete</status> </kyronix> ```
---
How KML AST Parsing Works under the Hood
When `@kyronixai/executer` receives a KML response stream over WebSockets, the `KMLParser` module ingests raw chunks and builds an Abstract Syntax Tree (AST):
1export interface KMLAST {2 root: KMLNode;
export interface KMLNode { tag: string; // e.g. "tool", "path", "content" attributes: Record<string, string>; // e.g. { name: "write_file", executionId: "exec_99201" } children: (KMLNode | string)[]; } ```
Step-by-Step Execution Pipeline:
1. **Incremental Chunk Parsing**: `KMLParser` identifies opening `<tool name="...">` tags instantly. 2. **Raw String Extraction**: Text inside `<content>` tags is treated as literal character sequences, completely avoiding JSON quote-escaping rules. 3. **AST Node Dispatch**: The parsed node is passed to `Dispatcher.dispatch()`. 4. **Security Check**: `PermissionManager` validates that the target path is safe via `Sandbox.isPathSafe()`. 5. **Tool Execution**: Executed directly by host system executors (`ReadFile`, `WriteFile`, `Terminal`, `GitCommand`).
---
Benchmark: KML vs JSON Tool Calling Reliability
We ran 10,000 multi-step coding executions comparing standard JSON schema tool calling against KML XML parsing across 500 complex repository tasks:
| Metric | Standard JSON Tool Calling | Kyronix KML Protocol | | :--- | :--- | :--- | | **Parsing Error Rate** | 8.4% (SyntaxError / Escaping) | **0.00% (Deterministic AST)** | | **Multi-line File Reliability** | 84.2% success | **100.0% success** | | **First-Token Execution Latency** | 2,400ms (Must await closing `}`) | **120ms (Streaming XML tags)** | | **Token Efficiency Overhead** | High (Escaped backslashes `\\`) | **Minimal (Clean XML markup)** |
---
Summary
By replacing brittle JSON payloads with streamable XML AST syntax, **KML provides the rock-solid foundation needed for high-velocity agent execution.**
Ready to try KML? Check out the [@kyronixai/runtime SDK docs](/docs).