Skip to content

Conversation

@PederHP
Copy link

@PederHP PederHP commented Oct 26, 2025

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 ChatOptions is 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.

ChatClientAgentRunOptions could 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 ChatClientAgentOptions are 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

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI and others added 2 commits October 26, 2025 11:52
* 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.
Copilot AI review requested due to automatic review settings October 26, 2025 11:00
Copy link
Contributor

Copilot AI left a 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 _agentOptions field from nullable to non-nullable by initializing with empty instance when null
  • Made Instructions and ChatOptions properties 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

@github-actions github-actions bot changed the title Make ChatOptions and Instructions mutable in ChatClientAgent .NET: Make ChatOptions and Instructions mutable in ChatClientAgent Oct 26, 2025
Change var to explicit types
@PederHP
Copy link
Author

PederHP commented Oct 26, 2025

@microsoft-github-policy-service agree

PederHP and others added 3 commits October 26, 2025 12:11
* 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>
@PederHP PederHP changed the title .NET: Make ChatOptions and Instructions mutable in ChatClientAgent .NET: Introduce MutableChatClientAgent Oct 26, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants