LearnThatStack Ace your next interview
AI Agents · question
Question 4 of 54

Describe the full round trip of one function call between your application and the model.

beginner
← All AI Agents questions
Re-explain

One function call takes two API calls, not one. The model never runs your code. It only asks you to run it, and you send the result back.

1. Your app sends the messages plus the tool schemas
2. Model replies with a tool_use block: name, input, and an id
   (stop_reason "tool_use" - no final text yet)
3. Your app runs the real function
4. Your app appends that assistant turn, then a user turn holding a
   tool_result block whose tool_use_id matches the same id
5. Resend the whole message list; the model reads the result and answers

Two details prove you have built this. The API is stateless and remembers nothing between calls, so step 5 resends every earlier turn, including the tool_use one. And the ids must pair exactly, or the request is rejected.

OpenAI names the same pieces tool_calls and role: "tool" with tool_call_id. The loop can repeat: the model may ask for another call before it stops.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for AI Agents One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • The model asks for two tools in the same turn. How do you send both results back? All tool_results go in one user message, each with its own tool_use_id. Splitting them across messages makes the model stop calling tools in parallel.
  • What goes back to the model when your function throws an error? A tool_result carrying the error text, flagged is_error on Anthropic, so the model can retry or change course instead of the loop crashing.
  • How do you know the loop is finished, and what stops it from running forever? Done when stop_reason is no longer tool_use. Add a max-iteration cap and a token or time budget, and decide what the user sees when it trips.
  • How do you force the model to call one specific tool, or stop it calling any? Names tool_choice and its modes: auto, require any tool, require one named tool, or none. Forcing one tool is a common way to get structured output.
  • Every round resends the full history. What does that do to cost, and how do you contain it? Input tokens grow every round. Cache the stable prefix with prompt caching, and trim or summarize old tool results before they pile up.

What you can say

  1. One function call is really two API calls, because the model never runs my code, it only asks me to run it and then reads the result.
  2. First I send the messages plus the tool schemas, and the model answers with a tool_use block holding the name, input and an id, with stop_reason tool_use and no final text.
  3. My app runs the real function, then appends the model's assistant turn and a user turn with a tool_result whose tool_use_id matches that same id.
  4. Then I resend the whole message list, because the API is stateless, and the model reads the result and writes its answer.
  5. The ids have to pair exactly or the request gets rejected, and on OpenAI the same pieces are tool_calls and a message with role tool and a tool_call_id.
  6. The catch is that it's a loop, not one hop, so the model may ask for another call, and every round resends the full history, which costs tokens.

Weak answers to avoid

  • Says the model executes the function The model only emits a request with a name and arguments, and your code runs it. Blur who runs what and it sounds like you have never built the loop.
  • Describes it as a single API call It takes two calls. Without the second request that carries the result back, the model never produces its answer.
  • Sends only the tool result on the second call The API is stateless, so the second request must carry every earlier turn, including the tool_use turn, or the tool_result id has nothing to pair with.
  • Assumes one tool call per answer After reading a result the model can ask for another call. Keep looping until stop_reason is no longer tool_use instead of hardcoding one round.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the AI Agents cheatsheet.

← Back to all AI Agents questions
Pro · $10/mo

47 of 54 AI Agents answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime