Skip to content

Python: Separate message texts with a newline in AgentResponse.text - #10093

Open
Mikhail Grechannikov (Revinand) wants to merge 1 commit into
microsoft:mainfrom
Revinand:fix/agent-response-text-separator
Open

Mikhail Grechannikov (Revinand) wants to merge 1 commit into
microsoft:mainfrom
Revinand:fix/agent-response-text-separator

Conversation

@Revinand

Copy link
Copy Markdown

Motivation & Context

AgentResponse.text joins 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 from str(response) and from an agent wrapped with as_tool(), which returns it to the calling model.

.NET's AgentResponse.Text puts a newline between the texts of non-empty messages (ConcatText), and Python's ChatResponse.text joins its messages with "\n".

Description & Review Guide

  • What are the major changes? AgentResponse.text joins the texts of non-empty messages with "\n" and skips messages without text, such as tool results, as ConcatText does. 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" in test_agent_run_response_text_property, and the two JSON documents in test_agent_response_value_parses_final_message_with_response_format are separated by a newline. Its .value assertions are unchanged.
  • What is the impact of these changes? When a response has more than one message with text, .text puts a newline between those texts, and str(response) and the result of as_tool() change with it. Responses with one message or none return the same text as before. .value is not affected: it parses only the last message since Python: parse structured response value from final message #6383.
  • What do you want reviewers to focus on? Whether ChatResponse.text should 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

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Claude Code helped with the issue analysis, the implementation, the tests and this description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) - a workflow keeps the label and title prefix in sync automatically.

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.

🟢 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

@Revinand

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch was successfully deployed

No deployments
github-app-auth — a692827f Deployed Nov 4, 2026 by Revinand via team_check #8698
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Python: [Bug]: AgentResponse.text joins message texts without a separator

2 participants