Class DelegateStreamHandler
A stream handler that delegates to callback functions.
Provides a simple way to handle streaming without implementing the full interface.
public sealed class DelegateStreamHandler : IAgentStreamHandler
- Inheritance
-
DelegateStreamHandler
- Implements
- Inherited Members
Examples
var handler = new DelegateStreamHandler(
onToken: token => Console.Write(token.Text));
await agent.RunStreamingAsync("Hello", handler);
Constructors
- DelegateStreamHandler(Action<AgentStreamToken>, Action<Agent, string>, Action<AgentExecutionResult>, Action<Exception>)
Initializes a new instance with synchronous callbacks.
- DelegateStreamHandler(Func<AgentStreamToken, CancellationToken, Task>, Func<Agent, string, CancellationToken, Task>, Func<AgentExecutionResult, CancellationToken, Task>, Func<Exception, CancellationToken, Task>)
Initializes a new instance with async callbacks.
Methods
- Console()
Creates a handler that writes content tokens to the console.
- ConsoleVerbose()
Creates a handler that writes all tokens to the console with type indicators.
- OnCompleteAsync(AgentExecutionResult, CancellationToken)
Called when streaming completes.
- OnErrorAsync(Exception, CancellationToken)
Called when an error occurs during streaming.
- OnStartAsync(Agent, string, CancellationToken)
Called when streaming starts.
- OnTokenAsync(AgentStreamToken, CancellationToken)
Called when a new token is received.