Skip to content

responses: preserve namespace tool identity - #16263

Open
pd95 wants to merge 4 commits into
ollama:mainfrom
pd95:feature/responses-namespace-tools-upstream
Open

pd95 wants to merge 4 commits into
ollama:mainfrom
pd95:feature/responses-namespace-tools-upstream

Conversation

@pd95

@pd95 pd95 commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Fixes #15921.

Ollama flattens namespace tools for its internal chat representation and must
recover the original (namespace, name) pair when returning a Responses tool
call. Losing that pair prevents clients such as Codex from routing the call to
the requested MCP tool. The Codex multi-agent failure reported in #18284 is a
real-world example of this round-trip symptom.

Current main expands namespace declarations and restores ordinary namespaced
calls, but its lookup is not injective. For example,
namespace a.b / member c, namespace a / member b.c, and flat function
a.b.c all produce the same internal name. Resolution then depends on
declaration order and can return the wrong tool identity to the client. Mixed
web-search output also bypasses request-scoped namespace restoration.

What this changes

  • builds one request-scoped, bidirectional mapping for declared tools,
    tool-search results, and tool-call history;
  • rejects duplicate or colliding identities instead of selecting one by
    declaration order;
  • canonicalizes dotted, colon, and Codex-style aliases when they are
    unambiguous;
  • restores the exact namespace and child name in streaming, non-streaming, and
    mixed web-search Responses output.

Scope

The change is limited to Responses request/output translation and the existing
web-search response assembly path.

Validation

go test ./openai ./middleware -count=1 passes. Focused tests cover namespace
round trips, collision rejection independent of declaration order, legacy
aliases, tool-search results, history, streaming, non-streaming, and mixed
web-search output. Repository lint and go build ./... also pass.

Runtime validation passes non-streaming, streaming, and namespaced-history
Responses requests with gpt-oss:20b.

AI assistance

Codex materially assisted with implementation review, tests, validation, and
this PR description. The contributor reviewed the final changes and test
results.

@pd95

pd95 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

@drifkin would you mind taking a look at this PR (#16263) when you have a chance?

This PR adds support for namespaced tool calls in the OpenAI-compatible Responses API, addressing #15921. It translates type: "namespace" tools into Ollama’s existing flat internal tool naming, then restores
the namespace field on Responses API function call output items so clients like Codex can resolve MCP tools correctly.

If the approach looks reasonable, I’d appreciate a review or help routing it toward merge.

@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch from cd9d5f2 to eb608e4 Compare June 22, 2026 19:59
@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch from eb608e4 to cbb9112 Compare July 8, 2026 12:30
@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch 3 times, most recently from 12bff25 to a962d6a Compare August 14, 2026 21:08
@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch 2 times, most recently from 507808d to fbeb2c0 Compare August 28, 2026 14:46
@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch 2 times, most recently from 15b572c to 3c05eb9 Compare September 5, 2026 09:33
@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch 2 times, most recently from c53c2eb to 3a78148 Compare September 18, 2026 12:17
@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch 3 times, most recently from 6e8daeb to e41a8b9 Compare September 23, 2026 18:40
@pd95 pd95 changed the title responses: support namespace tool calls responses: preserve namespace tool identity Sep 23, 2026
@pd95

pd95 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

@drifkin, a quick update following the namespace support added by @dhiltgen in #17593—thanks for providing that foundation.

I have rebased and substantially narrowed this PR so it no longer duplicates the basic namespace expansion. It is now a single commit containing only the remaining correctness pieces:

  • use one request-scoped, bidirectional namespace/name resolver;
  • reject duplicate or ambiguous flattened identities instead of resolving them by declaration order;
  • canonicalize dotted, colon, and Codex-style aliases when unambiguous;
  • restore namespace identity for mixed web-search/function-call output;
  • cover streaming, non-streaming, history, tool-search output, and collision cases with focused tests.

The PR is based directly on current main, and its focused tests, repository lint, build, and runtime namespace round-trip checks pass.

Would you be willing to take another look at the updated, reduced diff?

@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch from e41a8b9 to 6c1c328 Compare September 27, 2026 20:56
@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch from 6c1c328 to 54dcfb5 Compare October 8, 2026 18:16
pd95 and others added 4 commits October 21, 2026 12:32
Run the nested configure command before each native build while preserving the v0.34.4 mlx, mlxc, and XGrammar targets.

Co-authored-by: Codex <noreply@openai.com>
Preserve explicit pinned llama.cpp, MLX, and MLX-C sources for per-architecture builds.

Co-authored-by: Codex <noreply@openai.com>
Order Metal v4 after v3 only when both targets exist, and cover reversed and single-target declaration shapes.

Co-authored-by: Codex <noreply@openai.com>
Reconcile request-scoped namespace identities with v0.34.4 Responses and tool-search conversion, including legacy aliases and mixed web-search output.

Co-authored-by: Codex <noreply@openai.com>
@pd95
pd95 force-pushed the feature/responses-namespace-tools-upstream branch from 54dcfb5 to a8f5a12 Compare October 21, 2026 21:27

This branch has not been deployed

No deployments
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.

OpenAI Compatibility: Support namespace field in tool calls for Responses API parity

1 participant