Open Agent Loops
API Reference

runAgent

@open-agent-loops/core


function runAgent(options): Promise<RunResult>;

Defined in: primitives/loop.ts:283

Run the agentic loop for one session until it reaches a stopping point.

Parameters

ParameterTypeDescription
optionsRunAgentOptionsThe model, memory, prompt, and run configuration.

Returns

Promise<RunResult>

The full and newly-added messages plus the number of turns taken.

Remarks

One run: load history, append the prompt, then repeat [ stream assistant -> run tools ] until a stopping point. It stops when the model returns a turn with no tool calls (a final answer), when a tool sets terminate, when a stopWhen condition fires, or when the maxSteps safety cap is hit (prevents runaway loops).

Everything it touches is an interface (ModelClient, Memory, Tool, StopCondition), so the loop itself is provider-, storage-, and tool-agnostic.

Throws

The signal's reason (an AbortError) if the run is cancelled.

Example

const result = await runAgent({
  model: new OpenAICompatibleModel({ model: "deepseek-ai/DeepSeek-V3.1" }),
  memory: new SessionMemoryStore(),
  sessionId: "demo",
  prompt: "What is 2 + 2?",
});
console.log(result.messages.at(-1)?.content); // -> "4"

See

On this page