runAgentLoop function
Future<List<Message> >
runAgentLoop({
- required List<
Message> prompts, - required Context context,
- required AgentLoopConfig config,
- required StreamFunction streamFunction,
- required ToolExecutor toolExecutor,
- required AgentEventSink emit,
- CancelToken? cancelToken,
- CancelTokenSource? cancelTokenSource,
Starts an agent loop with new prompt messages, delivering events to
emit and resolving with the messages produced by the run.
This is the emit-based core beneath agentLoop (pi's runAgentLoop);
use it when events must be awaited as part of the run (the stateful
Agent does this for its listeners). Unlike agentLoop, exceptions
from emit or a TransformContextHook propagate to the caller instead
of being swallowed into a closed stream.
Implementation
Future<List<Message>> runAgentLoop({
required List<Message> prompts,
required Context context,
required AgentLoopConfig config,
required StreamFunction streamFunction,
required ToolExecutor toolExecutor,
required AgentEventSink emit,
CancelToken? cancelToken,
/// The writable side of [cancelToken] (issue #1923 AC1): the provider-
/// phase steering interrupt cancels the run through it and re-arms the
/// latch before the resubmit. Null keeps the interrupt inert (the
/// pre-#1923 boundary-only steering semantics).
CancelTokenSource? cancelTokenSource,
}) {
return _runAgentLoop(
prompts: prompts,
context: context,
config: config,
emit: emit,
streamFunction: streamFunction,
toolExecutor: toolExecutor,
cancelToken: cancelToken,
cancelTokenSource: cancelTokenSource,
);
}