---
title: "What is an AI agent? The LLM tool loop explained | BroadRouter"
description: "An AI agent is an LLM that decides its own next steps and calls tools in a loop until a task is done. How the loop works, what it costs in tokens, and how to cap it."
url: https://broadrouter.com/glossary/agent/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# AI agent

Updated 2026-11-16

An AI agent is a system in which a language model directs its own steps toward a goal: it decides which tools to call, reads the results and repeats until it produces a final answer or hits a limit. A fixed script that calls a model at set points is usually called a workflow instead.

Also called: LLM agent, agentic AI, autonomous agent, agent loop, AI agents

An agent is a model in a loop: ask, act with a tool, read the result, decide again.

## How it works

Anthropic separates two designs. Workflows are “systems where LLMs and tools are orchestrated through predefined code paths.” Agents are systems where “LLMs dynamically direct their own processes and tool usage.”

The OpenAI Agents SDK documents the loop itself. The runner calls the model. If the reply is a final answer, the run ends. If it contains [tool calls](https://broadrouter.com/glossary/tool-calling/), the runner executes them, appends the results and calls the model again. A `max_turns` setting caps the loop and raises `MaxTurnsExceeded` when it is passed.

A worked example: a coding agent asked to fix a failing test might take four turns.

```text
Turn 1  model -> tool call: run_tests()
Turn 2  model -> tool call: read_file("src/dates.py")
Turn 3  model -> tool call: edit_file("src/dates.py", ...)
Turn 4  model -> final answer: "Fixed the timezone bug; tests pass."
```

Each turn is a separate API request. If the system prompt and tool definitions come to 5,000 tokens, they are sent 4 times: 20,000 input tokens before any history or tool output is counted.

Tools can be your own functions or come from [MCP](https://broadrouter.com/glossary/mcp/) servers, which let one agent plug into file systems, databases and SaaS APIs through a shared protocol.

## Why it matters

-   **Cost grows with turns.** Every turn is a new request that resends the conversation. The [agent token budget](https://broadrouter.com/blog/agent-token-budget/) post breaks down where those tokens go. Cached input lowers the bill for the repeated prefix.
-   **Context fills up.** Long runs push against the [context window](https://broadrouter.com/glossary/context-window/) and get worse before they hit it. See [context management for long-running agents](https://broadrouter.com/blog/long-running-agent-context-management/).
-   **Errors compound.** Anthropic notes that autonomy brings “higher costs, and the potential for compounding errors.” Add stopping conditions, [guardrails](https://broadrouter.com/glossary/guardrails/) and human approval for actions that change data or spend money.
-   **Parallelism.** Several agents mean several requests in flight. Your provider’s [concurrency](https://broadrouter.com/glossary/concurrency/) limit decides how many can run at once. [Multi-agent cost](https://broadrouter.com/blog/multi-agent-cost/) compares per-token and flat pricing for that case.

## On BroadNet Inference

Any agent framework that accepts an OpenAI-compatible base URL can call BroadNet; the [OpenAI Agents SDK guide](https://broadrouter.com/guides/openai-agents-sdk-custom-provider/) shows the setup. BroadNet’s docs list tool calling for GLM 5.3 and Qwen3.8 27B. BroadNet’s docs set a pay-as-you-go key at 30 requests per minute and 4 in flight.

The [flat-rate plans](https://broadrouter.com/glossary/flat-rate-llm-plan/) (Full Moon, Orbit, Meteor) cover DeepSeek V4.1 Flash with no token meter. One session runs one request at a time, the way a single agent works, so you buy one session per agent you run in parallel. BroadNet’s docs do not list tool calling for DeepSeek V4.1 Flash, so test your agent’s tool calls on it before you rely on a plan; documented tool calling means GLM 5.3 or Qwen3.8 27B on pay-as-you-go.

## Questions

### What is the difference between an agent and a workflow?

In a workflow, your code fixes the order of model and tool calls. In an agent, the model chooses the next step each turn. Anthropic's guide uses exactly this split.

### Why are agents expensive to run on per-token pricing?

Each turn resends the system prompt, tool definitions and the growing history as input tokens. A 50-turn task can bill the same prefix 50 times, which is why cached input and flat plans matter.

### How do I stop an agent from looping forever?

Set a maximum number of turns and a token or time budget. The OpenAI Agents SDK, for example, raises MaxTurnsExceeded when a run passes its max\_turns limit.

## See also

-   [Tool calling](https://broadrouter.com/glossary/tool-calling/) (term)
-   [MCP (Model Context Protocol)](https://broadrouter.com/glossary/mcp/) (term)
-   [Flat-rate LLM plan](https://broadrouter.com/glossary/flat-rate-llm-plan/) (term)
-   [Context window](https://broadrouter.com/glossary/context-window/) (term)
-   [Guardrails](https://broadrouter.com/glossary/guardrails/) (term)
-   [Concurrency](https://broadrouter.com/glossary/concurrency/) (term)
-   [ReAct (reason and act)](https://broadrouter.com/glossary/react-agent/) (term)
-   [Subagent](https://broadrouter.com/glossary/subagent/) (term)
-   [Multi-agent system](https://broadrouter.com/glossary/multi-agent-system/) (term)
-   [AI coding agent](https://broadrouter.com/glossary/coding-agent/) (term)
-   [Context engineering](https://broadrouter.com/glossary/context-engineering/) (term)
-   [Run the OpenAI Agents SDK on BroadNet Inference](https://broadrouter.com/guides/openai-agents-sdk-custom-provider/) (guide)
-   [Use Cline with BroadNet Inference (OpenAI Compatible provider)](https://broadrouter.com/guides/cline-openai-compatible/) (guide)
-   [Agent token budget: where an agent loop's tokens go](https://broadrouter.com/blog/agent-token-budget/) (article)
-   [What multi-agent setups really cost: per token vs flat sessions](https://broadrouter.com/blog/multi-agent-cost/) (article)
-   [Context management for long-running agents with a 1M window](https://broadrouter.com/blog/long-running-agent-context-management/) (article)
-   [How to run parallel coding agents on a flat-rate LLM API](https://broadrouter.com/blog/run-parallel-coding-agents-flat-rate/) (article)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=glossary-agent&utm_content=page-cta) ·

**Sources**

-   [Anthropic, Building effective agents (workflows vs agents)](https://www.anthropic.com/engineering/building-effective-agents)
-   [OpenAI Agents SDK, running agents (agent loop and max\_turns)](https://openai.github.io/openai-agents-python/running_agents/)
-   [BroadNet Inference API reference, limits](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=glossary-agent&utm_content=sources#limits)
