-
Notifications
You must be signed in to change notification settings - Fork 552
.NET: Duplicate System Instruction when creating a ChatClientAgentOptions instance with the constructor #1382
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
.NET: Duplicate System Instruction when creating a ChatClientAgentOptions instance with the constructor #1382
Conversation
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
Fixes a bug where system instructions were duplicated when creating a ChatClientAgentOptions
instance using the constructor that accepts only the instruction
parameter. The issue occurred because instructions were being set both in the constructor and again during chat options merging.
- Removed redundant instruction assignment in
ChatClientAgentOptions
constructor - Added test case to verify single instruction assignment behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentOptions.cs | Removes duplicate instruction assignment logic from constructor |
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs | Adds test case to verify instructions are not duplicated when using constructor |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
I noticed that six tests are currently failing because they depend on the code in constructor I just removed. |
@htilssu, thanks for the contribution! |
@westey-m Thanks for the feedback! I've updated the unit tests accordingly to align with the new implementation. |
@TaoChenOSU Could you please review the changes in this PR when you have a moment? |
Motivation and Context
1. Why is this change required?
Creating a
ChatClientAgentOptions
instance with the constructor that accepts only theinstruction
argument caused the instruction text to be duplicated internally when the agent options were later merged into chat options.2. What problem does it solve?
This change removes redundant instruction concatenation logic to ensure that
Instructions
are applied only once.It prevents recursive or repeated values being passed into
ChatOptions
during agent initialization.3. What scenario does it contribute to?
Improves consistency and correctness when initializing
ChatClientAgent
instances with predefined instructions, especially in scenarios where low-level options are already configured throughCreateConfiguredChatOptions()
.Description
Motivation and Context
When
ChatClientAgent.RunAsync()
is called withrequestOptions == null
,the logic at
agent-framework/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs
Lines 609 to 613 in 7e1fd67
manually concatenates
this.Instructions
withchatOptions.Instructions
.However,
this.Instructions
is just a proxy for_agentOptions.Instructions
agent-framework/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs
Lines 143 to 145 in 7e1fd67
and during
ChatClientAgentOptions
construction, the same instruction value is alreadypropagated into its
ChatOptions
field:agent-framework/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentOptions.cs
Lines 48 to 51 in 7e1fd67
Contribution Checklist