Skip to content

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

Merged
Quim Muntal (qmuntal) merged 4 commits into
mainfrom
dotnet-port-api-agentmode-session-helpers-20260720-9d856a177c90b0db
Sep 9, 2026
Merged

[dotnet-port-api] Align agentmode session helpers#1004
Quim Muntal (qmuntal) merged 4 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

This comment has been minimized.

@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

Comment thread agent/harness/agentmode/agentmode.go Outdated
@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.

Comment thread agent/harness/agentmode/agentmode.go Outdated
// 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
Member

Choose a reason for hiding this comment

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

Don't use the Get prefix.

Comment thread agent/harness/agentmode/agentmode.go Outdated
func (p *Provider) SetMode(mode string, opts ...agent.Option) error {
// GetMode returns the current operating mode from the session option.
// If no state has been persisted yet, it returns the configured default mode.
func (p *Provider) GetMode(opts ...agent.Option) string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove this function.

Comment thread agent/harness/agentmode/agentmode.go Outdated
// SetMode sets the operating mode in the session option, validating it against
// the provider's configured modes. Returns an error if the mode is invalid or
// no session is available.
func (p *Provider) SetMode(mode string, opts ...agent.Option) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove this function.

Signed-off-by: michelle-clayton-work <mclayton+github@microsoft.com>
@github-actions github-actions Bot added the pending-auto-risk Automatic risk classification is in progress label Sep 9, 2026
@github-actions github-actions Bot added risk:high Large blast radius, difficult rollback, or sensitive behavior and removed risk:medium Contained production impact requiring normal review depth pending-auto-risk Automatic risk classification is in progress labels Sep 9, 2026
@github-actions

This comment has been minimized.

@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 · 128.6 AIC · ⌖ 6.38 AIC · ⊞ 9.6K

Comment thread agent/harness/agentmode/agentmode.go
Comment thread agent/harness/agentmode/agentmode.go
@qmuntal
Quim Muntal (qmuntal) added this pull request to the merge queue Sep 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Sep 9, 2026
@qmuntal

Copy link
Copy Markdown
Member

Copilot resolve the merge conflicts in this pull request

…mode-session-helpers-20260720-9d856a177c90b0db

# Conflicts:
#	docs/dotnet-go-sdk-feature-comparison.md

Co-authored-by: qmuntal <3747816+qmuntal@users.noreply.github.com>

Copilot AI commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Copilot resolve the merge conflicts in this pull request

Resolved the merge conflict and merged the current main into this branch in aacfb3e.

@github-actions github-actions Bot added pending-auto-risk Automatic risk classification is in progress and removed risk:high Large blast radius, difficult rollback, or sensitive behavior labels Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Go API Consistency Review

  • Scope: public API, user-visible behavior
  • Changed Go contract: agent/harness/agentmodeProvider.GetMode(opts ...agent.Option) string and Provider.SetMode(mode string, opts ...agent.Option) error are removed and replaced by new session-first methods Provider.ModeForSession(session *agent.Session) string and Provider.SetModeForSession(session *agent.Session, mode string) error. Internal helpers getSessionLock/loadState/saveState were refactored to delegate to new session-typed variants (getSessionLockForSession, loadStateForSession, saveStateForSession); this refactor itself is fine.
  • Upstream evidence reviewed:
    • microsoft/agent-framework#7052 — "[BREAKING] Graduate todo and agent mode providers out of experimental" (PR)
    • dotnet/src/Microsoft.Agents.AI/Harness/AgentMode/AgentModeProvider.cs — renames GetMode/SetMode to async GetModeAsync/SetModeAsync, adds per-session locking, and this rename is explicitly flagged as breaking (PR title [BREAKING], PR body: "Breaking (experimental surface): AgentModeProvider.GetMode/SetMode are renamed... These types were experimental, but the change is flagged as breaking so preview users are notified.")
    • Compare with the companion Go PR [dotnet-port-api] Add TodoProvider session helpers #1003 (agent/harness/todo), which ported the same upstream commit for TodoProvider and similarly renamed GetAllItems/GetRemainingItemsAllTodos/RemainingTodos without keeping compatibility wrappers, but that PR's description accurately said this was additive/non-breaking only because upstream's TodoProvider helpers were being added fresh in Go (no prior Go equivalent existed at that name).
  • Result: findings reported.

Summary

The PR body states "Breaking Changes: No" and explicitly claims "The existing option-based GetMode and SetMode APIs remain available and now delegate to the new session-first helpers." However, the diff for agent/harness/agentmode/agentmode.go shows GetMode and SetMode are deleted outright — I could not find any remaining method named GetMode or SetMode on *Provider, nor a wrapper that delegates to ModeForSession/SetModeForSession. This is a real, unflagged breaking change to previously-stable Go public API (the Go agentmode package carries no experimental marker), left inline on the removed methods with a suggested fix (keep thin compatibility wrappers, or correct the PR description and explicitly document the break).

Aside from this compatibility gap, the session-first API shape (ModeForSession(session), SetModeForSession(session, mode)) is a reasonable and idiomatic Go parallel to upstream's GetModeAsync(session, ct)/SetModeAsync(session, mode, ct), and the per-session locking behavior already existed in Go via getSessionLock prior to this PR, so no divergence there. The docs/dotnet-go-sdk-feature-comparison.md update accurately reflects the new session helpers.

Generated by Go API Consistency Review Agent for #1004 · copilot · auto · 107.8 AIC · ⌖ 5.89 AIC · ⊞ 9.6K ·

@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 · 107.8 AIC · ⌖ 5.89 AIC · ⊞ 9.6K

Comment thread agent/harness/agentmode/agentmode.go
@github-actions github-actions Bot added risk:high Large blast radius, difficult rollback, or sensitive behavior and removed pending-auto-risk Automatic risk classification is in progress labels Sep 9, 2026
@qmuntal
Quim Muntal (qmuntal) added this pull request to the merge queue Sep 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 9, 2026
@qmuntal
Quim Muntal (qmuntal) added this pull request to the merge queue Sep 9, 2026
Merged via the queue into main with commit 9d651fe Sep 9, 2026
37 checks passed
@qmuntal
Quim Muntal (qmuntal) deleted the dotnet-port-api-agentmode-session-helpers-20260720-9d856a177c90b0db branch September 9, 2026 19:10
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:high Large blast radius, difficult rollback, or sensitive behavior 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

4 participants