Skip to content

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

Merged
Quim Muntal (qmuntal) merged 4 commits into
microsoft:mainfrom
PratikDhanaveFork:propagate-authorname-openai-chat
Aug 21, 2026
Merged

Propagate message.AuthorName to the OpenAI chat request name field#730
Quim Muntal (qmuntal) merged 4 commits 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 (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 (PratikDhanave) force-pushed the propagate-authorname-openai-chat branch from e32f99b to 81d324b Compare July 24, 2026 09:30
@github-actions

This comment has been minimized.

# Conflicts:
#	provider/openaiprovider/chat.go
#	provider/openaiprovider/chat_test.go
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Aug 4, 2026
# Conflicts:
#	provider/openaiprovider/chat.go
#	provider/openaiprovider/chat_test.go
@github-actions github-actions Bot added area:provider Changes files in the provider area area:provider/openai Changes files in the provider / openai area size:large At most 300 changed lines across at most 10 files pending-auto-risk Automatic risk classification is in progress labels Aug 20, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added failed-auto-risk Automatic risk classification was inconclusive or failed and removed pending-auto-risk Automatic risk classification is in progress labels Aug 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Cross-repo parity review — one issue found

This PR correctly ports the AuthorName → OpenAI Chat Completions name field propagation from .NET and Python. The overall approach (struct literals, conditional Name field, skip tool messages, 64-char cap) is well-aligned with both upstream implementations.

One parity gap: underscore handling in sanitizeAuthorName

SDK Allowed characters
Python (_chat_completion_client.py) [a-zA-Z0-9_] (regex [^a-zA-Z0-9_]+)
.NET (SanitizeAuthorName reference) [a-zA-Z0-9_] (per Python module comment)
Go (this PR) [a-zA-Z0-9] (unicode.IsLetter || unicode.IsDigit) — underscores stripped

An agent named Agent_One reaches the API as AgentOne in Go but Agent_One in Python/.NET — a silent cross-SDK divergence in multi-agent group-chat participant attribution.

See the inline comment on sanitizeAuthorName for the one-line fix and a suggested test case.

Generated by Go API Consistency Review Agent · sonnet46 · 51.9 AIC · ⌖ 5.88 AIC · ⊞ 6K ·

@github-actions github-actions Bot removed the parity-approved Go API consistency review found no parity issues label Aug 21, 2026

@github-actions github-actions Bot 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.

Generated by Go API Consistency Review Agent · sonnet46 · 51.9 AIC · ⌖ 5.88 AIC · ⊞ 6K

if strings.TrimSpace(name) == "" {
return ""
}
const maxLen = 64

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.

Parity issue: sanitizeAuthorName strips underscores, but upstream Python and .NET preserve them.

The Go implementation filters with unicode.IsLetter || unicode.IsDigit, which silently drops _.

Both upstream implementations explicitly keep underscores in allowed characters:

  • Python (_chat_completion_client.py): _INVALID_AUTHOR_NAME_RE = re.compile(r"[^a-zA-Z0-9_]+") — keeps [a-zA-Z0-9_].
  • .NET: The PR description itself cites .NET OpenAIChatClient.SanitizeAuthorName; the Python module's comment describes its character set as [a-zA-Z0-9_], matching the .NET original.

A participant named Agent_One would be sent as AgentOne by Go but as Agent_One by Python/.NET — a silent cross-SDK divergence for multi-agent group-chat flows that use underscore-separated agent names.

Suggested fix:

if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' {

The existing test TestChatAuthorNamePropagation_NonStreaming (input "Agent One" → expected "AgentOne") does not cover this case because a space is stripped by all three implementations. Please add a test with AuthorName: "Agent_One" expecting "name": "Agent_One" in the outgoing request.

Merged via the queue into microsoft:main with commit 97d0164 Aug 21, 2026
26 checks passed
@github-actions github-actions Bot added kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure labels Aug 21, 2026
@github-actions github-actions Bot added pending-auto-risk Automatic risk classification is in progress risk:medium Contained production impact requiring normal review depth and removed failed-auto-risk Automatic risk classification was inconclusive or failed pending-auto-risk Automatic risk classification is in progress labels Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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:tests Changes tests, fixtures, or test infrastructure risk:medium Contained production impact requiring normal review depth 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.

4 participants