Description
An agent whose name contains a space (or any of < | \ / >) cannot complete a single run on the Chat Completions path: the framework stamps the display name onto message.author_name, and OpenAIChatCompletionClient forwards it verbatim as the request-message name field. OpenAI validates that field against ^[^\s<|\\/>]+$, so every request 400s.
The forwarding was added by #2951 ("Support OpenAI message 'name' field"), whose discussion explicitly quotes the .NET implementation's SanitizeAuthorName — but the Python implementation shipped without the sanitization step. The .NET side hit the identical bug (#1195) and fixed it in dotnet/extensions#6827 by sanitizing; the Python port still sends the raw name from three sites in agent_framework_openai/_chat_completion_client.py (_prepare_message_for_openai: the system/developer path, the general path, and the pending-args path — main @ c35a63e lines ~883, ~898, ~955), with no validation anywhere in the file.
- Expected: a human-readable agent name like
"My Agent" works; the wire name is sanitized to the provider's charset (as .NET does).
- Actual:
openai.BadRequestError 400 on every request from that agent.
Suggested fix: port .NET's SanitizeAuthorName — replace characters matching [\s<|\\/>] before setting name, at all three assignment sites.
Code Sample
Serialization-only repro (no network):
from agent_framework import Content, Message
from agent_framework_openai import OpenAIChatCompletionClient
client = OpenAIChatCompletionClient(model="gpt-4o", api_key="sk-not-used")
msg = Message(role="assistant", contents=[Content.from_text("hello")], author_name="My Agent")
print(client._prepare_message_for_openai(msg))
Output — name goes out with the space, which the API rejects:
[{'role': 'assistant', 'name': 'My Agent', 'content': 'hello'}]
End-to-end, the same happens for any Agent(name="My Agent", ...) backed by OpenAIChatCompletionClient, since the agent's display name is stamped onto author_name on every response message.
Error Messages / Stack Traces
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid 'messages[1].name': string does not match pattern. Expected a string that matches the pattern '^[^\\s<|\\\\/>]+$'.", 'type': 'invalid_request_error', 'param': 'messages[1].name', 'code': 'invalid_value'}}
Package Versions
agent-framework-core: 1.10.0 (same behavior at 1.11.0), agent-framework-openai: 1.10.0 (verified identical in 1.10.1, the latest release; still present on main @ c35a63e)
Python Version
Python 3.12
Additional Context
Description
An agent whose
namecontains a space (or any of< | \ / >) cannot complete a single run on the Chat Completions path: the framework stamps the display name ontomessage.author_name, andOpenAIChatCompletionClientforwards it verbatim as the request-messagenamefield. OpenAI validates that field against^[^\s<|\\/>]+$, so every request 400s.The forwarding was added by #2951 ("Support OpenAI message 'name' field"), whose discussion explicitly quotes the .NET implementation's
SanitizeAuthorName— but the Python implementation shipped without the sanitization step. The .NET side hit the identical bug (#1195) and fixed it in dotnet/extensions#6827 by sanitizing; the Python port still sends the raw name from three sites inagent_framework_openai/_chat_completion_client.py(_prepare_message_for_openai: the system/developer path, the general path, and the pending-args path —main@ c35a63e lines ~883, ~898, ~955), with no validation anywhere in the file."My Agent"works; the wirenameis sanitized to the provider's charset (as .NET does).openai.BadRequestError400 on every request from that agent.Suggested fix: port .NET's
SanitizeAuthorName— replace characters matching[\s<|\\/>]before settingname, at all three assignment sites.Code Sample
Serialization-only repro (no network):
Output —
namegoes out with the space, which the API rejects:End-to-end, the same happens for any
Agent(name="My Agent", ...)backed byOpenAIChatCompletionClient, since the agent's display name is stamped ontoauthor_nameon every response message.Error Messages / Stack Traces
Package Versions
agent-framework-core: 1.10.0 (same behavior at 1.11.0), agent-framework-openai: 1.10.0 (verified identical in 1.10.1, the latest release; still present on
main@ c35a63e)Python Version
Python 3.12
Additional Context
SanitizeAuthorNamein Fix a couple of issues in M.E.AI.OpenAI clients dotnet/extensions#6827 — the Python implementation of Python: Support OpenAI message "name" field #2951 omitted that step.author_name).[^\s<|\\/>]+, which leaks a wire-format constraint into display names.