Function Calling
How a model asks your code to do something — the mechanism underneath every agent, and it's the model requesting, never executing.
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 theif. 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.
Sources & 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%.