API Reference
runAgent
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
| Parameter | Type | Description |
|---|---|---|
options | RunAgentOptions | The 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"