Skip to content

[dotnet-port-api] Align agentmode session helpers - #1004

Open
Michelle Clayton (michelle-clayton-work) wants to merge 2 commits into
mainfrom
dotnet-port-api-agentmode-session-helpers-20260720-9d856a177c90b0db
Open

[dotnet-port-api] Align agentmode session helpers#1004
Michelle Clayton (michelle-clayton-work) wants to merge 2 commits into
mainfrom
dotnet-port-api-agentmode-session-helpers-20260720-9d856a177c90b0db

Conversation

@michelle-clayton-work

Copy link
Copy Markdown
Contributor

Summary

Add explicit session-first AgentMode helper APIs by introducing (*agentmode.Provider).GetModeForSession and SetModeForSession, then keep the existing option-based GetMode and SetMode methods as compatibility wrappers.

This ports the narrow public API portion of the upstream AgentMode graduation work so Go callers can read and update mode state directly from an *agent.Session, matching the current .NET usage model without forcing a breaking rename of the existing Go helpers.

Upstream reference:

Ported .NET PRs

Breaking Changes

No.

Tests and Examples

  • go test ./agent/harness/agentmode -count=1
  • go test ./agent/... -count=1
  • Added focused coverage for GetModeForSession and SetModeForSession
  • Updated the external mode-change tests to exercise the new session-based helpers
  • Updated docs/dotnet-go-sdk-feature-comparison.md
  • No examples changed

Notes

  • The existing option-based GetMode and SetMode APIs remain available and now delegate to the new session-first helpers.
  • This PR intentionally ports only the AgentMode session-helper surface from .NET: [BREAKING] Graduate todo and agent mode providers out of experimental agent-framework#7052; broader todo-provider graduation work was left out to keep the nightly change narrowly scoped.
  • Existing workflow items already cover nearby tool-approval and workflow-behavior changes, so they were intentionally not bundled here.
  • Upstream head inspected during candidate selection was upstream-agent-framework/main at 7c6b1e975.

Generated by .NET to Go API Porting Agent · 876.6 AIC · ⌖ 39 AIC · ⊞ 21.7K ·

Closes #568

Port the AgentMode session-helper parity from microsoft/agent-framework#7052 by adding explicit session-based helper methods while preserving the existing option-based helpers as compatibility wrappers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 4, 2026 22:29
@github-actions github-actions Bot added area:agent Changes files in the agent area size:large At most 300 changed lines across at most 10 files labels Sep 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is additive with compatibility wrappers preserved, and the updated tests/docs support the intended session-first API shape.

Pull request overview

Adds explicit session-first AgentMode helper APIs so callers can read/write mode state directly from an *agent.Session, while keeping the existing option-based helpers as compatibility wrappers (aligning the Go surface with the .NET usage model without breaking changes).

Changes:

  • Introduces (*agentmode.Provider).GetModeForSession and SetModeForSession, and refactors internal state/lock helpers to accept a session directly.
  • Keeps GetMode / SetMode as wrappers delegating to the new session-first APIs.
  • Updates harness docs and adjusts/extends tests to cover the new helper methods.
File summaries
File Description
agent/harness/agentmode/agentmode.go Adds session-first mode helpers and refactors lock/state helpers; preserves existing option-based API via wrappers.
agent/harness/agentmode/agentmode_test.go Adds focused tests for GetModeForSession / SetModeForSession and updates external mode-change tests to use session-first helpers.
docs/dotnet-go-sdk-feature-comparison.md Updates feature matrix text to mention AgentMode session helper API alignment.
Review details

Suppressed comments (2)

agent/harness/agentmode/agentmode_test.go:333

  • session, _ := agent.GetOption(...) ignores the ok flag, which can mask missing-session option regressions and make the test pass/fail for the wrong reason. Add an assertion that the session option is present and non-nil.
	opts := sessionOpts()
	session, _ := agent.GetOption(opts, agent.WithSession)
	msgs := newMessages("hi")

