Skip to content

feat(gateway): add rewrite-all-system-to-user upstream flag - #799

Merged
yyyr-p merged 4 commits into
Menci:mainfrom
yyyr-p:devin/1796036174-upstream-system-compat
Dec 1, 2026
Merged

yyyr-p merged 4 commits into
Menci:mainfrom
yyyr-p:devin/1796036174-upstream-system-compat

Conversation

@yyyr-p

@yyyr-p yyyr-p commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add rewrite-all-system-to-user, a default-off per-upstream compatibility flag for upstreams that don't handle non-empty system instructions correctly.

  • Rewrite existing system and developer messages to user.
  • Move non-empty top-level system instructions into a leading user message and leave the original field empty.
  • If the original conversation does not start with a user message, send an empty leading system message or the protocol's equivalent. If it already starts with user and has no top-level instruction to move, do not add one.

Applies to OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, and Gemini GenerateContent. The rewrite runs for the selected upstream protocol, after translation when applicable.

Verification

  • 44 tests passed across 8 test files, including Chat Completions translated to Gemini.
  • Scoped ESLint and Gateway/Web type checks passed.

yyyr-p and others added 2 commits November 30, 2026 12:17
Gate the rewrite behind rewrite-all-system-to-user. Preserve the original system and developer roles in <system_instruction> and <developer_instruction> tags, and declare those tags in the leading system instruction when needed.
@yyyr-p
yyyr-p marked this pull request as draft November 30, 2026 14:45
@yyyr-p
yyyr-p marked this pull request as ready for review November 30, 2026 15:01
@yyyr-p
yyyr-p merged commit 7208f61 into Menci:main Dec 1, 2026
21 checks passed
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