-
Notifications
You must be signed in to change notification settings - Fork 1k
.NET: Pass AdditionalProperties from parent to child when exposing an agent as a FunctionTool #3219
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
base: main
Are you sure you want to change the base?
.NET: Pass AdditionalProperties from parent to child when exposing an agent as a FunctionTool #3219
Conversation
… as a FunctionTool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables the propagation of AdditionalProperties from a parent agent to a child agent when the child is exposed as a FunctionTool. This allows custom properties set on the parent agent's run context to flow through to nested agent invocations.
Changes:
- Modified
AgentExtensions.AsAIFunctionto extract AdditionalProperties from the parent agent's FunctionInvokingChatClient context and pass them to the child agent via AgentRunOptions - Added a comprehensive unit test to verify that AdditionalProperties are correctly passed from parent to child agent
- Added a helper method in the test class to use reflection for setting the FunctionInvokingChatClient's CurrentContext for testing purposes
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/AgentExtensions.cs | Modified InvokeAgentAsync to propagate AdditionalProperties from FunctionInvokingChatClient.CurrentContext to child agent options |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs | Added test for AdditionalProperties propagation and helper method for setting CurrentContext via reflection; enhanced TestAgent to track received AgentRunOptions |
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentExtensionsTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| // Propagate any additional properties from the parent agent's run to the child agent if the parent is using a FunctionInvokingChatClient. | ||
| AgentRunOptions? agentRunOptions = FunctionInvokingChatClient.CurrentContext?.Options?.AdditionalProperties is AdditionalPropertiesDictionary dict | ||
| ? new AgentRunOptions { AdditionalProperties = dict } | ||
| : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might be missing the ChatOptions here.
I would addtionally check if the agent is a ChatClientAgent and provide the FunctionInvokingChatClient.CurrentContext?.Options as new ChatClientAgentRunOptions { ChatOptions = options } and if not use the current proposed code approach.
Suggest adding an additional test UT to covering ChatClientAgent (and non-chatclientagents, which seems a bit odd as I think this is exclusive to ChatClientAgents and FICC scenarios..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that we can pick the entire ChatOptions and pass it down.
E.g. we shouldn't be passing tools, conversation id, instructions, AllowBackgroundResponses, ContinuationToken or ResponseFormat, since all of these would be based on the behavior and underlying service of the parent agent, and may cause the child agent to behave incorrectly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that we can pick the entire ChatOptions and pass it down.
E.g. we shouldn't be passing tools, conversation id, instructions, AllowBackgroundResponses, ContinuationToken or ResponseFormat, since all of these would be based on the behavior and underlying service of the parent agent, and may cause the child agent to behave incorrectly.
I'm trying to understand why AdditionalProperties have a different criteria compared to other Properties, sound a bit inconsistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main difference is that they are not used by the AF/MEAI stack, but customers may need them to pass their data down the stack.
Motivation and Context
#3127
Description
Contribution Checklist