Fix: Kiro Gateway Anthropic system message compatibility - #270
Conversation
|
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. |
|
I have read the CLA and I accept its terms |
There was a problem hiding this comment.
Pull request overview
This PR improves Anthropic-API compatibility by accepting system messages embedded inside the messages[] array (as sent by Claude Code), promoting them into the effective system prompt, and ensuring only user/assistant messages become conversation history in the Kiro payload.
Changes:
- Allow
role="system"inAnthropicMessagefor compatibility with clients that send inline system messages. - Add extraction/promotion of inline system messages and merge them with the top-level Anthropic
systemfield during Anthropic鈫扠iro conversion. - Add unit regression tests covering inline system extraction and end-to-end payload inclusion; update
.gitignoreto ignore local venv.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
kiro/models_anthropic.py |
Expands Anthropic message role validation to include compatibility system role. |
kiro/converters_anthropic.py |
Promotes inline system messages into the system prompt and excludes them from history conversion. |
tests/unit/test_converters_anthropic.py |
Adds regression coverage for inline system extraction and payload promotion. |
fix_anthropic-system-message-compatibility_en.md |
Adds English PR-style writeup of the change and validation steps. |
fix_anthropic-system-message-compatibility_zh.md |
Adds Chinese PR-style writeup of the change and validation steps. |
.gitignore |
Ignores .venv/ and normalizes an entry formatting. |
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| for message in messages: | ||
| if message.role == "system": | ||
| system_text = convert_anthropic_content_to_text(message.content) | ||
| if system_text: | ||
| system_parts.append(system_text) | ||
| else: | ||
| conversation_messages.append(message) |
|
|
||
| def test_includes_tools(self): |
|
Superseded by #271, which uses ytchen175:main after merging the fix branch into the fork's main branch. |
Branch:
fix/anthropic-system-message-compatibilityTitle:
Fix: Kiro Gateway Anthropic system message compatibilityDescription
systemmessage inside the Anthropicmessagesarray.Root Cause
Claude Code sent a request containing
messages[1].role = "system". The gateway schema only accepteduserandassistantroles, so Pydantic rejected the request with HTTP 422 before conversion.Old Logic
AnthropicMessage.rolewas limited touserandassistant.New Logic
systemas a compatibility role inAnthropicMessage.systemfield.Why it works
DoD
Code Changes
kiro/models_anthropic.pysystemrole inAnthropicMessage.kiro/converters_anthropic.pytests/unit/test_converters_anthropic.py.gitignoreValidate Results
Result:
249 passed, 1 warning.Additional smoke checks:
claude-opus-5.git diff --check: passed.Commit Messages
Fix: Kiro Gateway Anthropic system message compatibility