interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / spec / LENSHIFT.md

226 lines · 15764 bytes Raw Blame History Source

Lenshift: model-native representation <-> canonical intent

Lenshift owns representation differences. It never executes, never authorizes, never decides whether a capability exists. It produces LenshiftTurn:

LenshiftTurn {
  dialect, dialect_version, parser_version, model,
  text: string              // the model's prose, with tool-call markup and think blocks removed
  reasoning_digest: Digest|null   // sha256 of the reasoning channel; raw reasoning not kept
  intents: [tool_request]   // structurally valid calls, in emission order
  rejected: [{ index, code, message, source_digest }]   // malformed calls, in emission order
  partial: bool             // a tool call was cut off (streaming/truncation)
}

rejected entries also become rejected results (malformed_tool_call) so the model learns the call was not understood. Partial calls are rejected, never guessed.

Every intent's provenance records dialect, parser_version, model, source_turn, source_call_id (if the dialect has ids), source_digest (sha256 of the exact dialect-native representation of that one call), raw_name, coercion.

Tool name canonicalization: raw_name is split on the last . into namespace + name only when the prefix matches ^[a-z][a-z0-9_]*$; otherwise namespace = null and name = raw_name. Lenshift never renames tools.

Request ids: source_call_id when the dialect provides one, else "<trace_id>:t<turn>:c<index>" assigned by the caller. Lenshift itself does not know the trace; it emits request_id = null and the pipeline fills it. (In the reference implementations the parse function takes the trace and turn so ids are filled in one step.)

Dialect openai (version 1)

Input: one assistant message object {role, content, tool_calls?, reasoning_content?} as returned by an OpenAI-compatible /v1/chat/completions (non-streamed, or streamed and assembled by the caller; dialect openai_stream below assembles a stream).

Render result -> {"role":"tool","tool_call_id":<source_call_id or request_id>,"content":<string>} where content is data JSON-serialized (canonical) for ok, otherwise {"error": {"code":..., "message":...}, "status": ...} serialized. Never raw secrets.

Dialect openai_stream (version 1)

Input: the body of a streamed OpenAI-compatible /v1/chat/completions response (stream: true), as one string of Server-Sent Events, exactly as the server sent it. Lenshift assembles the fragments into one assistant message and parses it with the openai rules above. Grounded in the six streamed captures under qualification/captures/qwen35-{ollama,llamacpp,sglang}/h{1,2}-*.json: Ollama sends each tool call whole; llama.cpp sends id, name and "{" first and the arguments in later pieces; SGLang does the same but repeats "id": null, "name": null in every later piece and sends content: "\n\n" before the call.

Framing (the data subset of the WHATWG Server-Sent Events format):

Assembly, chunk by chunk in arrival order:

Assembled message: {"role": "assistant", "content": <text>, "tool_calls": [...]} with calls in ascending index, each {"type": "function", "function": {"name", "arguments"}} plus "id" when one arrived; "reasoning_content" is present when reasoning text arrived. A call with no name or no arguments keeps the field absent and is rejected by the openai rules.

Completeness: the stream is complete only when finish_reason is stop, tool_calls or function_call. Otherwise (absent, length, content_filter, anything else) every call of the turn is rejected malformed_tool_call "truncated tool call" with its own index, digest and id, and partial = true when there was at least one call. Text is kept. A cut-off stream is never guessed, even when a call's arguments already parse.

Stream errors and non-string input: no intents, text = "", one rejected entry at index 0 (malformed_tool_call, the error message, source_digest = sha256 of the body text, or of its JCS form for a non-string), partial = false.

Intents carry dialect = "openai_stream", dialect_version = "1"; source_digest is of the assembled call object (JCS), as for openai. Render result is the same as openai.

Dialect qwen35 (version 1)

Grounded in the official Qwen/Qwen3.5-9B chat template (sha256 a4aee8af…, lines 53, 105-137).

Input: the assistant turn as text (what the server returned in content, possibly with the reasoning included inline).

Render result -> the content of a role: tool message: <tool_response>\n<serialized>\n</tool_response> with the same serialization as the openai dialect. (The chat template wraps tool messages itself; Lenshift emits the inner text and the caller places it in a tool role message.)

Both forms of a Qwen3.5 tool call are real inputs: raw XML when the caller reads the model text, and OpenAI tool_calls when a serving engine's parser converted it. The openai dialect handles the second; qualification runs both.

Dialect aien_legacy (version 1)

The textual protocol of aien-cli (aien-sovereign-core 7580039). Ground truth, all under crates/aien-cli/src/: parser client.rs:350-419 (parse_tool_call_json, extract_tool_calls), prompt-side format client.rs:100-160, result reinjection main.rs:330-340 (the same shape repeats at main.rs:414-421 and :537-553). Input: the assistant turn as text.

aien-cli streams reasoning in a separate reasoning / reasoning_content delta and keeps it out of the text it parses (client.rs:297-325); it never looks for <think> in the text.

Lenshift's rules (differences from aien-cli are marked deviation):

Render result -> {"role":"user","content":"<tool_response name=\"NAME\">\n<serialized>\n</tool_response>"} with the shared serialization of the openai dialect. NAME is the intent's raw_name; without an intent (for example a rejected call) it is unknown. aien-cli serializes its own result object with serde_json::to_string; Lenshift does not reproduce that shape, only the envelope.

Versus qwen35's hermes_json variant: the JSON body grammar is the same, but aien_legacy adds the two repairs, the placeholder-name rule, the fenced fallback and the user-role rendering, and qwen35 accepts the XML <function=...> form which aien-cli does not. They are separate dialects with separate parsers.

Dialect ajax — reserved, not implemented

Ajax (announced 2026-10-02 as a Qwen3.5-9B fine-tune for Odysseus) had no published weights, model card, license, tokenizer or chat template on 2026-10-04. No parser exists. Adding one must require only a new module under dialects/ajax and lenshift/ajax.*, plus fixtures captured from the official artifact: no change to Core. The reference implementations' dialect registry is the abstraction test for that.

Fixtures

dialects/fixtures/<dialect>/<name>.json: {"input": ..., "model": ..., "expected": LenshiftTurn-without-digests, "expected_digests": {...}}. Required openai_stream fixtures: every streamed capture under qualification/captures byte for byte (with its sha256_response); fragmented call; repeated null fragments; two interleaved calls; cut mid-arguments; cut after complete arguments; finish_reason length; unterminated last event; CRLF and comment framing; streamed plain text, complete and cut; assembled arguments not JSON; each stream error. Fixtures record expected_digests, and both runners compare every recorded digest. Required qwen35 fixtures: valid single call; multiple calls; malformed (unclosed function); reasoning plus call; plain answer with no tool; unknown tool name (parses fine); partial/truncated call; multi-line parameter value; JSON-typed parameter; hermes_json form. Required aien_legacy fixtures: valid single call; multiple calls; reasoning plus call; repaired bracket; repaired missing braces; trailing comma (rejected); single quotes (rejected); unterminated (rejected, partial); fenced json fallback; placeholder name (rejected); missing arguments; arguments not object; plain answer. Required openai fixtures: single; multiple; arguments not JSON; arguments not object; missing name; reasoning_content present; plain answer; legacy function_call; arguments as a decoded object (rejected); arguments not a string (rejected).

Fixture provenance: inputs are constructed from the official template grammar, not captured from a live model, until the qualification run under qualification/ captures real outputs and pins them.