How AI tool calling works (40 lines of vanilla JavaScript)
Summary
This article is a practical guide to tool calling for chat models, showing how to turn a model into an agent by exposing tools and running a four-stage loop (messages, model decision, tool call, tool result). It includes runnable JavaScript and Python examples, discusses tool descriptions in JSON, and covers best practices, cost considerations, and when to use SDK runners versus hand-written loops.