.NET: Support InvokeFunctionTool for declarative workflows#4014
.NET: Support InvokeFunctionTool for declarative workflows#4014
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements support for the InvokeFunctionTool action in declarative workflows, enabling workflows to call functions directly without going through an AI agent first. This is a new capability that allows pre-fetching data or executing operations before AI involvement.
Changes:
- Adds
InvokeFunctionToolExecutorto execute function tool invocations in workflows - Implements workflow visitor pattern to integrate InvokeFunctionTool into the workflow execution model
- Includes comprehensive unit and integration tests
- Provides sample implementation demonstrating function tool invocation with and without approval requirements
- Updates package dependencies (Microsoft.Agents.ObjectModel from 2026.2.2.1 to 2026.2.3.1, PowerFx from 1.5.0 to 1.8.1)
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/InvokeFunctionToolExecutor.cs | Core executor implementation handling function tool invocation, approval requests, result capture, and conversation integration |
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowActionVisitor.cs | Visitor pattern integration to wire up InvokeFunctionTool in workflow execution graph |
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowTemplateVisitor.cs | Marks InvokeFunctionTool as not supported in template workflows |
| dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/InvokeFunctionToolExecutorTest.cs | Unit tests covering executor functionality including approval, arguments, conversation ID handling |
| dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/InvokeFunctionToolWorkflowTest.cs | Integration tests validating end-to-end workflow execution with function tools |
| dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Workflows/InvokeFunctionTool.yaml | Test workflow demonstrating function tool invocation |
| dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Workflows/InvokeFunctionToolWithApproval.yaml | Test workflow demonstrating function tool invocation with approval requirement |
| dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Framework/WorkflowHarness.cs | Fixes checkpoint tracking and request counting for workflow resume operations |
| dotnet/samples/GettingStarted/Workflows/Declarative/InvokeFunctionTool/Program.cs | Sample program demonstrating InvokeFunctionTool usage |
| dotnet/samples/GettingStarted/Workflows/Declarative/InvokeFunctionTool/MenuPlugin.cs | Sample plugin with menu functions for demonstration |
| dotnet/samples/GettingStarted/Workflows/Declarative/InvokeFunctionTool/InvokeFunctionTool.yaml | Sample workflow YAML file |
| dotnet/samples/GettingStarted/Workflows/Declarative/InvokeFunctionTool/InvokeFunctionTool.csproj | Project configuration for sample |
| dotnet/agent-framework-dotnet.slnx | Adds new sample project to solution |
| dotnet/Directory.Packages.props | Updates package versions for ObjectModel and PowerFx dependencies |
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowActionVisitor.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/InvokeFunctionToolExecutor.cs
Outdated
Show resolved
Hide resolved
...soft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/InvokeFunctionToolExecutorTest.cs
Outdated
Show resolved
Hide resolved
...ests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Framework/WorkflowHarness.cs
Show resolved
Hide resolved
| ChatMessage requestMessage = new(ChatRole.Tool, [functionCall]); | ||
|
|
||
| // If approval is required, add user input request content | ||
| if (requireApproval) |
There was a problem hiding this comment.
I wonder if approval and execution need to be separate turns?
There was a problem hiding this comment.
I thought about that, but I think it makes sense for the client to handle both however they see fit. We can get this in and get feedback from the service team and other users and change if needed.
| { | ||
| try | ||
| { | ||
| JsonDocument jsonDocument = JsonDocument.Parse(jsonString); |
There was a problem hiding this comment.
Does this need to be disposed?
| JsonDocument jsonDocument = JsonDocument.Parse(jsonString); | |
| using JsonDocument jsonDocument = JsonDocument.Parse(jsonString); |
| await this.AssignAsync(this.Model.Output.Result?.Path, objectProperties.ToFormula(), context).ConfigureAwait(false); | ||
| return; | ||
| } | ||
| catch |
There was a problem hiding this comment.
Can we narrow the catch to JsonException?
| catch | |
| catch (JsonException) |
Motivation and Context
This implementation supports the
InvokeFunctionToolaction in a declarative workflow to call functions directly from the workflow without going through an AI agent first. This is different from the standardInvokeAzureAgentpattern where the AI decides which functions to call based on the conversation.This PR includes tests and samples for the new action type and sample yaml implementations.
Fixes #3377
Fixes #3414
Contribution Checklist