Skip to content

Function: loop()

@providerprotocol/agents


@providerprotocol/agents / execution / loop

loop(options): ExecutionStrategy

Defined in: src/execution/loop.ts:62

Creates a loop execution strategy for agent execution.

The loop strategy is the simplest execution pattern, equivalent to UPP’s native tool loop behavior. It follows this cycle:

  1. Send input to LLM
  2. If response has tool calls, execute tools and loop
  3. Continue until no tool calls or maxIterations reached
  4. Return final response as UPP Turn

This strategy is ideal for straightforward tool-use scenarios where the model naturally knows when to stop calling tools.

LoopOptions = {}

Configuration options for the loop strategy

ExecutionStrategy

An ExecutionStrategy instance implementing the loop pattern

import { createAgent, loop } from '@providerprotocol/agents';
// Basic usage with default settings (unlimited iterations)
const agent = createAgent({
llm: myLLM,
tools: [weatherTool, searchTool],
strategy: loop(),
});
// With iteration limit
const limitedAgent = createAgent({
llm: myLLM,
tools: [weatherTool],
strategy: loop({ maxIterations: 5 }),
});
// Execute
const result = await agent.generate('What is the weather in Tokyo?');
console.log(result.turn.response.text);
  • react for reasoning-enhanced execution
  • plan for structured multi-step execution