QlearnAI

5 min

Tool calls and the loop: one more step, I promise

Learn how an agent asks for a tool, what happens to the result, and what makes it stop.

By the end of this lesson you can

  • Explain how an agent asks for a tool
  • Walk through one loop: think, act, look
  • Say what makes an agent stop

From earlier lessons

What makes something an agent, rather than a chatbot that just replies?

Pick one answer.

POV: you ask for Friday dinner. Behind the scenes, the model's reply isn't a sentence for you. It's closer to a filled-in form: tool "search_restaurants", area "downtown", party size 6. Nobody types that. So how does a text predictor know that form exists?

Take a guess

How does the model know which tools it can use?

No pressure. Guess now, and the lesson will show you if you were right.

The model only knows a tool by its name and description. Describe it badly and expect creative results Picture: Original two-panel meme.
Maya

so the model just goes on the internet

Sam

no. the app gives it a menu: each tool's name, what it does, and what inputs it needs

Maya

and it orders off the menu

Sam

yep. it writes a structured request: the tool name plus the inputs. that's a tool call. some people call it function calling

Maya

then the restaurant list just pops into its head

Sam

the app runs the tool and adds the result to the conversation. next time, the model reads it like any other text

Maya

so think, act, look, repeat

Sam

exactly. read what it has, ask for a tool, read the result, decide again 🔁

Every pass through the loop is another model call, so a long task takes more time and costs more Picture: Original "me at the start vs me later" split meme.

So when does it stop? Usually when the model decides it has enough and writes a final answer instead of another tool call. Apps add guardrails too: a maximum number of steps, a time limit or a spending cap. Some also pause and ask you before certain actions. Stop too early and the job is half done. Stop too late and it burns time and money.

Predict, then reveal

Plot twist time. Everyone assumes the agent remembers what the search found because it "saw" it. Where is that result actually kept?

For fresh facts like opening hours, a tool result usually beats what the model remembers from training Picture: Original two-panel reject/approve meme.

What is a tool call?

Pick one answer.

The agent has every fact it needs for your answer. What should happen next?

Pick one answer.

FlashcardsIndex cardsFlashcards ⚡

Card 1 of 5

Worth keeping

  1. The app tells the model which tools exist. The model knows them only by name and description.
  2. A tool call is a structured request. The app runs it and adds the result to the conversation.
  3. Each loop is another model call, so long tasks cost more time and money.
  4. An agent stops on a final answer, or when it hits a limit the app set.

One loop, a few steps, a tidy answer. Now give it a task with twenty steps. If each step is right most of the time, how often is the whole task right?