Class StreamingAgentExecutor
Executes agents with streaming output support.
Provides both callback-based and IAsyncEnumerable<T> APIs for consuming streaming agent responses.
public sealed class StreamingAgentExecutor : IDisposable
- Inheritance
-
StreamingAgentExecutor
- Implements
- Inherited Members
Examples
// Callback-based streaming
var executor = new StreamingAgentExecutor();
var handler = DelegateStreamHandler.Console();
var result = await executor.ExecuteStreamingAsync(agent, "Hello", handler);
// IAsyncEnumerable streaming
await foreach (var token in executor.StreamAsync(agent, "Hello"))
{
Console.Write(token.Text);
}
Constructors
- StreamingAgentExecutor()
Initializes a new instance of the StreamingAgentExecutor class.
Properties
- BufferSize
Gets or sets the buffer size for token batching.
Larger values reduce callback overhead but increase latency. Default is 1 (no batching).
- StreamStatus
Gets or sets whether to include status updates.
Default is false.
- StreamThinking
Gets or sets whether to include thinking tokens in the stream.
When true, reasoning from planning strategies is streamed. Default is false.
- StreamToolCalls
Gets or sets whether to include tool call/result tokens.
Default is true.
Methods
- Dispose()
Disposes the executor.
- ExecuteStreamingAsync(Agent, string, IAgentStreamHandler, AgentExecutionOptions, CancellationToken)
Executes an agent with streaming output to a handler.
- StreamAsync(Agent, string, AgentStreamResult, AgentExecutionOptions, CancellationToken)
Streams agent output as an async enumerable.
Events
- StreamingCompleted
Fired when streaming completes.
- StreamingStarted
Fired when streaming starts.