LLM Learning Hub

workspace/llm-course/home

Tool Calling Loop

The tool-calling loop is the iterative cycle of LLM → tool_call → execute → append result → LLM again, repeating until the model emits a final answer with no further tool calls.

What is Tool Calling Loop?

The tool-calling loop is the iterative cycle of LLM → tool_call → execute → append result → LLM again, repeating until the model emits a final answer with no further tool calls.

The tool-calling loop is the iterative cycle of LLM → tool_call → execute → append result → LLM again, repeating until the model emits a final answer with no further tool calls.

Where is it used?

LangChain `AgentExecutor` and the OpenAI Assistants `run` API run this loop; multi-step agents like AutoGPT and Claude's computer use rely on many loop iterations.

How to build it

Write a `while True:` loop: call the LLM, if `message.tool_calls` execute each and append results, else `break` and return `message.content`; cap iterations to avoid infinite loops.