Automatic AI JavaScript Tool Function Calling

AI tool function calling (often just called “tool use”) is a feature where an AI model can invoke external functions or APIs during a conversation to get real data or perform actions—rather than just generating text.

The core idea

Instead of guessing or fabricating answers, the model can:

  1. Recognize when a tool is needed (e.g., “What’s the weather?” → needs a weather API)
  2. Output a structured function call (JSON with function name + arguments)
  3. Let your application execute the function
  4. Receive the result and continue the response

Automatic JavaScript Tool Functions

  • Application provides JavaScript functions that run within the Chilkat.Js embedded JavaScript engine.
  • The tool registry and permissions are provided in the JavaScript.
  • Chilkat internally handles tool calls by finding the matching JavaScript function(s), calling them, and sending results back to the AI model.
  • The JavaScript code has full access to Chilkat classes, but only with application allowed permissions.

Simple example flow

Application:

Call Chilkat's Ask function to ask "What’s my horoscope? I’m an Aquarius."

Model decides:

I should call get_horoscope(sign="Aquarius")

Chilkat:

  • (witin the Ask function) finds your get_horoscope JavaScript function and calls it.
  • Sends the tool call result back to the AI.

Model:

Uses that result to produce the final answer

Chilkat:

Ask returns the final answer


Key points

  • The model does NOT execute code itself → Chilkat finds and runs your JavaScript function(s).
  • The model chooses when and how to call tools
  • Inputs/outputs are structured (usually JSON)