Skip to content

.NET: AgentModeProvider keeps a restored mode that is no longer configured #9829

Closed

Description

Description

AgentModeProvider validates the default mode and every SetModeAsync / mode_set call against the configured modes.
A mode restored from a persisted session is not validated.
If an app removes or renames a mode, sessions saved before that change keep the old mode.

Observed on main (2684614) after changing the modes from draft/review to draft/publish:

  • GetModeAsync returns "review".
  • The instructions tell the model "You are currently operating in the review mode.", but the mode list has no review section, so the model gets no rules for its current mode.
  • SetModeAsync(session, "review") throws ArgumentException, so the provider reports a mode it would itself reject.

ProviderSessionState.GetOrInitializeState returns the StateBag value without calling the initializer, so the configured-mode check only applies to new sessions.

Repro (unit test)

var v1 = new AgentModeProvider(new() { Modes = [new("draft", "..."), new("review", "...")], DefaultMode = "draft" });
var session = new ChatClientAgentSession();
await v1.SetModeAsync(session, "review");
JsonElement persisted = session.StateBag.Serialize();

var v2 = new AgentModeProvider(new() { Modes = [new("draft", "..."), new("publish", "...")], DefaultMode = "draft" });
var restored = new ChatClientAgentSession(stateBag: AgentSessionStateBag.Deserialize(persisted));
string mode = await v2.GetModeAsync(restored); // "review"

Expected

Match Python: get_agent_mode in python/packages/core/agent_framework/_harness/_mode.py falls back to the default mode when the stored mode is no longer configured.

Related: #9493, which has the same restored-state gap in Mem0Provider.

Activity

  1. added
    .NETUsage: [Issues, PRs], Target: .Net
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 29, 2026
  2. changed the title [-].NET: AgentModeProvider keeps a restored mode that is no longer configured[/-] [+]Python: .NET: AgentModeProvider keeps a restored mode that is no longer configured[/+] on Oct 29, 2026
  3. changed the title [-]Python: .NET: AgentModeProvider keeps a restored mode that is no longer configured[/-] [+].NET: AgentModeProvider keeps a restored mode that is no longer configured[/+] on Oct 29, 2026
  4. added a commit that references this issue on Nov 2, 2026
    60eae45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETUsage: [Issues, PRs], Target: .NetpythonUsage: [Issues, PRs], Target: PythontriageUsage: [Issues], Target: All issues that still need to be triaged

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions