Skip to content

Port Abstractions behaviors and structured output - #1273

Open
Quim Muntal (qmuntal) wants to merge 2 commits into
mainfrom
feat/abstractions-behavioral-parity
Open

Quim Muntal (qmuntal) wants to merge 2 commits into
mainfrom
feat/abstractions-behavioral-parity

Conversation

@qmuntal

@qmuntal Quim Muntal (qmuntal) commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Port meaningful stable .NET Abstractions behaviors and tests for agents, context and history providers, sessions, responses, messages, and compaction. Expose in-memory history helpers and support concurrent session operations after initialization using a per-session lock.
  • Support typed non-object structured output with a shared JSON-format wrapper and decoder across OpenAI Chat and Responses (including Foundry), Anthropic, and Gemini, in streaming and non-streaming runs. Keep ForType and explicit response-format semantics unchanged.
  • Reconcile API assessments and one-to-one .NET test pairings in the symbol catalog.
  • Address review feedback: preserve JSON marshaling of Session values, reject blank compaction state keys at construction, and avoid the AG-UI initialization lock on the existing-ID path.

Validation

  • go test -shuffle=on -count=1 ./... (Go 1.26.1, Windows ARM64)
  • go vet ./...
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0 run --new-from-rev=origin/main (0 issues)
  • go -C _catalog run ./cmd/symbolmap reconcile -summary -check
  • go -C _catalog run ./cmd/symbolmap tests -summary -check

Align session state concurrency, history, and compaction behavior with Abstractions; add behavioral tests for agents, sessions, context providers, responses, and messages.

Support non-object typed JSON output across providers and reconcile .NET API and test mappings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@qmuntal
Quim Muntal (qmuntal) requested a review from a team as a code owner October 9, 2026 11:00
Copilot AI balanced review requested due to automatic review settings October 9, 2026 11:00
@github-actions github-actions Bot added area:agent Changes files in the agent area area:examples Changes files in the examples area area:message Changes files in the message area area:provider Changes files in the provider area area:provider/agui Changes files in the provider / agui area area:provider/anthropic Changes files in the provider / anthropic area area:provider/gemini Changes files in the provider / gemini area area:provider/openai Changes files in the provider / openai area size:xlarge More than 300 changed lines or 10 files labels Oct 9, 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.

🟡 Changes recommended

Session serialization compatibility, delayed state-key panics, and global AG-UI lock contention remain unresolved.

3 open findings
What changed in this PR

Ports stable abstractions behavior, adds concurrency-safe session state, and supports typed non-object structured output across providers.

Changes:

  • Adds synchronized session/history and compaction behavior.
  • Wraps and decodes non-object structured output consistently.
  • Expands behavioral tests and .NET symbol mappings.
File Description
provider/​openaiprovider/​strict_schema_test.go Tests explicit schema rejection.
provider/​openaiprovider/​responses.go Adds wrapped structured output.
provider/​openaiprovider/​chat.go Adds wrapped structured output.
provider/​openaiprovider/​chat_test.go Tests structured output end-to-end.
provider/​geminiprovider/​agent.go Adds wrapped structured output.
provider/​geminiprovider/​agent_test.go Tests non-object output.
provider/​anthropicprovider/​agent.go Adds wrapped structured output.
provider/​anthropicprovider/​agent_test.go Tests non-object output.
provider/​aguiprovider/​agui.go Synchronizes thread-ID initialization.
provider/​aguiprovider/​agui_test.go Tests concurrent thread IDs.
message/​message_test.go Expands source-cloning tests.
examples/​02-agents/​agents/​step18_compaction_pipeline/​main.go Displays history size.
agent/​value.go Synchronizes lazy state values.
agent/​structuredoutput_test.go Tests custom provider formats.
agent/​session.go Makes session state concurrent.
agent/​session_test.go Expands state and concurrency tests.
agent/​response_test.go Ports response behavior tests.
agent/​options.go Documents structured wrapping.
agent/​history.go Exposes in-memory history helpers.
agent/​history_test.go Tests history APIs and behavior.
agent/​harness/​todo/​todo.go Clones todo snapshots.
agent/​harness/​todo/​todo_test.go Tests stable todo snapshots.
agent/​format/​jsonformat/​structuredoutput.go Implements schema wrapping and decoding.
agent/​format/​jsonformat/​encoding_test.go Tests wrapper constraints and decoding.
agent/​context_test.go Ports context-provider tests.
agent/​compaction/​provider.go Serializes per-session compaction.
agent/​compaction/​historyprovider.go Validates history state keys.
agent/​compaction/​historyprovider_test.go Expands reducer tests.
agent/​compaction/​compaction_test.go Tests concurrent compaction.
agent/​agent.go Clarifies format documentation.
agent/​agent_test.go Ports agent metadata/invocation tests.
_catalog/​dotnet-go-sdk-symbol-mapping.json Reconciles APIs and test pairs.

