Skip to content

Conversation

@suneetnangia
Copy link

This pull request enhances the agent framework to support dynamic tool loading, enabling tools to add new capabilities during execution. The main changes ensure that the current tools list is passed to tool functions, allowing them to register additional tools on the fly, this allows progressive tools exposure for LLM instead of loading all tools upfront. A new sample is also provided to demonstrate this feature in action.

Framework improvements for dynamic tool loading:

  • Updated function_invocation_wrapper and streaming_function_invocation_wrapper to pass the current tools list in the kwargs to tool functions, allowing tools to dynamically add more tools during execution. [1] [2]

Testing and sample updates:

  • Added assertions in the test mock_get_response to verify that the tools list is present in kwargs and is a list, ensuring correct propagation for dynamic tool loading.
  • Added a new sample script dynamic_tool_loading.py demonstrating how a tool can add new tools (e.g., factorial and fibonacci calculators) to the agent at runtime, and how these tools can be used immediately within the same run.

Copilot AI review requested due to automatic review settings January 22, 2026 22:20
@github-actions github-actions bot changed the title feat: enable dynamic tool loading by passing tools list in kwargs [progressive exposure] Python: feat: enable dynamic tool loading by passing tools list in kwargs [progressive exposure] Jan 22, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Jan 22, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _tools.py7627490%226, 272, 323, 325, 353, 523, 555–556, 658, 660, 680, 698, 712, 724, 729, 731, 738, 771, 827–829, 870, 895–904, 910–919, 955, 965, 1206, 1543, 1629–1633, 1758, 1760, 1826, 1920, 1926, 1970–1971, 1984–1985, 2028, 2114, 2152–2153, 2183–2185, 2223–2224, 2234, 2291–2292, 2299–2300
TOTAL17486270384% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3229 213 💤 0 ❌ 0 🔥 1m 8s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables progressive/dynamic tool exposure by forwarding the active tools list to tool functions via **kwargs, allowing tools to register additional tools during execution.

Changes:

  • Pass the current tools collection into tool runtime kwargs in both non-streaming and streaming function invocation wrappers.
  • Extend kwargs-propagation tests to assert the tools list is present in tool **kwargs.
  • Add a new Python sample demonstrating dynamic tool loading at runtime.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
python/packages/core/agent_framework/_tools.py Injects the current tools list into custom_args passed to tool execution for dynamic tool registration.
python/packages/core/tests/core/test_kwargs_propagation_to_ai_function.py Adds assertions ensuring tools is propagated in tool **kwargs.
python/samples/getting_started/tools/dynamic_tool_loading.py New sample showing a tool that adds factorial/fibonacci tools during the same agent run.

# Access tools list directly
tools_list = kwargs.get("tools")

if not tools_list:
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this sample, if not tools_list: will treat an empty list as missing. Since the framework can legitimately pass an empty tools list, this should distinguish None/missing from an empty list (and ideally validate the type before branching) so the error path isn’t triggered incorrectly.

Suggested change
if not tools_list:
if tools_list is None:

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the suggestion is valid in this instance.
Since we are checking in the tool itself, framework should never pass is an empty i.e. there should be at least 1 tool?

suneetnangia and others added 4 commits January 22, 2026 23:42
- Fixed inconsistency where approved tool executions didn't receive kwargs['tools']
- Both async and streaming approval paths now use custom_args_with_tools
- This ensures dynamic tool loading works consistently with approvals
- Added comprehensive test coverage for tools identity checks
- All tests verify tools list is the same object reference for mutation
@markwallace-microsoft markwallace-microsoft added the documentation Improvements or additions to documentation label Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants