Skip to content

fix(translation): encode Responses tool turns correctly#111

Open
nachiketb-nvidia wants to merge 1 commit into
mainfrom
nachiketb/fix-responses-tool-turn-translation
Open

fix(translation): encode Responses tool turns correctly#111
nachiketb-nvidia wants to merge 1 commit into
mainfrom
nachiketb/fix-responses-tool-turn-translation

Conversation

@nachiketb-nvidia

@nachiketb-nvidia nachiketb-nvidia commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What

Fix OpenAI Responses request encoding for normalized tool turns.

  • Encode function_call.arguments as a JSON string, as required by the Responses API.
  • Drop Anthropic-signed private thinking when targeting Responses input.
  • Preserve unsigned Responses reasoning items during Responses round trips.

Why

Anthropic tool-use input is represented as structured JSON in the neutral request type, while the
Responses API requires the same arguments to be serialized as a JSON string. Anthropic private
thinking also cannot be replayed as a Responses reasoning item.

Keeping this translation behavior in a focused MR avoids coupling provider codec correctness to the
libsy server refactor.

How

The Responses encoder serializes normalized tool-call arguments with the existing json_string
helper. It filters reasoning blocks carrying an Anthropic signature and continues to encode unsigned
reasoning blocks produced by the Responses decoder.

What to review

  1. Anthropic tool-use arguments become valid Responses function_call input.
  2. Signed Anthropic thinking does not leak into Responses input.
  3. Responses reasoning still survives decode and re-encode.

Validation

  • cargo fmt --all --check
  • cargo test -p switchyard-translation --test request_translation (34 passed)

Summary by CodeRabbit

  • Bug Fixes
    • Improved translation of Anthropic requests to Responses format by excluding private signed reasoning content.
    • Preserved tool calls and their outputs when private thinking content is present.
    • Encoded tool-call arguments consistently as JSON strings.
  • Tests
    • Added coverage for tool-call argument encoding and private thinking removal during request translation.

Signed-off-by: nachiketb <nachiketb@nvidia.com>
@nachiketb-nvidia
nachiketb-nvidia requested a review from a team as a code owner July 21, 2026 21:17
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c3c82f44-48c2-49a4-8e12-94379abc77c1

📥 Commits

Reviewing files that changed from the base of the PR and between 89edae4 and bdce6dd.

📒 Files selected for processing (2)
  • crates/switchyard-translation/src/codecs/responses/buffered.rs
  • crates/switchyard-translation/tests/request_translation.rs

Walkthrough

Changes

Responses translation

Layer / File(s) Summary
Responses encoding behavior
crates/switchyard-translation/src/codecs/responses/buffered.rs
Signed reasoning blocks are filtered out, unsigned reasoning remains supported, and tool-call arguments are encoded as JSON strings.
Translation regression coverage
crates/switchyard-translation/tests/request_translation.rs
Tests verify string-encoded tool arguments and removal of private thinking while retaining function-call items.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

I’m a rabbit with bytes in my tray,
Hopping signed thoughts away.
Tool arguments curl into strings,
While function calls grow little wings.
Tests cheer: “The payload’s just right!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change by describing the Responses translation fix for tool turns.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

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