Python: Add InvokeFunctionTool action for declarative workflows#3716
Open
moonbox3 wants to merge 4 commits intomicrosoft:mainfrom
Open
Python: Add InvokeFunctionTool action for declarative workflows#3716moonbox3 wants to merge 4 commits intomicrosoft:mainfrom
moonbox3 wants to merge 4 commits intomicrosoft:mainfrom
Conversation
Member
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive support for invoking Python functions as tools in declarative YAML workflows through a new InvokeFunctionTool action. The implementation introduces a well-designed BaseToolExecutor abstract class that provides extensibility for future tool types (MCP, API, etc.) while maintaining consistency with existing workflow patterns.
Changes:
- Added
InvokeFunctionToolaction executor with support for sync/async functions, expression-based arguments, optional approval flow, and structured output formatting - Added
WorkflowFactory.register_tool()fluent API for registering Python functions by name - Introduced
BaseToolExecutorabstract base class that encapsulates common tool invocation patterns (registry lookup, approval flow, output formatting, error handling) - Added comprehensive test coverage (88% for declarative package) including tests for function invocation, error handling, approval flow, and factory registration
- Added two sample workflows demonstrating basic function invocation and agent-to-function chaining patterns
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
_executors_tools.py |
New module with BaseToolExecutor and InvokeFunctionToolExecutor implementations |
_factory.py |
Added register_tool() method and _tools registry to WorkflowFactory |
_declarative_builder.py |
Integrated InvokeFunctionToolExecutor into builder with tool registry support |
__init__.py |
Exported new tool-related classes and constants |
test_function_tool_executor.py |
Comprehensive test suite for function tool executor (716 lines) |
test_workflow_factory.py |
Added tests for tool registration and fluent API |
test_workflow_handlers.py |
Extended tests for various action handlers (695 new lines) |
test_workflow_state.py |
Added 338 lines of state evaluation tests |
test_powerfx_functions.py |
Added 443 lines of PowerFx function tests |
test_declarative_loader.py |
Added 423 lines of loader and factory tests |
test_actions_agents.py |
New test file (885 lines) for agent action handlers |
invoke_function_tool/ |
Sample workflow demonstrating basic function tool invocation |
agent_to_function_tool/ |
Sample workflow demonstrating agent-to-function tool chaining |
README.md |
Updated documentation with InvokeFunctionTool action description |
python/packages/declarative/agent_framework_declarative/_workflows/_factory.py
Show resolved
Hide resolved
python/packages/declarative/agent_framework_declarative/_workflows/_factory.py
Show resolved
Hide resolved
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
InvokeFunctionToolaction kind that invokes registered Python functions from declarative YAML workflowsWorkflowFactory.register_tool()API for registering sync/async functions by namerequireApproval), and structured output (result + ChatMessage history)BaseToolExecutorabstract class for future tool types (MCP, API, etc.)invoke_function_toolandagent_to_function_toolDescription
Contribution Checklist