Propagate message.AuthorName to the OpenAI chat request name field - #730
Propagate message.AuthorName to the OpenAI chat request name field#730PratikDhanave wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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
namefield can be set. - Add
sanitizeAuthorNamehelper 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.
This comment has been minimized.
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.
e32f99b to
81d324b
Compare
Cross-Repo Parity ReviewPR: Propagate Scope: SummaryThis PR restores a previously dropped behavior: mapping Parity Findings✅ Feature intent: alignedBoth the Python and .NET SDKs pass
|
What
buildMessageParaminprovider/openaiprovider/chat.gonever readmsg.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 theopenai.SystemMessage/UserMessageconvenience helpers) so the optionalnamefield can be set. A newsanitizeAuthorNamehelper produces the value; tool messages are left unchanged since they have no name field.Why
message.Message.AuthorNameis populated by the multi-agent / group-chat hosting flows (agentworkflow sets it), and the OpenAI SDK exposesNameon 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 setsParticipantName = SanitizeAuthorName(AuthorName).sanitizeAuthorNamemirrors 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.godriving the exportedRunAPI through the existing fake-transport harness and asserting the outgoing request body:TestChatAuthorNamePropagation_NonStreaming—AuthorName: "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 leavenameunset.These fail before the change and pass after.
go build ./...,go vet ./provider/openaiprovider/..., andgo test ./provider/openaiprovider/...are green.