Function: loop()
@providerprotocol/agents / execution / loop
Function: loop()
Section titled “Function: 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:
- Send input to LLM
- If response has tool calls, execute tools and loop
- Continue until no tool calls or maxIterations reached
- 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.
Parameters
Section titled “Parameters”options
Section titled “options”LoopOptions = {}
Configuration options for the loop strategy
Returns
Section titled “Returns”An ExecutionStrategy instance implementing the loop pattern
Example
Section titled “Example”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 limitconst limitedAgent = createAgent({ llm: myLLM, tools: [weatherTool], strategy: loop({ maxIterations: 5 }),});
// Executeconst result = await agent.generate('What is the weather in Tokyo?');console.log(result.turn.response.text);