Skip to content

feat(inkling): message-frame protocol — reasoning, text and JSON tool calls (#650 P3) - #686

Merged
goodmai merged 1 commit into
mainfrom
feat/650-p3-inkling-protocol
Nov 22, 2026
Merged

goodmai merged 1 commit into
mainfrom
feat/650-p3-inkling-protocol

Conversation

@goodmai

@goodmai goodmai commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Part of #650 (Inkling 2), P3 first half: the response protocol.

What

  • Fork pin 580bcbd → 70d0190 (goodmai/mlx-swift-lm branch basalt-650-inkling-protocol, one commit on top of perf(qwen3next): fused 512-expert router in the fork and in streamed prediction (#642 P1) #681's pin):
    • ToolCallFormat.inkling and InklingStreamAdapter/InklingToolCallParser, ported from Add Inkling 2 Mini and Small ml-explore/mlx-swift-lm#821 (MIT, Apple's header kept) and adapted to this fork's NaiveStreamingDetokenizer;
    • frames <|message_model|>name<|content_kind|>payload<|end_message|> are parsed by token id: thinking → reasoning events, text → response, <|content_invoke_tool_json|> → schema-checked tool calls (undeclared tool, bad JSON, name mismatch → rejected calls); stop at <|content_model_end_sampling|>;
    • the format is inferred from a template carrying <|content_invoke_tool_json|> or tool_parser_type inkling/inkling2, and is kept as a whole-protocol format like Harmony and Onyx.
  • basalt:
    • Inkling2Model.toolCallFormat = .inkling;
    • InklingReasoningStateMachine taps <|content_thinking|> frames. The fork's public Generation stream drops reasoning for framed protocols by design, so basalt taps it the way it already does for Onyx. OnyxReasoningTapIterator is now generic over a small ReasoningTokenParser protocol, so both share the box and the relay path.

Measured on the real model

mlx-community/Inkling-2-Mini-oQ3e-mtp, release build, basalt serve, temperature 0, CI idle, GPU lock:

Request Result
/v1/chat/completions turn 1, tool get_weather(city, days:int) finish_reason: tool_calls, get_weather({"days":3,"city":"Paris"}) (integer kept), content empty, reasoning in reasoning_content
turn 2 with the call and the tool result in history final answer from the tool output, no protocol tokens in content
/v1/messages (Anthropic) thinking block, then tool_use get_weather {"city":"Tokyo"}, stop_reason: tool_use

Tests

InklingProtocolTests (new):

  • the reasoning parser reports only thinking frames, flags the first non-thinking frame, and treats <|end_message|> written as text as text;
  • Inkling2Model selects .inkling, and the real template infers it;
  • through handOffWithOnyx → GenerationRelay, a scripted turn (thinking, text, tool frame, end sampling) yields the reasoning, the text, and one tool call weather.get {"days":3}.

Inkling, Muse Glimmer (Onyx tap), and tool-call suites: 65 tests pass.

Not in this PR (rest of P3)

  • Restart rule for prompt-cache reuse after a re-rendered history, and the bitwise anchor-restore test.
  • The real two-turn Claude Code trace (turn-2 TTFT), and the 50 scripted tool turns gate.

Verified

swift build -Xswiftc -warnings-as-errors clean; no new comments; no size limit exceeded.

🤖 Generated with Claude Code

https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh

… calls (#650 P3)

- Fork pin 580bcbd -> 70d0190 (goodmai/mlx-swift-lm
  basalt-650-inkling-protocol): ToolCallFormat.inkling and
  InklingStreamAdapter, ported from ml-explore/mlx-swift-lm#821. Frames are
  parsed by token id, so marker-shaped text in a payload is text.
- Inkling2Model.toolCallFormat is .inkling.
- InklingReasoningStateMachine taps <|content_thinking|> frames, because
  the fork's public Generation stream drops reasoning for framed
  protocols. The Onyx reasoning tap iterator is now generic over a
  ReasoningTokenParser, so both protocols share the box and the relay path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant