Python: accept newly discovered tools in client search results - #2768
Draft
adityachaudhry wants to merge 2 commits into
Draft
adityachaudhry wants to merge 2 commits into
adityachaudhry wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft scope note: this prototype still requires an initialized deferred inventory and calls
session.tools.setinternally. It does not implement descriptor-only startup or carry new definitions directly in the pending search result. The intended no-startup-discovery, no-replacement-RPC flow requires changes to the CLI/runtime Responses provider, result schema, and dispatch registry before this is the complete solution.A Python
tool_search_tooloverride can discover tools that were not registered when the session started, but returning their names intool_referencesdoes not register their definitions or handlers. Applications currently have to replace the external tool catalog through the low-level RPC and handle the new calls themselves.This adds
ToolResult(tools=[...])for successful search overrides. The SDK preserves the existing catalog, registers new definitions and handlers before completing the search call, and forwards their names as tool references. The CLI can then emit a clienttool_search_outputand dispatch the discovered tools through the usual Python handlers.Returned names must be new and unique; existing tools can be referenced with
tool_references. Registration is serialized, definitions are JSON-validated before publishing local state, and an explicit RPC rejection rolls back the new handlers. Ambiguous transport failures retain handlers because the runtime may already have applied the update.This uses the existing experimental
session.tools.setRPC internally. It does not change the runtime's search activation rules: the CLI must already have an active deferred inventory. Descriptor-only startup without any initialized tools is a separate runtime limitation. Directsession.tools.setcalls must not be mixed with this SDK-owned catalog.Validation:
npm run check:pythonpassed; 585 Python unit tests passed.mainand passes with this change.gpt-5.6-solResponses runs on Copilot CLI 1.0.89-1 selected two different MCP servers from a five-server catalog. Each produced a clienttool_search_call, callback-driven MCP discovery, a matching clienttool_search_outputwith new function definitions, and SDK-dispatched MCP execution.Related to #1896. Python-only draft for API review and cross-language alignment.