Repository navigation
llamacpp adapter: her text turn renders and parses through the model's own chat handling (S2b slice 1) - #6145
Merged
Merged
Conversation
…nged Serving S2b routes a resident's turn through the model's own chat handling (ChatRender, #6142): render with tools and reasoning, parse native tool calls. That work lands in generate_text, a 392-line body inside the 853-line adapter file, which would cross the 1,000-line rule. This is the move only: LlamaCppAdapter::generate in llamacpp_adapter/generate.rs (404 lines), the trait method delegates. No line of the body changes; llamacpp_adapter.rs is 463 lines. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
The streamed OpenAI-compatible path assembled a model's native tool calls inline in openai_adapter/stream.rs (name filter, UnparsedArguments::parse with the generation end, the unparseable-arguments probe, ToolCall). The in-process engine reads the same calls from the model's own chat parser (S2b), so the assembly moves to inference::native_tool_calls::assemble and both call it: a call's fate reads the same whichever engine served her turn. Behavior unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…s own chat handling (S2b slice 1) A text turn now renders through ChatTemplates (llama.cpp common/chat, #6142) with her tools, from the same wire_messages and openai_tools serving sends, and what she writes is parsed by that same ChatRender into content, reasoning and native tool calls. The calls are assembled by native_tool_calls::assemble, the owner the streamed path uses; content blocks come from native_tool_calls::content_blocks, which the streamed path now uses too. - LlamaCppBackend::render_chat_turn: templates load once beside the model (OnceLock, Mutex: the templates are Send, not Sync); the lock is held for the render alone, released before decode. - One ChatRender per request, from render to final parse. - A named tool_choice is refused (ChatTurnError::SpecificToolChoice): the model's own tool-choice parser takes a mode, and widening a name to any tool would be a silent change. - Media turns keep the plain template until mtmd takes a chat render. Not in this slice (slice 2): the render's grammar, lazy triggers, preserved tokens and extra stops into the sampler, then the four proofs. No resident is routed here until then. Tests: her_turn_renders_the_wire_messages_and_tools_serving_sends, a_named_tool_choice_is_refused_not_widened, a_decode_that_reached_its_cap_ended_at_the_output_limit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…d (stringly_errors ratchet) f556a46 moved generate_text's body into an inherent LlamaCppAdapter::generate, which added a second Result<_, String> signature beside the trait's (stringly_errors 4245 -> 4246). The move is now the whole AIProviderAdapter impl into llamacpp_adapter/provider.rs, the way openai_adapter/provider.rs holds that adapter's: no new signature, generate.rs is gone. Verified byte-exact: provider.rs after its header equals canary's llamacpp_adapter.rs lines 188-853; llamacpp_adapter.rs equals lines 1-187 plus 'mod provider;'. 853 -> 188 + 673 lines. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…o S2b slice 1 Git carried slice 1's edits through the generate.rs -> provider.rs rename: the chat render, parse and response fields now sit inside AIProviderAdapter::generate_text in provider.rs (704 lines). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ngth, only media turns build the plain-template messages (Codex on #6145) - The registry template is the chat render's override only for a model without its own; with one, common/chat loads the GGUF's templates (its named tool_use one among them), which an explicit override suppresses (common/chat.cpp:761-776). - finish_reason(end, called): the output limit first, so a turn the cap cut (even mid-call) reads Length, never ToolUse/Stop. - carries_media decides the path before anything is built: a text turn no longer clones every message into ChatMsg to discard it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…'s default OR named tool_use template (Codex on #6145) A GGUF carrying only tokenizer.chat_template.tool_use read as having no template (chat_template() queries the default only), so the registry template masked the model's own. Now the one-time ChatTemplates init asks Model::has_chat_template (pointer check, no copy) for the default or the named tool_use template, and asks for the registry template only when both are absent. The registry lookup is a closure: a text turn copies no template string; the media path resolves its plain template where it renders. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ames NO_TRAINED_CONTEXT by its crate path Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…to fable/s2b-chat-turn
…fusal carries the choice, assemble takes the calls as they come Pays back the three ratchets bb0a6f2 raised: - string_identities (+3): prompt_of and parse_turn deserialize Described / ParsedMessage / ParsedCall instead of reading .get("prompt"|"tool_calls"|"id") by name. - stringly_errors (+1): ChatTurnError::SpecificToolChoice carries the ToolChoice, not its name. - contract_shape (+1): native_tool_calls::assemble takes impl IntoIterator<Item = StreamToolAccum> (it consumes them); parse_turn feeds its calls straight in, no intermediate Vec. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ngs 13 -> 12); the tests import it themselves Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply
marked this pull request as ready for review
November 18, 2026 20:26
# Conflicts: # core/continuum-engine/src/inference/llamacpp_adapter/provider.rs
joelteply
added a commit
that referenced
this pull request
Nov 19, 2026
…'s ChatRender), the residents' contract ported onto it Canary's serving S2a/S2b (#6142, #6145) and this branch's 75cea66 built the same capability twice (chat_boundary.cpp + ChatRender + chat_turn.rs, and chat_template.cpp + chat_template.rs + native_chat.rs); both defined continuum_chat_free, so they could not link together. Canary's stays the owner (agreed with Codex, 06:07Z). Ported onto it, the three things residents need that it lacked: - the think budget: chat_boundary's continuum_chat_reasoning_budget (llama.cpp's common_reasoning_budget, what llama-server ran) as llama::SamplerChainBuilder::reasoning_budget, bounded by the render's own thinking tags (chat_turn::Described::think_bound); a stated zero budget renders with enable_thinking off (chat_turn::thinking_request); - the template's extra stops (Described::additional_stops) into the decode's stops; - her view's end (chat_turn::view_text: her view rendered by the same templates, generation prompt off; describe now returns generation_prompt), passed as TurnPrompt.stable_prefix so the engine checkpoints her there (CONTINUUM-ENGINE 4.15). Deleted: core/llama/chat_template.cpp, src/safe/chat_template.rs, llamacpp_adapter/native_chat.rs, LlamaCppBackend::chat_templates and its second `chat` field, the inline AIProviderAdapter impl (it lives in provider.rs on canary), and the llama crate's serde deps. The fork pin moves to 2869b164a7 (fable/persona-files merged with 51c7089eec, so it carries canary's 74be098b5 and #6156's pooled graph). Checked with serving down (06:08-06:13Z): cargo check of continuum-core, continuum-engine --tests, the persona crates and the metal example; llama chat tests 3/3; persona-engine 21/21. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Serving S2b slice 1, stacked on #6144 (move-only). Design agreed with Codex on airc 2026-11-18 18:52Z.
A text turn on the in-process adapter now renders through the model's own chat handling (
ChatTemplates, #6142) with her tools, and what she writes is parsed by the sameChatRenderinto content, reasoning and native tool calls.Owners reused, nothing parallel:
request_body::wire_messagesandrequest_body::openai_tools, which serving already sends and the trainer renders a lived turn from;openai_adapter/stream.rsmoves toinference::native_tool_calls::assemble, which both paths now call;native_tool_calls::content_blocks, which both paths now use.Codex's conditions:
ChatRenderper request, from render to final parse.ChatTemplatesisSend, notSync. It sits in aOnceLock<Result<Mutex<_>>>beside the model, and the lock is held for the render alone, released before decode.Refused rather than widened: a named
tool_choice(ChatTurnError::SpecificToolChoice), because the model's own parser takes a mode.Media turns keep the plain template until mtmd takes a chat render.
Slice 2 (separate PR): the render's grammar, lazy triggers, preserved tokens and extra stops go into the sampler. Then the four proofs: a streamed native tool call, a schema, a reasoning budget, and a resumed native prefix.
Measured
Not built locally (this machine serves), so CI is the first compile. Model-free tests:
her_turn_renders_the_wire_messages_and_tools_serving_sendsa_named_tool_choice_is_refused_not_wideneda_decode_that_reached_its_cap_ended_at_the_output_limitThe real-model checks are slice 2's four proofs.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo