You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: [Bug]: Message("user", "text") creates one text content per character #9326
Passing a plain string as contents to Message creates one text content per character instead of a single text content. With Chat Completions, every character is then sent as its own user message.
Message.__init__ declares contents: Sequence[Content | str | Mapping[str, Any]] | None and passes it straight to _parse_content_list, which iterates it. A str is itself a Sequence[str], so the type hint accepts Message("user", "Hello"), and iterating it yields single characters. The docstring says strings are auto-converted to text content, which only holds when they are wrapped in a list.
The repository uses this form too. python/samples/04-hosting/foundry-hosted-agents/responses/workflows/main.py builds Message("user", f"Create a {request.style} slogan for {request.topic}."), and 27 test call sites in the foundry, foundry_hosting and declarative packages do the same.
Expected:Message("user", "Write a slogan.") behaves like Message("user", ["Write a slogan."]), with one text content whose text is the whole string.
contents: 15 ['W', 'r', 'i', 't', 'e'] ...
text: 'W r i t e a s l o g a n .'
chat completions messages: 15 [{'role': 'user', 'content': 'W'}, {'role': 'user', 'content': 'r'}, {'role': 'user', 'content': 'i'}] ...
Error Messages / Stack Traces
None. The message is silently split.
Package Versions
agent-framework-core: 1.21.0 (source checkout of main at b53d25e)
Python Version
Python 3.13
Additional Context
Reproduced on Windows and Linux.
Fix: wrap a bare string in a list in Message.__init__ before parsing, so it becomes a single text content. I'll open a PR with this and regression tests.
Activity