Skip to content

Join multiple system instructions in Responses API requests - #447

Open
Pybsama wants to merge 2 commits into
huggingface:mainfrom
Pybsama:join-responses-instructions
Open

Pybsama wants to merge 2 commits into
huggingface:mainfrom
Pybsama:join-responses-instructions

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Updated Responses.createRequestBody (Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift) and OpenResponsesAPI.createRequestBody (Sources/AnyLanguageModel/Models/OpenResponsesLanguageModel.swift) to collect all non-empty .system instructions in order and join them with "\n" in body["instructions"], matching AnthropicLanguageModel and GeminiLanguageModel.
  • Previously, each .system message overwrote body["instructions"], so transcripts with multiple .instructions entries silently dropped earlier instructions (and a trailing empty .text("") instruction could clear earlier instructions).

Testing

  • Added cross-platform regression tests in ResponsesSystemInstructionsTests (Tests/AnyLanguageModelTests/ResponsesSystemInstructionsTests.swift):
    • instructionsEntriesAreJoinedWithoutImages(provider:streaming:) (reproduced failure across all 4 (provider, streaming) cases pre-fix)
    • trailingEmptyInstructionsDoesNotClearEarlierInstructions(provider:)
    • emptyInstructionsOmitsField(provider:)
  • Ran swift format lint --strict --recursive . (PASS)
  • Ran swift test --disable-index-store --filter "ResponsesSystemInstructionsTests|OpenAIToolCallHistoryTests" (PASS)
  • Ran swift test --skip-build --disable-index-store --skip OllamaLanguageModelTests (1,119 tests in 116 suites PASS)

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