Skip to content

fix(transports): dedupe OpenAI tool schemas before strict providers#18497

Open
fjlaowan1983 wants to merge 1 commit into
NousResearch:mainfrom
fjlaowan1983:fix/dedupe-openai-tools-before-api
Open

fix(transports): dedupe OpenAI tool schemas before strict providers#18497
fjlaowan1983 wants to merge 1 commit into
NousResearch:mainfrom
fjlaowan1983:fix/dedupe-openai-tools-before-api

Conversation

@fjlaowan1983

Copy link
Copy Markdown

Summary

Several providers (Anthropic direct, Vertex AI, Azure OpenAI, Bedrock Converse, and other strict OpenAI-compatible routes) reject requests when the tools array contains duplicate function.name entries, typically with HTTP 400 and messages like Tool names must be unique. This change adds a shared guard that keeps the first schema for each name and drops later duplicates at the transport / auxiliary boundary, so bad lists cannot reach the wire.

What changed

  • New helper dedupe_openai_tool_definitions_for_api in agent/transports/base.py.
  • Applied before outbound tool payloads from:
    • ChatCompletionsTransport.build_kwargs
    • AnthropicTransport / BedrockTransport / CodexTransport build_kwargs
    • agent/auxiliary_client (chat completions _build_call_kwargs, plus Codex auxiliary tool conversion path)
  • Duplicate removals are logged at debug level with a count.

This complements existing agent-side dedup (e.g. context-engine schema injection) by hardening the last mile for any caller that still assembled a duplicate list.

Testing

pytest tests/agent/transports/test_chat_completions.py::TestChatCompletionsBuildKwargs::test_tools_included \
       tests/agent/transports/test_chat_completions.py::TestChatCompletionsBuildKwargs::test_tools_duplicate_names_keep_first \
       tests/agent/test_auxiliary_client.py::TestAuxiliaryChatCompletionsToolDedup -q -o addopts=

…quests

Align outbound tools with providers that enforce unique function names (Anthropic, Vertex, Bedrock, Azure, etc.). Adds dedupe_openai_tool_definitions_for_api in transports base and applies it from chat completions, Anthropic, Bedrock, Codex transports and auxiliary chat.completions helpers.

Fixes NousResearch#18478.
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent loop, run_agent.py, prompt builder labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants