# Build a Reliable Tool-Calling Agent Loop on OpenRouter

DevFeed: [Build a Reliable Tool-Calling Agent Loop on OpenRouter](<https://devfeed.tech/articles/build-a-reliable-tool-calling-agent-loop-on-openrouter-78636.md>)

Original publisher: [Read original article](<https://openrouter.ai/blog/tutorials/build-tool-calling-agent-loop/>)

Author: OpenRouter

Published: 2026-09-17T00:00:00Z

Content type: tutorial

Language: en

Sources: [OpenRouter](<https://devfeed.tech/sources/openrouter.md>)

Topics: [AI Agent](<https://devfeed.tech/topics/ai-agent.md>), [Multi-step AI processes](<https://devfeed.tech/topics/multi-step-ai-processes.md>), [ReAct agent Python](<https://devfeed.tech/topics/react-agent-python.md>)

Tags: [agent](<https://devfeed.tech/tags/agent.md>), [openrouter](<https://devfeed.tech/tags/openrouter.md>), [tool-calling](<https://devfeed.tech/tags/tool-calling.md>), [typescript](<https://devfeed.tech/tags/typescript.md>)

## AI overview

This tutorial builds a TypeScript tool-calling agent loop with the OpenRouter SDK. It covers tool execution, matching results to call IDs, iteration caps, repeated-call detection, model fallback, concurrency choices, and limiting conversation history.

## Source excerpt

A tool-calling agent loop sends the conversation and tool definitions to a model, runs the tool calls the model returns, appends the results, and repeats until the model answers or a stop condition fires. This guide builds that loop in TypeScript with the OpenRouter SDK, then adds an iteration cap, repeated-call detection, model fallback, and history controls.