agent/harness/agentmode/agentmode_test.go:365

  • session, _ := agent.GetOption(...) ignores the ok flag, so a missing session option could be silently treated as nil and make this test assert the wrong behavior. Assert ok and non-nil session before calling SetModeForSession.
	opts := sessionOpts()
	session, _ := agent.GetOption(opts, agent.WithSession)
	msgs := newMessages("hi")
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread agent/harness/agentmode/agentmode_test.go
@github-actions github-actions Bot added kind:code Changes production behavior or code kind:docs Changes documentation or comments kind:tests Changes tests, fixtures, or test infrastructure pending-auto-risk Automatic risk classification is in progress risk:medium Contained production impact requiring normal review depth and removed pending-auto-risk Automatic risk classification is in progress labels Sep 4, 2026
@github-actions github-actions Bot added pending-auto-risk Automatic risk classification is in progress and removed risk:medium Contained production impact requiring normal review depth labels Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Scope: public API, user-visible behavior

Changed Go contract: agent/harness/agentmode package — new exported (*agentmode.Provider).GetModeForSession(session *agent.Session) string and SetModeForSession(session *agent.Session, mode string) error; existing GetMode(opts ...agent.Option) string and SetMode(mode string, opts ...agent.Option) error retained as option-based compatibility wrappers that now delegate to the session-first helpers.

Upstream evidence reviewed:

Result: findings reported (one inline comment)

Summary: The Go PR correctly narrows the port to the session-first helper surface and keeps naming aligned (GetModeForSession/SetModeForSession vs. GetModeAsync/SetModeAsync, Async suffix omitted as an expected Go idiom since Go uses synchronous mutex-based locking here rather than SemaphoreSlim). Per-session locking parity with TodoProvider-style locking is preserved via getSessionLockForSession. However, upstream made the session parameter non-nullable for both getter and setter (Throw.IfNull(session) in both GetModeAsync and SetModeAsync), while the Go port only rejects nil sessions in SetModeForSessionGetModeForSession silently falls back to the default mode for a nil session, which is an inconsistent, divergent contract from upstream and from its own sibling setter. See inline comment for details and a suggested resolution.

No examples/ changes were included or expected for this narrowly-scoped API surface change.

Generated by Go API Consistency Review Agent for #1004 · copilot · auto · 55.5 AIC · ⌖ 7.36 AIC · ⊞ 9.5K ·

@github-actions github-actions Bot added the public-api-change Pull Request changes public APIs label Sep 5, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated by Go API Consistency Review Agent for #1004 · copilot · auto · 55.5 AIC · ⌖ 7.36 AIC · ⊞ 9.5K

// If no state has been persisted yet, it returns the configured default mode.
func (p *Provider) GetMode(opts ...agent.Option) string {
mu := p.getSessionLock(opts)
func (p *Provider) GetModeForSession(session *agent.Session) string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parity finding: Upstream AgentModeProvider.GetModeAsync(AgentSession session, ...) (dotnet/src/Microsoft.Agents.AI/Harness/AgentMode/AgentModeProvider.cs, lines ~180-194) calls Throw.IfNull(session) and throws ArgumentNullException when the session is null — the upstream port explicitly made the session parameter non-nullable/required for both GetModeAsync and SetModeAsync as part of graduating this API (microsoft/agent-framework#7052).

Go's new GetModeForSession(session *agent.Session) silently accepts a nil session and falls back to the configured default mode (via getSessionLockForSession/loadStateForSession returning the null-session lock and default state) instead of returning an error. This is inconsistent with the sibling SetModeForSession, which does return fmt.Errorf("agentmode: no session available") for a nil session, and it diverges from the upstream contract that requires a non-null session for both getters and setters.

Suggested resolution: either (a) have GetModeForSession return an error (or panic, consistent with Go idioms for programmer errors) when session == nil, mirroring SetModeForSession and the upstream non-nullable contract, or (b) if the permissive nil-session default-mode fallback is an intentional Go-specific ergonomic choice, document that divergence explicitly in the doc comment so it is not mistaken for an oversight.

@github-actions github-actions Bot added risk:medium Contained production impact requiring normal review depth and removed pending-auto-risk Automatic risk classification is in progress labels Sep 5, 2026
@michelle-clayton-work

Copy link
Copy Markdown
Contributor Author

Copilot address PR feedback

Copilot AI commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Copilot address PR feedback

The session-option assertions are present in all three cited tests in a2b04a2; go test ./agent/harness/agentmode -count=1 passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Changes files in the agent area kind:code Changes production behavior or code kind:docs Changes documentation or comments kind:tests Changes tests, fixtures, or test infrastructure public-api-change Pull Request changes public APIs risk:medium Contained production impact requiring normal review depth size:large At most 300 changed lines across at most 10 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[dotnet-port-api] Align agentmode session helpers

3 participants