Table of Contents

Class MulticastStreamHandler

Namespace
LMKit.Agents.Streaming
Assembly
LM-Kit.NET.dll

A stream handler that broadcasts to multiple handlers.

Useful for writing to multiple destinations simultaneously, such as console and file, or UI and logging.

public sealed class MulticastStreamHandler : IAgentStreamHandler
Inheritance
MulticastStreamHandler
Implements
Inherited Members

Examples

var handler = new MulticastStreamHandler()
    .Add(DelegateStreamHandler.Console())
    .Add(TextWriterStreamHandler.ToFile("log.txt"));

await agent.RunStreamingAsync("Hello", handler);

Constructors

MulticastStreamHandler()

Initializes a new instance of the MulticastStreamHandler class.

MulticastStreamHandler(params IAgentStreamHandler[])

Initializes a new instance with the specified handlers.

Properties

ContinueOnError

Gets or sets whether to continue if a handler throws an exception.

When true, exceptions are caught and execution continues with other handlers. Default is true.

Handlers

Gets the list of handlers.

Methods

Add(IAgentStreamHandler)

Adds a handler to the multicast.

Clear()

Clears all handlers.

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.

Remove(IAgentStreamHandler)

Removes a handler from the multicast.