-
Notifications
You must be signed in to change notification settings - Fork 1k
.NET Workflows - Support agent level function invocation for declarative workflow #1442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
crickman
merged 26 commits into
main
from
crickman/workflows-declarative-agent-toolcall
Oct 14, 2025
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
fc75fdf
Checkpoint
crickman 5934523
Merge branch 'main' into crickman/workflows-declarative-agent-toolcall
crickman 1d21b47
Resolve merge from main
crickman 6491ab7
Checkpoint
crickman ca2207e
Checkpoint
crickman c5e8c5c
Good
crickman 557a52a
Merge branch 'main' into crickman/workflows-declarative-agent-toolcall
crickman bcc13da
Namespace
crickman 45e9f52
Namespace
crickman 407ecbf
Dun
crickman e2ed2f0
Async Test
crickman 7bddf1f
AgentId
crickman 97246ab
Portable pattern
crickman 7b45604
Portable2
crickman 3fa3a54
Portable3
crickman f0a28a7
Respond to comments
crickman 960580e
Namespace
crickman c853906
Function call selection
crickman 8dc95d5
ToHashSet
crickman 920198f
ToHashSet
crickman fa9303d
Updated
crickman aba5fef
Parameter name
crickman 8911eea
Merge branch 'main' into crickman/workflows-declarative-agent-toolcall
crickman f3aa3f7
Final
crickman 7c8b950
Tests
crickman 8a0f1cc
Merge branch 'main' into crickman/workflows-declarative-agent-toolcall
crickman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
30 changes: 30 additions & 0 deletions
30
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Events/AgentToolRequest.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.Extensions.AI; | ||
|
|
||
| namespace Microsoft.Agents.AI.Workflows.Declarative.Events; | ||
|
|
||
| /// <summary> | ||
| /// Represents a request for user input. | ||
| /// </summary> | ||
| public sealed class AgentToolRequest | ||
crickman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| /// <summary> | ||
| /// The name of the agent associated with the tool request. | ||
| /// </summary> | ||
| public string AgentName { get; } | ||
|
|
||
| /// <summary> | ||
| /// A list of tool requests. | ||
| /// </summary> | ||
| public IList<FunctionCallContent> FunctionCalls { get; } | ||
|
|
||
| [JsonConstructor] | ||
| internal AgentToolRequest(string agentName, IList<FunctionCallContent>? functionCalls = null) | ||
| { | ||
| this.AgentName = agentName; | ||
| this.FunctionCalls = functionCalls ?? []; | ||
| } | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Events/AgentToolResponse.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.Extensions.AI; | ||
|
|
||
| namespace Microsoft.Agents.AI.Workflows.Declarative.Events; | ||
|
|
||
| /// <summary> | ||
| /// Represents a user input response. | ||
| /// </summary> | ||
| public sealed class AgentToolResponse | ||
| { | ||
| /// <summary> | ||
| /// The name of the agent associated with the tool response. | ||
| /// </summary> | ||
| public string AgentName { get; } | ||
|
|
||
| /// <summary> | ||
| /// A list of tool responses. | ||
| /// </summary> | ||
| public IList<FunctionResultContent> FunctionResults { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="InputResponse"/> class. | ||
crickman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// </summary> | ||
| [JsonConstructor] | ||
| internal AgentToolResponse(string agentName, IList<FunctionResultContent> functionResults) | ||
| { | ||
| this.AgentName = agentName; | ||
| this.FunctionResults = functionResults; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Factory method to create an <see cref="AgentToolResponse"/> from an <see cref="AgentToolRequest"/> | ||
| /// Ensures that all function calls in the request have a corresponding result. | ||
| /// </summary> | ||
| /// <param name="toolRequest">The tool request.</param> | ||
| /// <param name="functionResults">On or more function results</param> | ||
| /// <returns>An <see cref="AgentToolResponse"/> that can be provided to the workflow.</returns> | ||
| /// <exception cref="DeclarativeActionException">Not all <see cref="AgentToolRequest.FunctionCalls"/> have a corresponding <see cref="FunctionResultContent"/>.</exception> | ||
| public static AgentToolResponse Create(AgentToolRequest toolRequest, params IEnumerable<FunctionResultContent> functionResults) | ||
| { | ||
| HashSet<string> callIds = [.. toolRequest.FunctionCalls.Select(call => call.CallId)]; | ||
| HashSet<string> resultIds = [.. functionResults.Select(call => call.CallId)]; | ||
| if (!callIds.SetEquals(resultIds)) | ||
| { | ||
| throw new DeclarativeActionException($"Missing results for: {string.Join(",", callIds.Except(resultIds))}"); | ||
| } | ||
crickman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return new AgentToolResponse(toolRequest.AgentName, [.. functionResults]); | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.