Repository navigation
Python: Separate message texts with a newline in AgentResponse.text - #10093
Open
Mikhail Grechannikov (Revinand) wants to merge 1 commit into
Open
Mikhail Grechannikov (Revinand) wants to merge 1 commit into
Mikhail Grechannikov (Revinand) wants to merge 1 commit into
Conversation
Mikhail Grechannikov (Revinand)
temporarily deployed
to
github-app-auth
November 4, 2026 11:57 — with
GitHub Actions
Inactive
Mikhail Grechannikov (Revinand)
had a problem deploying
to
github-app-auth
November 4, 2026 11:57 — with
GitHub Actions
Error
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the change to separate non-empty response messages with newlines.
No open issues 🎉
What changed in this PR
Fixes #10067 by separating non-empty message texts in Python’s AgentResponse.text with newlines, preventing tool-call preambles from running into final answers. Structured .value parsing remains unchanged.
Changes:
- Join non-empty message texts with
"\n"and document the behavior. - Add regression coverage for messages surrounding a tool call and update existing text assertions.
| File | Description |
|---|---|
python/packages/core/tests/core/test_types.py |
Tests newline-separated output and omission of textless tool-result messages. |
python/packages/core/agent_framework/_types.py |
Updates AgentResponse.text joining logic and its docstring. |
Review effort: Balanced
Author
|
@microsoft-github-policy-service agree |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
AgentResponse.textjoins the texts of a response's messages with no separator. An agent that calls a tool returns the whole loop in one response, and a sentence the model writes before the tool call runs into the final answer:'Let me check the weather.It is sunny in Paris.'. The same text comes back fromstr(response)and from an agent wrapped withas_tool(), which returns it to the calling model..NET's
AgentResponse.Textputs a newline between the texts of non-empty messages (ConcatText), and Python'sChatResponse.textjoins its messages with"\n".Description & Review Guide
AgentResponse.textjoins the texts of non-empty messages with"\n"and skips messages without text, such as tool results, asConcatTextdoes. The docstring describes the separator. A new test covers a preamble with a tool call, a tool result and an answer. Two existing assertions pinned the joined output and now expect the newline:"HelloHello"becomes"Hello\nHello"intest_agent_run_response_text_property, and the two JSON documents intest_agent_response_value_parses_final_message_with_response_formatare separated by a newline. Its.valueassertions are unchanged..textputs a newline between those texts, andstr(response)and the result ofas_tool()change with it. Responses with one message or none return the same text as before..valueis not affected: it parses only the last message since Python: parse structured response value from final message #6383.ChatResponse.textshould match. It joins every message with"\n"and strips the result, and an empty message in the middle, such as a tool result, leaves a blank line:'Let me check.\n\nIt is sunny.'. I left it unchanged to keep this PR to .NET: Python: [Bug]: AgentResponse.text joins message texts without a separator #10067.Related Issue
Fixes #10067
No other open PR addresses this issue.
AI Assistance
AI assistance details: Claude Code helped with the issue analysis, the implementation, the tests and this description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) - a workflow keeps the label and title prefix in sync automatically.