Method RunStreamingAsync
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
agentAgentThe agent to execute.
inputstringThe input prompt.
handlerIAgentStreamHandlerThe stream handler to receive tokens.
optionsAgentExecutionOptionsOptional execution options.
cancellationTokenCancellationTokenCancellation 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
agentAgentThe agent to execute.
inputstringThe input prompt.
onTokenAction<AgentStreamToken>Callback for each token.
optionsAgentExecutionOptionsOptional execution options.
cancellationTokenCancellationTokenCancellation 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
agentAgentThe agent to execute.
inputstringThe input prompt.
onContentAction<string>Callback for content text (not thinking or tool calls).
optionsAgentExecutionOptionsOptional execution options.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<AgentExecutionResult>
The final execution result.
Examples
var result = await agent.RunStreamingAsync("Hello",
text => Console.Write(text));