Repository navigation
Chat Completions: keep one leading instruction message and render catalogs as user context - #194
Merged
Merged
Conversation
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.
Fixes #190. Related implementation and investigation: #191.
Why this fails
A session with profile instructions and a skill catalog currently sends
system, system, userthrough a custom Chat Completions endpoint. Two instruction layers alone produce the same sequence. Qwen3.5-9B’s published chat template rejects the second system message. We reproduced the reported HTTP 400 on Parasail through OpenRouter using Lightspeed’s custom-provider dialect and a pinned route. DeepInfra accepted the same payload on the same model.How the adapter now renders context
developerfor OpenAI and OpenRouter,systemfor DeepSeek and custom endpoints such as LiteLLM. Skip blank layers and omit the leading message when all layers are blank. Only instruction entries that contribute text map to message 0 in rejection diagnostics.Why catalogs stay out of the leading message
Suppose a run starts with skills A and B, and the agent writes skill C. On the next run the harness can append an updated catalog listing A, B and C. Rebuilding the leading instruction message with that new inventory would change the prompt near the beginning and shorten the prefix eligible for cache reuse. Appending the successor preserves the earlier conversation. A genuine change to profile or environment instructions intentionally rebuilds the leading message.
Catalog removal is a separate concern. The regression test checks that the earlier messages remain a prefix across a refresh. Actual cache hits depend on the serving stack.
Relation to #191
#191 identified the template constraint and contributed the self-hosted Qwen investigation on #190. Its later work also proposes a single instruction prompt and user-role catalogs. This PR was developed independently from
main. Its production change is confined to Chat Completions, with live reproductions that can target pinned OpenRouter backends or a LiteLLM deployment.Verification
cargo test --locked -p llm-runtimeandcargo clippy --workspace --all-targets --locked -- -D warningspassed.To reproduce with
OPENROUTER_API_KEYin the environment or root.env:cargo test --locked -p llm-runtime --test openai_completions_live qwen:: -- --ignored --nocapture --test-threads=1For LiteLLM, set
QWEN_LIVE_BASE_URL,QWEN_LIVE_MODEL, and, if needed,QWEN_LIVE_API_KEY.Platform fixes
https://openrouter.ai/api/v1. The clients append/chat/completionsor/responsesfor the chosen API kind.