Home/AI Agents/Function Calling
AI Agents

Function Calling

How a model asks your code to do something — the mechanism underneath every agent, and it's the model requesting, never executing.

Reviewed July 11, 2026Stable
Reading level: Curious
Pick your depth ↓

When not to use it

  • When the model can answer from context. Adding a function for something already in the prompt is latency and a chance to be wrong.
  • For anything irreversible without confirmation. Refunds, deletions, sends. The model's confidence is not evidence.
  • When you have dozens of tools and no retrieval step. Selection accuracy is already gone; a bigger model won't restore it.
  • When a deterministic rule would do. If the logic is if status == X then Y, write the if. A model call to decide it is slower, costlier, and occasionally wrong.

Reach for something else instead

  • Structured output — when you need the model to return shaped data rather than trigger an action.
  • Retrieval — when the need is knowledge rather than action.
  • Deterministic code paths — for anything with clear rules. Most of what people build agents for.
  • Human confirmation steps — for irreversible actions, this is a design, not a fallback.

Further reading

  • Schick et al. (2023), Toolformer: Language Models Can Teach Themselves to Use Tools — models learning when to call, not just how.
  • Yao et al. (2022), ReAct: Synergizing Reasoning and Acting in Language Models — the interleaved reason-then-act loop underneath most agent designs.
  • Patil et al. (2023), Gorilla: Large Language Model Connected with Massive APIs — what happens to selection accuracy as the tool count grows.

Primary sources, listed so you can check the claims on this page rather than take them on trust.

Where people go wrong

  • Treating the model as the permission layer. It decides what to request; your code decides what to allow.
  • Writing function descriptions for humans. They're the selection prompt — vague descriptions produce wrong calls.
  • Exposing too many tools and blaming the model when selection degrades.
  • Passing raw tool errors back without sanitising them, opening an injection surface through the result channel.
  • Assuming per-step accuracy is end-to-end accuracy. 95% per step over five steps is 77%.

At a glance

FieldAI Agents
Who executesyour code, never the model
What the model doesrequests
Selection degrades pastroughly a dozen tools
Descriptions arethe prompt, not documentation
DifficultyIntermediate
Flashcards for this concept · study, save or share them →
Question
Answer
1 / 4

Often compared with

Function calling vs. structured output — one asks your code to do something, the other asks the model to return something shaped. Same underlying mechanism, different purpose.

Where this sits

26 concepts come first. Understanding it opens up 1 more.

13Levelsteps in
26Needs firstconcepts
1Opens up0% of 310
1Areastays here
Learn these firstTool Use
LEARN FIRST Tool Use Function Calling Structured Output UNLOCKS
Function Calling sits after Tool Use, and leads to 1 concept.

Computed from the prerequisite graph, not assigned. How this works