Skip to content

Join Response.String() messages with a newline like .NET ConcatText - #742

Open
PratikDhanave wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:response-string-newline-concattext
Open

Join Response.String() messages with a newline like .NET ConcatText#742
PratikDhanave wants to merge 1 commit into
microsoft:mainfrom
PratikDhanaveFork:response-string-newline-concattext

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

Response.String() flattened the text of every message into a single strings.Builder with no separator. For a two-message assistant turn (foo, Bar) it returned fooBar. It now joins each non-empty per-message text with a newline, yielding foo\nBar, and skips empty messages so no double newline is produced. Text glued within a single message (multiple TextContent items) is unchanged.

Why (.NET parity)

In microsoft/agent-framework, AgentResponse.Text is backed by messages.ConcatText(). ConcatText(IList<ChatMessage>) documents that "A newline separator is added between each non-empty piece of text" and uses AppendLine between non-empty messages. The Go port glued messages together instead, so the same two-message turn produced fooBar in Go vs foo\nBar in .NET.

The per-message join was already correct: msg.String() == message.Contents.Text(), the analog of ChatMessage.Text. This change reuses msg.String() and only fixes the cross-message separator.

This also aligns the agent-as-tool result: agenttool's FuncTool returns resp.String() as the tool output, the analog of .NET AsAIFunction returning response.Text.

Testing

Added TestResponse_String in agent/response_test.go (black-box, package agent_test) covering: two single-text messages join with a newline; an empty middle message is skipped without a double newline; multiple TextContent items within one message stay glued. go build ./..., go vet ./agent/..., and go test ./agent/... (plus ./tool/agenttool/...) pass.

Copilot AI review requested due to automatic review settings July 24, 2026 04:00
@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 24, 2026 04:00

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.

Pull request overview

This PR aligns agent.Response.String() output with the .NET ConcatText / AgentResponse.Text behavior by inserting a newline between each non-empty message’s text, instead of concatenating message texts with no separator.

Changes:

  • Update Response.String() to join each non-empty msg.String() with \n and skip empty messages.
  • Add black-box tests covering newline joining, skipping empty messages without double newlines, and preserving within-message text concatenation across multiple TextContent items.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
agent/response.go Changes Response.String() to newline-separate non-empty message text using msg.String() (which delegates to message.Contents.Text()).
agent/response_test.go Adds TestResponse_String to validate cross-message newline joining and empty-message skipping while keeping within-message concatenation unchanged.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot added parity-approved Go API consistency review found no parity issues public-api-change Pull Request changes public APIs labels Jul 24, 2026
@github-actions

This comment has been minimized.

Response.String() flattened every message's text into one builder with no
separator, so a multi-message assistant turn returned "fooBar" where .NET
AgentResponse.Text (backed by ChatMessage list ConcatText) returns "foo\nBar".
Join each non-empty per-message text with a newline, skipping empty messages,
matching .NET semantics. This also aligns the agent-as-tool result returned by
agenttool's FuncTool, which surfaces resp.String().
@PratikDhanave
PratikDhanave force-pushed the response-string-newline-concattext branch from a3831db to f533990 Compare July 24, 2026 09:30
@github-actions

Copy link
Copy Markdown
Contributor

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent · 27.7 AIC · ⌖ 4.9 AIC · ⊞ 5.9K ·

@gdams
gdams added this pull request to the merge queue Jul 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Jul 29, 2026
@gdams
gdams enabled auto-merge July 29, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity-approved Go API consistency review found no parity issues public-api-change Pull Request changes public APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants