[dotnet-port-api] Align agentmode session helpers - #1004
[dotnet-port-api] Align agentmode session helpers#1004Michelle Clayton (michelle-clayton-work) wants to merge 2 commits into
Conversation
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>
There was a problem hiding this comment.
🟢 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).GetModeForSessionandSetModeForSession, and refactors internal state/lock helpers to accept a session directly. - Keeps
GetMode/SetModeas 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 theokflag, 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 theokflag, so a missing session option could be silently treated as nil and make this test assert the wrong behavior. Assertokand non-nil session before callingSetModeForSession.
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.
|
Scope: public API, user-visible behavior Changed Go contract: 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 ( No
|
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
|
Copilot address PR feedback |
Summary
Add explicit session-first AgentMode helper APIs by introducing
(*agentmode.Provider).GetModeForSessionandSetModeForSession, then keep the existing option-basedGetModeandSetModemethods 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:
microsoft/agent-framework@e57f046
Ported .NET PRs
Breaking Changes
No.
Tests and Examples
go test ./agent/harness/agentmode -count=1go test ./agent/... -count=1GetModeForSessionandSetModeForSessiondocs/dotnet-go-sdk-feature-comparison.mdNotes
GetModeandSetModeAPIs remain available and now delegate to the new session-first helpers.upstream-agent-framework/mainat7c6b1e975.Closes #568