Skip to content

[dotnet-port-api] Expose session state count - #1283

Merged
Quim Muntal (qmuntal) merged 2 commits into
mainfrom
dotnet-port-session-state-count-20261014-4b84f64bb6181c8c
Oct 14, 2026
Merged

Quim Muntal (qmuntal) merged 2 commits into
mainfrom
dotnet-port-session-state-count-20261014-4b84f64bb6181c8c

Conversation

@microsoft-agent-framework-for-go

Copy link
Copy Markdown
Contributor

Summary

Port the assessed Microsoft.Agents.AI.AgentSessionStateBag.Count capability as agent.Session.StateCount(). The method reports the number of stored session-state keys under the session's existing read lock and returns zero for an uninitialized or nil session.

Ported .NET PRs

None. The contract was verified directly at pinned .NET revision 0c9944cc9f577d51277ac7c55dbc388b60a577af in dotnet/src/Microsoft.Agents.AI.Abstractions/AgentSessionStateBag.cs. The inventoried .NET assemblies are catalog-pinned at version 1.22.0.0.

Breaking Changes

None intended. This is an additive public API; existing session state behavior is unchanged.

Tests and Examples

  • Added TestSessionState_StateCount_TracksValues, covering empty, insertion, replacement, and deletion behavior.
  • go test ./agent
  • gofmt -w agent/session.go agent/session_test.go
  • git diff --check

Notes

  • Exact catalog leaf: Microsoft.Agents.AI.AgentSessionStateBag.Count (unmapped). Expected catalog maintenance after merge: reassess it as covered, retaining the existing declaring-type mapping to agent.Session.
  • Pinned source contract: Count returns the concurrent state dictionary's key/value count. Go maps the session-owned state bag to Session.StateCount() while preserving lock-safe access and nil/zero-value behavior.
  • The pinned declaration is not marked experimental.
  • Duplicate checks used the fixed issue query repo:microsoft/agent-framework-go AgentSessionStateBag Count session state count and PR query with the same syntax, both at perPage: 10 and fields number,title,state,html_url; the final issue query returned no hits, and the only PR hit was broad merged PR Port Abstractions behaviors and structured output #1273, whose direct diff/catalog assessment did not add a count API. Earlier screened groups were excluded because workflow edge metadata is already claimed by closed PR [dotnet-port-api] Expose workflow edge kind metadata #1265, while skills caching options are already present in the current Go implementation.
  • No catalog or mapping-guide files were changed.

Warning

Firewall blocked 3 domains

The following domains were blocked by the firewall during workflow execution:

  • proxy.golang.org
  • storage.googleapis.com
  • sum.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"
    - "storage.googleapis.com"
    - "sum.golang.org"

See Network Configuration for more information.

Generated by .NET to Go API Porting Agent · copilot · gpt56 · 6.86 AIC · ⌖ 0.686 AIC · ⊞ 24.8K · ◷

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added area:agent Changes files in the agent area size:medium At most 100 changed lines across at most 5 files labels Oct 14, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added parity-approved Go API consistency review found no parity issues public-api-change Pull Request changes public APIs kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure labels Oct 14, 2026
Comment thread agent/session.go Outdated
}

// StateCount returns the number of values stored in the session state.
func (s *Session) StateCount() int {

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.

Rename to Count.

@qmuntal

Copy link
Copy Markdown
Member

Copilot fix review comments.

@qmuntal
Quim Muntal (qmuntal) marked this pull request as ready for review October 14, 2026 07:28
@qmuntal
Quim Muntal (qmuntal) requested a review from a team as a code owner October 14, 2026 07:28
Copilot AI balanced review requested due to automatic review settings October 14, 2026 07:28
Co-authored-by: qmuntal <3747816+qmuntal@users.noreply.github.com>

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 additive API correctly preserves session locking and zero-value semantics with adequate behavioral coverage.

0 open findings

What changed in this PR

Adds a lock-safe Session.StateCount() API matching the upstream session-state count capability.

Changes:

  • Returns stored key count, including zero for nil/uninitialized sessions.
  • Tests insertion, replacement, and deletion behavior.
File Description
agent/​session.go Adds the synchronized state-count accessor.
agent/​session_test.go Verifies count behavior across state mutations.

🧠 Review effort: Balanced


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

Copilot AI commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Copilot fix review comments.

Renamed the accessor to Count() and updated the regression test in commit 170a198.

@github-actions

Copy link
Copy Markdown
Contributor

API consistency review

Result Scope
aligned public API

Changed Go contract

Adds (*Session).Count() int to agent/session.go, returning the number of key-value pairs currently stored in the session's state map. Zero-value/nil-state sessions return 0. No other exported APIs changed.

Upstream evidence reviewed

Implementation Source Contract checked
.NET AgentSessionStateBag.cs public int Count => this._state.Count; — exposes the number of entries in the session-scoped, thread-safe key/value state bag.
Python _sessions.py — AgentSession.state state: dict[str, Any] is a plain dict; callers use len(session.state) for the same semantic (count of stored session-state entries), since Python exposes the state as a native mapping rather than a dedicated type.

Assessment

The Go Session.Count() method is a direct, non-divergent match for .NET's AgentSessionStateBag.Count property (same semantics: number of entries in the session-local state store), and is semantically equivalent to len(session.state) in Python, where the state is a plain dict rather than a wrapped type. Naming (Count() vs Count) and shape (method vs property) differ only due to Go not having properties, which is an idiomatic, non-substantive difference. Behavior for nil/zero-value sessions (returning 0) is consistent with the existing nil-safety pattern already used by Get, Set, and Delete on the same type. No parity issues found.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • github.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent for #1283 · copilot · auto · 142.3 AIC · ⌖ 6.18 AIC · ⊞ 13.9K · ◷

Merged via the queue into main with commit 00dd60a Oct 14, 2026
28 checks passed
@qmuntal
Quim Muntal (qmuntal) deleted the dotnet-port-session-state-count-20261014-4b84f64bb6181c8c branch October 14, 2026 08:21
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:tests Changes tests, fixtures, or test infrastructure parity-approved Go API consistency review found no parity issues public-api-change Pull Request changes public APIs size:medium At most 100 changed lines across at most 5 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants