How does function calling / tool use work in modern LLMs?
mediumAnswer
- Developer declares a set of tool schemas (name, description, JSON-schema parameters).
- At inference, the model may decide to emit a special token followed by a JSON matching one of the schemas instead of a text reply.
- The runtime executes the tool, appends the result as a message, and re-invokes the model.
- Loop until the model emits a normal message.
- Foundation for agents, calculators, retrieval, code execution, and every non-trivial LLM app.
Check yourself — multiple choice
- The LLM runs functions itself
- Model outputs a JSON matching a schema → runtime executes → appends → re-invoke LLM in a loop
- Only regex
- Impossible in modern LLMs
Function calling: model emits JSON → runtime executes → loop until text response.
#prompting#agents#tools#function-calling
Practise LLMs & GenAI
214 interview questions in this topic.
Related questions
- Describe a basic ReAct / agent loop.
- How should you write tool descriptions for reliable agent tool selection?
- What does an ideal function-calling schema look like?
- What is prompt chaining and why prefer it over one big prompt?
- How do you scale to hundreds of tools without overwhelming the LLM?
- Do agents plan explicitly or should we let them just react?