Table of Contents

Method StreamAsync

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

StreamAsync(Agent, string, AgentExecutionOptions, CancellationToken)

Streams agent output as an async enumerable.

public static IAsyncEnumerable<AgentStreamToken> StreamAsync(this Agent agent, string input, AgentExecutionOptions options = null, CancellationToken cancellationToken = default)

Parameters

agent Agent

The agent to execute.

input string

The input prompt.

options AgentExecutionOptions

Optional execution options.

cancellationToken CancellationToken

Cancellation token.

Returns

IAsyncEnumerable<AgentStreamToken>

An async enumerable of streaming tokens.

Examples

await foreach (var token in agent.StreamAsync("Hello"))
{
    if (token.Type == AgentStreamTokenType.Content)
        Console.Write(token.Text);
}

StreamAsync(Agent, string, AgentStreamResult, AgentExecutionOptions, CancellationToken)

Streams agent output with result accumulation.

public static IAsyncEnumerable<AgentStreamToken> StreamAsync(this Agent agent, string input, AgentStreamResult result, AgentExecutionOptions options = null, CancellationToken cancellationToken = default)

Parameters

agent Agent

The agent to execute.

input string

The input prompt.

result AgentStreamResult

Accumulator for the streaming result.

options AgentExecutionOptions

Optional execution options.

cancellationToken CancellationToken

Cancellation token.

Returns

IAsyncEnumerable<AgentStreamToken>

An async enumerable of streaming tokens.

Examples

var result = new AgentStreamResult();
await foreach (var token in agent.StreamAsync("Hello", result))
{
    Console.Write(token.Text);
}
Console.WriteLine($"\n\nTotal tokens: {result.TokenCount}");