Class BufferedStreamHandler
A stream handler that buffers tokens before forwarding.
Useful for reducing callback overhead when token-by-token updates are not needed, or for writing to destinations that benefit from larger writes.
public sealed class BufferedStreamHandler : IAgentStreamHandler, IDisposable
- Inheritance
-
BufferedStreamHandler
- Implements
- Inherited Members
Constructors
- BufferedStreamHandler(IAgentStreamHandler)
Initializes a new instance of the BufferedStreamHandler class.
Properties
- BufferContentOnly
Gets or sets whether to buffer only content tokens.
When true, non-content tokens (tool calls, status, etc.) are forwarded immediately. Default is true.
- BufferSize
Gets or sets the buffer size in characters.
When the buffer exceeds this size, it is flushed automatically. Default is 100 characters.
- FlushInterval
Gets or sets the flush interval.
The buffer is flushed periodically at this interval. Default is 100ms.
Methods
- Dispose()
Disposes the handler.
- FlushAsync(CancellationToken)
Flushes any buffered tokens to the inner handler.
- 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.