Tech & AI News
Hacker News

How AI tool calling works (40 lines of vanilla JavaScript)

The article explains how to turn a chat model into an agent using a simple four-step loop in vanilla JavaScript. A user prompt triggers the model; if it emits a tool-use block, the program parses the JSON arguments, calls a defined function (e.g., getWeather), and feeds the result back as a user message. The loop continues until the model’s reply no longer requests a tool, at which point the final text is printed.