Python: Progressive Tools Exposure#3877
Open
suneetnangia wants to merge 5 commits intomicrosoft:mainfrom
Open
Conversation
Signed-off-by: Suneet Nangia <suneetnangia@gmail.com>
Signed-off-by: Suneet Nangia <suneetnangia@gmail.com>
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds “progressive tools exposure” to the Python agent framework by injecting the current tools list into **kwargs for tools that accept keyword arguments, enabling tools to dynamically add additional tools during the same agent run.
Changes:
- Core: inject a mutable
toolslist into tool runtime kwargs during function invocation (python/packages/core/agent_framework/_tools.py). - Tests: add async coverage validating tools-list propagation, dynamic tool addition, persistence across invocations, and approval-mode behavior (
python/packages/core/tests/core/test_kwargs_propagation_to_ai_function.py). - Samples/docs: add a new sample demonstrating dynamic tool exposure and reference it in the samples README (
python/samples/getting_started/tools/function_tool_dynamic_tool_exposure.py,python/samples/README.md).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_tools.py | Injects the tools list into runtime kwargs passed to tools, enabling in-run mutation for progressive exposure. |
| python/packages/core/tests/core/test_kwargs_propagation_to_ai_function.py | Adds tests confirming tools list is available in kwargs and that mutations persist and work with approvals. |
| python/samples/getting_started/tools/function_tool_dynamic_tool_exposure.py | New sample showing a tool that dynamically registers additional math tools at runtime. |
| python/samples/README.md | Adds the new sample to the tools samples index. |
python/samples/getting_started/tools/function_tool_dynamic_tool_exposure.py
Show resolved
Hide resolved
python/packages/core/tests/core/test_kwargs_propagation_to_ai_function.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Suneet Nangia <suneetnangia@gmail.com>
Signed-off-by: Suneet Nangia <suneetnangia@gmail.com>
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.
Motivation and Context
This PR enables loading tools progressively as model (S/LLM) expands on the execution plan, in the same run; in several instances model is frontloaded with too many tools, this results in lower tool selection accuracy (a known concern), bloated context and higher processing costs; this change will allow building solutions where model (S/LLM) will have access to 1000s of tools dynamically without any of the forementioned concerns.
This PR supersedes #3398 (now closed due to major changes in codebase since then)
Description
This pull request introduces dynamic tool loading capabilities to the agent framework, allowing tools to access and modify the list of available tools at runtime. This enables advanced scenarios such as loading new tools based on context or previous tool calls. The implementation is thoroughly tested, and a new sample demonstrates the feature in action.
Core framework enhancements:
**kwargsof tools that accept keyword arguments, allowing tools to inspect or modify the set of available tools during execution. If the tools input is already a list, the same object is used so modifications persist. (python/packages/core/agent_framework/_tools.py) [1] [2]Testing and validation:
kwargsand can inspect it.**kwargsdo not receive the tools list.python/packages/core/tests/core/test_kwargs_propagation_to_ai_function.py)Documentation and samples:
python/samples/getting_started/tools/function_tool_dynamic_tool_exposure.py)python/samples/README.md)Contribution Checklist