TextResponse Class

Definition

A high-level convenience that produces a complete text-message response stream. Implements IAsyncEnumerable<T> so it can be returned directly from CreateAsync(CreateResponse, ResponseContext, CancellationToken).

Handles the full SSE lifecycle automatically: response.createdresponse.in_progress → message/content events → response.completed.

Use the TextResponse(ResponseContext, CreateResponse, Func<CancellationToken,Task<String>>, Action<ResponseObject>) constructor when you have the complete text available (or can produce it in a single async call). Use the TextResponse(ResponseContext, CreateResponse, Func<CancellationToken,IAsyncEnumerable<String>>, Action<ResponseObject>) constructor when text arrives incrementally (e.g., token-by-token from an LLM).

public class TextResponse : System.Collections.Generic.IAsyncEnumerable<Azure.AI.AgentServer.Responses.Models.ResponseStreamEvent>
type TextResponse = class
    interface IAsyncEnumerable<ResponseStreamEvent>
Public Class TextResponse
Implements IAsyncEnumerable(Of ResponseStreamEvent)
Inheritance
TextResponse
Implements

Examples

Simplest usage — return a single text string:

return new TextResponse(context, request,
    createText: ct => Task.FromResult("Hello!"));

Constructors

Name Description
TextResponse(ResponseContext, CreateResponse, Func<CancellationToken,IAsyncEnumerable<String>>, Action<ResponseObject>)

Creates a TextResponse that produces a text message from a stream of text chunks (e.g., tokens from an LLM). Each chunk is emitted as a response.output_text.delta event.

TextResponse(ResponseContext, CreateResponse, Func<CancellationToken,Task<String>>, Action<ResponseObject>)

Creates a TextResponse that produces a single text message from a complete string.

Methods

Name Description
GetAsyncEnumerator(CancellationToken)

Returns an enumerator that iterates asynchronously through the collection.

Applies to