fix: accept inline system messages and merge them into system prompt - #262
Open
aceaura wants to merge 2 commits into
Open
fix: accept inline system messages and merge them into system prompt#262aceaura wants to merge 2 commits into
aceaura wants to merge 2 commits into
Conversation
Claude Desktop and Claude Code place reminder/memory blocks in a message
with role "system" inside the messages array. The Literal constraint
rejected those at the FastAPI validation layer, so the request 422'd
before reaching the converters:
422 {"loc":["body","messages",1,"role"],
"msg":"Input should be 'user' or 'assistant'"}
build_kiro_payload() already folds unknown roles into user via
normalize_message_roles(), so accepting them in the model is enough --
no converter change needed.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Accepting the role was only half the fix: normalize_message_roles() folds an inline system message into a user turn, which puts client context into the conversation as if the user had typed it, and inserts a synthetic assistant turn to keep roles alternating. Peel those messages off instead and append them to the system prompt, mirroring convert_openai_messages(). Top-level system stays first. Refs jwadow#190, jwadow#219, jwadow#255 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for the PR! 🎉 Before merge, we need a one-time CLA confirmation. Full CLA text: Please reply once with: You need to write once, all further messages from me can be ignored. |
Author
|
I have read the CLA and I accept its terms
cla-bot[bot] ***@***.***>于2026年7月27日 周一20:03写道:
… *cla-bot[bot]* left a comment (jwadow/kiro-gateway#262)
<#262 (comment)>
Thanks for the PR! 🎉
Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the
project to use it.
Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md
Please reply once with:
I have read the CLA and I accept its terms
You need to write once, all further messages from me can be ignored.
—
Reply to this email directly, view it on GitHub
<#262?email_source=notifications&email_token=AKU4KBWJLC37AFDNDVKM3SD5G5AHTA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBZGEYDGMJTGAYKM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-5091031300>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKU4KBSHF7IADYYQCGNF6735G5AHTAVCNFSNUABGKJSXA33TNF2G64TZHMYTCMJVGQ4DSMRRHA5US43TOVSTWNBZHA3TMNBSHE4DLILWAI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
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.
What
Accept
role: "system"/role: "developer"messages inside themessagesarray and merge their text into the system prompt instead of rejecting the request.Fixes #190, #219, #255.
Why
Claude Code and Claude Desktop place runtime context (
<system-reminder>blobs, memory files, session hooks) in a message withrole: "system"insidemessages.AnthropicMessage.roleisLiteral["user", "assistant"], so Pydantic rejects the request during FastAPI validation — before any downstream normalization runs — and the client cannot complete a single turn:How
Two parts, because widening the
Literalalone is not enough:models_anthropic.py—AnthropicMessage.roleacceptssystemanddeveloper, so the request passes validation. Unknown roles are still rejected, keeping the field constrained.converters_anthropic.py— newsplit_inline_system_messages()peels those messages off and appends their text to the system prompt;anthropic_to_kiro()calls it beforeconvert_anthropic_messages().Widening the
Literalon its own would letnormalize_message_roles()fold the message into a user turn, which puts client context into the conversation as if the user had typed it and triggers a synthetic assistant turn to keep roles alternating. Merging into the system prompt instead mirrors whatconvert_openai_messages()already does for OpenAIrole: "system", so both APIs now treat inline system messages the same way. Top-levelsystemstays first; inline parts are appended in the order the client sent them.This matches the approach @W0n9 proposed in #190.
Tests
tests/unit/test_models_anthropic.py—TestAnthropicMessageRoles(5 tests): each accepted role validates (parametrized), unknown roles still raise, and a full request carrying asystemmessage validates.tests/unit/test_converters_anthropic.py—TestSplitInlineSystemMessages(7 tests): extraction ofsystemanddeveloperroles, multiple system messages joined in order, text extracted from content blocks (thecache_controlshape Claude Code sends), empty content skipped, normal conversations unchanged, empty list.TestAnthropicToKiroInlineSystem(4 tests): inline context reaches the Kiro payload, top-levelsystemprecedes inline text, the system message does not become a history turn, and a request of only system messages raisesValueError(surfaced as a client error byroutes_anthropic).Full suite: 1708 passed.
🤖 Generated with Claude Code