Most LLM wrapper libraries do three things: send a request, get a response, done. But a true Agent goes further β it decides whether to call tools, executes them, feeds the results back to the LLM, and loops until it arrives at a final answer. This loop is the Agent Loop .
This article analyzes the Open Agent SDK (Swift) Agent Loop implementation β how it uses native Swift concurrency to run the entire cycle in-process.
What Is the Agent Loop?
In one sentence: user sends a prompt β LLM returns a response β if the LLM wants to call tools, execute them β feed tool results back to the LLM β repeat until the LLM says "I'm done" .
Rendered as a flowchart:
flowchart TD A["User prompt"] --> B["Build messages + tools"] B --> C["Call LLM API"] C -->|end_turn / stop_sequence| D["Return result"] C -->|max_tokens| C2["Append 'please continue'"] C2 --> C C -->|tool_use| E["Extract tool_use blocks"] E --> F["Partition into read-only / mutation"] F --> G["Read-only tools: concurrent execution"] F --> H["Mutationβ¦