Stop being the product.
Become the owner.
or
sign uplog in

How tool calling actually works under the hood Most agent…

How tool calling actually works under the hood

Most agent tutorials jump into heavy orchestration frameworks like LangChain, which hides what's actually happening over the wire.

Under the hood, tool calling is just a simple 4-step loop:

1. You hand the model your messages plus a JSON Schema description of your functions.
2. The model outputs structured JSON with a tool name and arguments instead of raw text.
3. Your JavaScript executes the function (`fetch`, DB query, local file read, etc.).
4. You append the result back into `messages` with `role: "user"` and matching `tool_use_id` and query the model again.

I wrote a doc showing the entire loop in \~40 lines of Node/JS, including the practicals that trip you up (why failing calls should still return a `tool_result` with `is_error: true`, handling parallel calls in a single user message, and how token costs compound over runs).

There's also an interactive, in-browser example where you can run the loop against a mock filesystem without needing to set up a local environment. Curious to hear how others are handling client-side tool execution and context in production.
#dev #js #technology #programming
earnings
4,000 mlx total
$0  total
engagement
4 views
0 reactions

0 comments