runAgentLoop function

Future<List<Message>> runAgentLoop({
  1. required List<Message> prompts,
  2. required Context context,
  3. required AgentLoopConfig config,
  4. required StreamFunction streamFunction,
  5. required ToolExecutor toolExecutor,
  6. required AgentEventSink emit,
  7. CancelToken? cancelToken,
})

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,
}) {
  return _runAgentLoop(
    prompts: prompts,
    context: context,
    config: config,
    emit: emit,
    streamFunction: streamFunction,
    toolExecutor: toolExecutor,
    cancelToken: cancelToken,
  );
}