Method RunStreamingAsync
- Namespace
- LMKit.Agents.Orchestration.Streaming
- Assembly
- LM-Kit.NET.dll
RunStreamingAsync(IOrchestrator, string, IOrchestrationStreamHandler, OrchestrationOptions, CancellationToken)
Executes the orchestration with streaming output to a handler.
public static Task<OrchestrationResult> RunStreamingAsync(this IOrchestrator orchestrator, string input, IOrchestrationStreamHandler handler, OrchestrationOptions options = null, CancellationToken cancellationToken = default)
Parameters
orchestratorIOrchestratorThe orchestrator to execute.
inputstringThe input prompt.
handlerIOrchestrationStreamHandlerThe stream handler to receive tokens.
optionsOrchestrationOptionsOptional orchestration options (StreamHandler will be set automatically).
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<OrchestrationResult>
The final orchestration result.
Examples
var handler = DelegateOrchestrationStreamHandler.ConsoleWithAgentLabels();
var result = await orchestrator.RunStreamingAsync("Analyze this data", handler);
RunStreamingAsync(IOrchestrator, string, Action<OrchestrationStreamToken>, OrchestrationOptions, CancellationToken)
Executes the orchestration with streaming output using a token callback.
public static Task<OrchestrationResult> RunStreamingAsync(this IOrchestrator orchestrator, string input, Action<OrchestrationStreamToken> onToken, OrchestrationOptions options = null, CancellationToken cancellationToken = default)
Parameters
orchestratorIOrchestratorThe orchestrator to execute.
inputstringThe input prompt.
onTokenAction<OrchestrationStreamToken>Callback for each token.
optionsOrchestrationOptionsOptional orchestration options.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<OrchestrationResult>
The final orchestration result.
Examples
var result = await orchestrator.RunStreamingAsync("Task",
token =>
{
if (token.Type == OrchestrationStreamTokenType.Content)
Console.Write(token.Text);
});
RunStreamingAsync(IOrchestrator, string, Action<string>, OrchestrationOptions, CancellationToken)
Executes the orchestration with streaming content output using a string callback.
public static Task<OrchestrationResult> RunStreamingAsync(this IOrchestrator orchestrator, string input, Action<string> onContent, OrchestrationOptions options = null, CancellationToken cancellationToken = default)
Parameters
orchestratorIOrchestratorThe orchestrator to execute.
inputstringThe input prompt.
onContentAction<string>Callback for content text (not agent transitions or tool calls).
optionsOrchestrationOptionsOptional orchestration options.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<OrchestrationResult>
The final orchestration result.
Examples
var result = await orchestrator.RunStreamingAsync("Task",
text => Console.Write(text));