Skip to content

AgentResponseExtensions

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework

AgentResponseExtensions Class

Convenience extensions for Microsoft.Agents.AI.AgentResponse.

public static class AgentResponseExtensions

Inheritance System.Object 🡒 AgentResponseExtensions

Methods

AgentResponseExtensions.GetText(this AgentResponse) Method

Extracts the concatenated text content from all messages in the response. Returns null if the response has no messages or all messages have empty text.

public static string? GetText(this Microsoft.Agents.AI.AgentResponse response);

Parameters

response Microsoft.Agents.AI.AgentResponse

Returns

System.String

Remarks

MAF's Microsoft.Agents.AI.AgentResponse.Messages can contain multiple Microsoft.Extensions.AI.ChatMessage entries (e.g., tool-call results interleaved with assistant text). This method concatenates only the non-empty Text properties, separated by newlines, into a single string.

Typical usage for standalone agent runs:

var response = await agent.RunAsync(prompt, cancellationToken: ct);
var text = response.GetText(); // "The answer is 42."