Skip to content

fix: namespace repeated tool call IDs - #1

Draft
ting-hong-shieh wants to merge 1 commit into
fix/reversible-tool-use-idsfrom
fix/unique-tool-call-occurrence-ids
Draft

fix: namespace repeated tool call IDs#1
ting-hong-shieh wants to merge 1 commit into
fix/reversible-tool-use-idsfrom
fix/unique-tool-call-occurrence-ids

Conversation

@ting-hong-shieh

Copy link
Copy Markdown
Owner

What

  • Generate occurrence-aware Anthropic tool_use IDs from the source response ID and tool index.
  • Restore the provider's original tool-call ID when Anthropic tool calls and results are replayed to an OpenAI-compatible backend.
  • Cover buffered and streaming translation, including fragmented stream fields and missing-ID fallback behavior.

Why

OpenAI-compatible providers may reuse IDs such as call_0 in consecutive responses. Passing those IDs through unchanged creates duplicate Anthropic tool_use IDs, which can mispair tool results and leave agent workflows looping.

Addresses NVIDIA-NeMo#502.

Depends on NVIDIA-NeMo#397 and is intentionally stacked on fix/reversible-tool-use-ids.

Before / after

Before:

chatcmpl-first  / call_0 -> Anthropic call_0
chatcmpl-second / call_0 -> Anthropic call_0

The repeated Anthropic ID made replay ambiguous.

After:

chatcmpl-first  / call_0 -> Anthropic sy64o_<first occurrence>
chatcmpl-second / call_0 -> Anthropic sy64o_<second occurrence>

The Anthropic-facing IDs are distinct, while both replay to the provider's original call_0.

How tested

  • uv run ruff check .
  • uv run mypy switchyard
  • uv run pytest tests/ -v — 147 passed, 2 skipped
  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace
  • Buffered and streaming regression tests replay repeated call_0 IDs correctly

Checklist

  • No new classes or public symbols.
  • Unit/regression tests added for the bug fix.
  • No customer-facing documentation change required.
  • Commit signed off per the DCO.

Notes for reviewers

Signed-off-by: Ting-Hong Shieh <32212900+ting-hong-shieh@users.noreply.github.com>
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