🧠 Review effort: Balanced


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

Comment thread agent/session.go Outdated
Comment thread agent/session.go
Comment thread provider/aguiprovider/agui.go
@github-actions github-actions Bot added kind:code Changes production behavior or code kind:examples Changes examples or example-support metadata kind:tests Changes tests, fixtures, or test infrastructure labels Oct 9, 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 labels Oct 9, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

API consistency review

Result Scope
aligned public API / user-visible behavior / examples

Changed Go contract

  • agent.Session gained an internal lock (sessionState with sync.RWMutex) so Get/Set/Delete/ServiceID/SetServiceID/marshal/unmarshal are safe for concurrent use after initialization; Session.Get/Set/Delete now panic on blank keys.
  • New exported Session.InMemoryHistory(stateKey string) ([]*message.Message, error) and Session.SetInMemoryHistory(stateKey string, messages []*message.Message) error.
  • compaction.NewHistoryProvider / compaction.NewContextProvider / agent.NewInMemoryHistoryProvider now panic on blank StateKey; contextProvider gained a per-session mutex around compaction.
  • New jsonformat.WrapNonObjectSchema and Format.UnmarshalStructuredOutput, wired into openaiprovider (chat + responses), anthropicprovider, and geminiprovider formatOf/unmarshal so non-object structured-output schemas are transparently wrapped in an object "data" property on the wire and unwrapped on decode; agent.WithStructuredOutput doc updated accordingly.
  • aguiprovider.getOrCreateThreadID adds a package-level mutex guarding first-time thread-ID initialization and a nil-session fallback.
  • examples/02-agents/agents/step18_compaction_pipeline updated to print in-memory history length using the new Session.InMemoryHistory accessor.

Upstream evidence reviewed

Implementation Source Contract checked
.NET AgentSessionStateBag.cs Session state bag is explicitly documented and implemented as thread-safe (ConcurrentDictionary), matching Go's new per-session sync.RWMutex guarding Session state.
.NET AgentSessionExtensions.cs TryGetInMemoryChatHistory/SetInMemoryChatHistory extension methods are the direct analog of Go's new Session.InMemoryHistory/SetInMemoryHistory; semantics (replace-on-set, state-key default, nil/missing-state handling) line up modulo idiomatic error-return vs. out/exception differences.
.NET AIAgentStructuredOutput.cs RunAsync<T> calls StructuredOutputSchemaUtilities.WrapNonObjectSchema on the generated ChatResponseFormat before dispatch and tracks IsWrappedInObject for unwrapping on decode — the same object-wrapping-for-non-object-schema behavior Go now implements via jsonformat.WrapNonObjectSchema/UnmarshalStructuredOutput, applied consistently across providers.

Assessment

The PR is a faithful, well-evidenced port of stable .NET Abstractions behavior: session thread-safety matches the documented ConcurrentDictionary-backed AgentSessionStateBag contract, the new in-memory history accessors mirror AgentSessionExtensions, and the non-object structured-output wrapping mirrors AIAgentStructuredOutput's WrapNonObjectSchema/IsWrappedInObject round trip, applied uniformly across OpenAI (chat + responses), Anthropic, and Gemini providers — consistent with ForType unwrapped local validation being preserved as stated in WithStructuredOutput's updated doc. The new blank-StateKey panics and aguiprovider thread-ID init-lock are internal hardening with no divergent upstream default. No actionable parity issues found; go build ./... succeeds on the PR branch.

Warning

Firewall blocked 4 domains

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

  • github.com
  • 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
    - "github.com"
    - "proxy.golang.org"
    - "storage.googleapis.com"
    - "sum.golang.org"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent for #1273 · copilot · auto · 86 AIC · ⌖ 7.63 AIC · ⊞ 13.9K · ◷

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 area:examples Changes files in the examples area area:message Changes files in the message area area:provider/agui Changes files in the provider / agui area area:provider/anthropic Changes files in the provider / anthropic area area:provider/gemini Changes files in the provider / gemini area area:provider/openai Changes files in the provider / openai area area:provider Changes files in the provider area kind:code Changes production behavior or code kind:examples Changes examples or example-support metadata 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:xlarge More than 300 changed lines or 10 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants