Agent SDK
Agent loops — multi-turn tool use with state — run on the standard chat-completions endpoint today. A first-party agent SDK with managed loops and tool execution is on the roadmap.
TypeScript
// Minimal agent loop with plain chat completions — no framework needed.
// Tools are defined per the tool-calling guide; loop until no tool_calls.
while (true) {
const resp = await client.chat.completions.create({
model: "anthropic/claude-sonnet-5",
messages,
tools,
});
const msg = resp.choices[0].message;
messages.push(msg);
if (!msg.tool_calls?.length) break;
for (const call of msg.tool_calls) {
const result = await runTool(call.function.name, call.function.arguments);
messages.push({ role: "tool", tool_call_id: call.id, content: result });
}
}The loop above is the whole pattern: call, execute tools, feed results back, repeat until the model stops calling tools. Frameworks like Mastra or Pydantic AI wrap the same mechanics — see the framework guides.