Table of Contents

Interface IAgentStreamHandler

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

Interface for handling streaming agent output.

Implement this interface to receive tokens as they are generated, enabling real-time display of agent responses.

public interface IAgentStreamHandler

Examples

class ConsoleStreamHandler : IAgentStreamHandler
{
    public Task OnTokenAsync(AgentStreamToken token, CancellationToken ct)
    {
        if (token.Type == AgentStreamTokenType.Content)
            Console.Write(token.Text);
        return Task.CompletedTask;
    }

    public Task OnStartAsync(Agent agent, string input, CancellationToken ct)
    {
        Console.WriteLine($"Starting: {agent.Identity?.Persona}");
        return Task.CompletedTask;
    }

    public Task OnCompleteAsync(AgentExecutionResult result, CancellationToken ct)
    {
        Console.WriteLine("\nComplete!");
        return Task.CompletedTask;
    }
}

Methods

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.