Skip to content

Propagate message.AuthorName to the OpenAI chat request name field - #730

Open
PratikDhanave wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:propagate-authorname-openai-chat
Open

Propagate message.AuthorName to the OpenAI chat request name field#730
PratikDhanave wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:propagate-authorname-openai-chat

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

buildMessageParam in provider/openaiprovider/chat.go never read msg.AuthorName, so the participant name was silently dropped from Chat Completions requests. System, user, and assistant params are now built as struct literals (rather than the openai.SystemMessage/UserMessage convenience helpers) so the optional name field can be set. A new sanitizeAuthorName helper produces the value; tool messages are left unchanged since they have no name field.

Why

message.Message.AuthorName is populated by the multi-agent / group-chat hosting flows (agentworkflow sets it), and the OpenAI SDK exposes Name on the System/User/Assistant message params to differentiate participants of the same role. The Go port dropped it, losing attribution.

This restores parity with the .NET OpenAIChatClient, which sets ParticipantName = SanitizeAuthorName(AuthorName). sanitizeAuthorName mirrors that behavior: it returns empty for empty/whitespace input, keeps only alphanumeric characters, and caps the result at 64 characters, so blank or fully-disallowed names leave the field unset.

Tests

Added black-box tests to chat_test.go driving the exported Run API through the existing fake-transport harness and asserting the outgoing request body:

  • TestChatAuthorNamePropagation_NonStreamingAuthorName: "Agent One" on system/user/assistant messages surfaces as "name": "AgentOne".
  • TestChatAuthorNameSanitizationAndTruncation_NonStreaming — a disallowed char plus a 70-char name is stripped and truncated to 64 runes.
  • TestChatAuthorNameEmpty_NonStreaming — empty / whitespace-only names leave name unset.

These fail before the change and pass after. go build ./..., go vet ./provider/openaiprovider/..., and go test ./provider/openaiprovider/... are green.

@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 24, 2026 03:42
Copilot AI review requested due to automatic review settings July 24, 2026 03:42

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.

Pull request overview

This PR restores propagation of message.Message.AuthorName into the OpenAI Chat Completions request message "name" field for system/user/assistant roles in openaiprovider, aligning Go behavior with the multi-agent/group-chat hosting flows that populate AuthorName.

Changes:

  • Build system/user/assistant chat message params as struct literals so the optional name field can be set.
  • Add sanitizeAuthorName helper to trim/strip disallowed characters and cap names at 64 characters, leaving the field unset when the result is empty.
  • Add black-box request-body tests (non-streaming) asserting name propagation, sanitization/truncation, and empty-name behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
provider/openaiprovider/chat.go Propagates sanitized AuthorName into OpenAI message params for system/user/assistant and adds the sanitizer helper.
provider/openaiprovider/chat_test.go Adds request-body assertions verifying name propagation/sanitization through the exported Run API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

This comment has been minimized.

buildMessageParam dropped msg.AuthorName, so participant attribution
set in multi-agent and group-chat flows never reached the Chat
Completions API. Build the system, user, and assistant params as struct
literals and set the optional name field via a sanitizeAuthorName helper
that mirrors .NET OpenAIChatClient.SanitizeAuthorName (keep alphanumerics,
cap at 64 characters, empty for blank input). Tool messages are unchanged
as they have no name field.
@PratikDhanave
PratikDhanave force-pushed the propagate-authorname-openai-chat branch from e32f99b to 81d324b Compare July 24, 2026 09:30
@github-actions

Copy link
Copy Markdown
Contributor

Cross-Repo Parity Review

PR: Propagate message.AuthorName to the OpenAI chat request name field

Scope: provider/openaiprovider/chat.go + chat_test.go — internal implementation, no exported API surface changed.

Summary

This PR restores a previously dropped behavior: mapping message.Message.AuthorName to the OpenAI Chat Completions name field for system, user, and assistant messages. The fix is correct and well-motivated.

Parity Findings

✅ Feature intent: aligned

Both the Python and .NET SDKs pass author_name / AuthorName through to the OpenAI name field. The Go implementation now joins them.

⚠️ Minor divergence: sanitization behavior

The Python implementation (python/packages/openai/agent_framework_openai/_chat_completion_client.py) passes author_name verbatim to the name field without any filtering or truncation:

if message.author_name and message.role != "tool":
    args["name"] = message.author_name

The Go implementation introduces a sanitizeAuthorName helper that strips all non-alphanumeric characters and truncates to 64 characters before setting the field.

The PR description attributes this sanitization to the .NET OpenAIChatClient.SanitizeAuthorName, but a code search of microsoft/agent-framework found no such symbol with that exact name in the current .NET source. The sanitization logic may be present but differently named or inlined in .NET — the upstream reference should be confirmed.

Impact: If a message.AuthorName contains spaces, hyphens, underscores, or non-ASCII letters, Go will silently strip them while Python passes the raw value. This produces different name field values for the same message across SDKs.

Recommendation: Verify whether the .NET SDK actually performs this sanitization, and if Python should be updated to match (or vice versa). If sanitization is intentional and the .NET SDK does it, it would be worth opening an upstream issue to align Python behavior. If sanitization is not present in .NET, the Go helper should be reconsidered.

✅ Tool messages: aligned

Tool messages correctly leave the name field unset in Go, matching Python behavior (role != "tool" guard).

✅ No exported API change

sanitizeAuthorName is unexported. The public-api-change label is not warranted for this PR.

Warning

Firewall blocked 1 domain

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

  • awmgmcpg

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

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent · 45.9 AIC · ⌖ 5.07 AIC · ⊞ 5.9K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants