Table of Contents

Method RunStreamingAsync

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

RunStreamingAsync(Agent, string, IAgentStreamHandler, AgentExecutionOptions, CancellationToken)

Executes the agent with streaming output to a handler.

public static Task<AgentExecutionResult> RunStreamingAsync(this Agent agent, string input, IAgentStreamHandler handler, AgentExecutionOptions options = null, CancellationToken cancellationToken = default)

Parameters

agent Agent

The agent to execute.

input string

The input prompt.

handler IAgentStreamHandler

The stream handler to receive tokens.

options AgentExecutionOptions

Optional execution options.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<AgentExecutionResult>

The final execution result.

Examples

var handler = DelegateStreamHandler.Console();
var result = await agent.RunStreamingAsync("Hello", handler);

RunStreamingAsync(Agent, string, Action<AgentStreamToken>, AgentExecutionOptions, CancellationToken)

Executes the agent with streaming output using a token callback.

public static Task<AgentExecutionResult> RunStreamingAsync(this Agent agent, string input, Action<AgentStreamToken> onToken, AgentExecutionOptions options = null, CancellationToken cancellationToken = default)

Parameters

agent Agent

The agent to execute.

input string

The input prompt.

onToken Action<AgentStreamToken>

Callback for each token.

options AgentExecutionOptions

Optional execution options.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<AgentExecutionResult>

The final execution result.

Examples

var result = await agent.RunStreamingAsync("Hello", 
    token => Console.Write(token.Text));

RunStreamingAsync(Agent, string, Action<string>, AgentExecutionOptions, CancellationToken)

Executes the agent with streaming content output using a string callback.

public static Task<AgentExecutionResult> RunStreamingAsync(this Agent agent, string input, Action<string> onContent, AgentExecutionOptions options = null, CancellationToken cancellationToken = default)

Parameters

agent Agent

The agent to execute.

input string

The input prompt.

onContent Action<string>

Callback for content text (not thinking or tool calls).

options AgentExecutionOptions

Optional execution options.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<AgentExecutionResult>

The final execution result.

Examples

var result = await agent.RunStreamingAsync("Hello",
    text => Console.Write(text));