-
Couldn't load subscription status.
- Fork 612
.NET: Introduce MutableChatClientAgent #1711
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?
Conversation
* Initial plan * Make ChatOptions and Instructions public and mutable in ChatClientAgent Co-authored-by: PederHP <127606677+PederHP@users.noreply.github.com> * Add null assertions before using null-forgiving operator in tests Co-authored-by: PederHP <127606677+PederHP@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PederHP <127606677+PederHP@users.noreply.github.com>
Updated documentation to reflect changes in chat options.
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 makes the Instructions and ChatOptions properties of ChatClientAgent mutable, enabling dynamic modification during agent execution. This supports common patterns like updating instructions for caching/trust levels, adjusting reasoning modes, and modifying tool sets at runtime.
Key Changes:
- Changed
_agentOptionsfield from nullable to non-nullable by initializing with empty instance when null - Made
InstructionsandChatOptionsproperties public with setters - Added comprehensive unit tests covering mutation scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
ChatClientAgent.cs |
Changed _agentOptions to non-nullable, made Instructions and ChatOptions properties public with setters, updated XML documentation, removed null-conditional operators |
ChatClientAgentTests.cs |
Added 7 new test methods covering mutation scenarios for Instructions and ChatOptions properties |
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
Change var to explicit types
|
@microsoft-github-policy-service agree |
* Initial plan * Move mutability to MutableChatClientAgent class Co-authored-by: PederHP <127606677+PederHP@users.noreply.github.com> * Address code review comments Co-authored-by: PederHP <127606677+PederHP@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PederHP <127606677+PederHP@users.noreply.github.com>
* Initial plan * Replace var with explicit types in MutableChatClientAgentTests.cs Co-authored-by: PederHP <127606677+PederHP@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PederHP <127606677+PederHP@users.noreply.github.com>
Motivation and Context
Solves #1710
It is a common pattern to have data in the
Instructions(for caching and to achieve highest model trust level). System notifications and reminders are another example of dynamic instruction/system level data.Mutable
ChatOptionsis needed to have agents with dynamic Tool sets and dynamic reasoning/thinking, which is also a common pattern. Another example is Claude skills and container ids.ChatClientAgentRunOptionscould be used as an alternative to this, but it is awkward, and for Tools it only allows adding Tools not changing the available Tools or removing some of them.I believe it is needed to support both per-request overrides and mutable agent properties. The alternative is to create a new agent whenever mutation is needed and migrate state to it.
Description
If no
ChatClientAgentOptionsare provided in the constructor a default is instantiated. This is functionally equivalent to the current behavior and allows making the properties mentioned above public and mutable.Contribution Checklist