Skip to content

[dotnet-port-api] Port message source attribution helpers - #1000

Open
Michelle Clayton (michelle-clayton-work) wants to merge 2 commits into
mainfrom
dotnet-port-api-message-source-helpers-c2b406815d117693
Open

[dotnet-port-api] Port message source attribution helpers#1000
Michelle Clayton (michelle-clayton-work) wants to merge 2 commits into
mainfrom
dotnet-port-api-message-source-helpers-c2b406815d117693

Conversation

@michelle-clayton-work

Copy link
Copy Markdown
Contributor

Summary

Port the small .NET message-source attribution helper surface to Go by adding message.Message helpers for reading and applying request message source attribution.

This change adds (*message.Message).SourceType(), (*message.Message).SourceID(), and (*message.Message).WithSource(...), then reuses WithSource in the context-provider, history-provider, and middleware source-stamping paths. It also updates the feature comparison matrix to mark this helper surface as aligned.

Ported .NET PRs

Relevant upstream commits:

  • ad0dac3c86201dc7dc1cd4866ba7e4502a910a0d
  • 7dccf3a07bc5fd76004b85305f5121712e188b15

Breaking Changes

No.

Tests and Examples

  • go test ./...
  • Added message/message_test.go coverage for default source type, explicit source id/type access, and clone-vs-reuse behavior in WithSource
  • No example changes were needed because the underlying source attribution workflow already existed; this PR ports the missing helper API surface

Notes

  • This is a narrow API-parity PR focused on the helper surface called out in docs/dotnet-go-sdk-feature-comparison.md
  • Broader history-provider reducer-trigger parity remains out of scope for this PR

Generated by .NET to Go API Porting Agent · 1.2K AIC · ⌖ 24.1 AIC · ⊞ 21.7K ·

Closes #761

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 4, 2026 22:28
@github-actions github-actions Bot added area:agent Changes files in the agent area area:message Changes files in the message 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 helper methods are small, nil-safe, covered by focused unit tests, and the call-site refactors preserve prior behavior while reducing duplication.

Pull request overview

Ports the .NET message-source attribution helper API surface into the Go SDK by adding convenience helpers on message.Message, then refactors existing source-stamping call sites to reuse the new helper. This brings the Go SDK closer to documented API parity without altering the underlying source attribution model.

Changes:

  • Added (*message.Message).SourceType(), SourceID(), and WithSource(...) helpers (nil-safe, clone-on-change behavior).
  • Refactored context provider, history provider, and middleware source-stamping to use WithSource.
  • Updated the .NET↔Go feature comparison matrix to mark source attribution helpers as aligned, and added unit tests for the new helpers.
File summaries
File Description
agent/context.go Replaces manual clone-and-stamp logic with msg.WithSource(...) for provided context messages.
agent/history.go Replaces manual clone-and-stamp logic with msg.WithSource(...) for provided history messages.
agent/middleware.go Uses WithSource when stamping middleware-generated messages with an empty source.
docs/dotnet-go-sdk-feature-comparison.md Updates matrix row to reflect the new message.Message source attribution helpers.
message/message.go Introduces SourceType(), SourceID(), and WithSource(...) helper methods on Message.
message/message_test.go Adds tests for default source type behavior and WithSource clone-vs-reuse semantics.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

@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:low Limited blast radius and straightforward rollback and removed pending-auto-risk Automatic risk classification is in progress labels Sep 4, 2026
…ge-source-helpers-c2b406815d117693

# Conflicts:
#	agent/context.go
#	agent/history.go
#	agent/middleware.go
#	docs/dotnet-go-sdk-feature-comparison.md
#	message/message.go
#	message/message_test.go
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Scope: public API, user-visible behavior

Changed Go contract: New exported message.Message methods SourceType() SourceType, SourceID() string, and WithSource(Source) *Message; agent/context.go, agent/history.go, and agent/middleware.go refactored to call WithSource instead of duplicating clone-and-tag logic inline (no behavior change to callers — same clone-only-when-changed semantics as before).

Upstream evidence reviewed:

  • dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageExtensions.csGetAgentRequestMessageSourceType(), GetAgentRequestMessageSourceId(), WithAgentRequestMessageSource(sourceType, sourceId) (from .NET: [BREAKING] Add ability to mark the source of Agent request messages and use that for filtering agent-framework#3540, #3805)
  • dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRequestMessageSourceType.csExternal (default), AIContextProvider, ChatHistory source type constants
  • Go agent/context.go (SourceTypeContextProvider), agent/history.go (SourceTypeHistoryProvider), agent/middleware.go (SourceTypeMiddleware), message/message.go (SourceTypeExternal)

Result: aligned. The Go SourceType()/SourceID()/WithSource() trio is a faithful, idiomatic port of the .NET ChatMessageExtensions helpers: same default-to-external semantics, same "return original if source unchanged, else clone" behavior, and equivalent source-type taxonomy (external/context-provider/history-provider vs. .NET's External/AIContextProvider/ChatHistory, plus a Go-specific middleware source type consistent with existing Go call sites). The refactor of agent/context.go, agent/history.go, and agent/middleware.go to reuse WithSource is behavior-preserving (same clone-avoidance logic, just deduplicated). No unconditional enablement or default change was introduced — this only exposes helper methods around existing, already-active source-stamping behavior. Docs update in docs/dotnet-go-sdk-feature-comparison.md accurately reflects the new "Aligned" status.

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 #1000 · copilot · auto · 27.5 AIC · ⌖ 5.86 AIC · ⊞ 9.6K ·

@github-actions github-actions Bot added public-api-change Pull Request changes public APIs pending-auto-risk Automatic risk classification is in progress risk:low Limited blast radius and straightforward rollback and removed risk:low Limited blast radius and straightforward rollback pending-auto-risk Automatic risk classification is in progress labels Sep 5, 2026
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:message Changes files in the message 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:low Limited blast radius and straightforward rollback 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] Port message source attribution helpers

2 participants