My App
Tool Call Lifecycle

onBeforeToolCall

The onBeforeToolCall event fires when the LLM requests a tool, but before Fragola actually executes the tool's handler function.

Usage

This event allows you to intercept the tool execution. It is heavily used in advanced patterns to:

  • Override or rewrite the arguments (params) provided by the LLM before they reach your handler.
  • Bypass the handler entirely by providing an injectResponse (useful for dynamic/remote tools).

Payload Details

agent.onBeforeToolCall(({ config, context }) => {
    // Check which tool is being called
    if (config.tool.name === "getWeather") {
        // You can rewrite the parameters the LLM provided
        if (config.params.city === "NYC") {
            config.params.city = "New York City";
        }
    }
    
    // Or completely bypass execution by providing a raw string response
    if (config.tool.name === "remoteTool") {
        config.injectResponse = JSON.stringify({ status: "handled externally" });
    }
    
    return config;
});

On this page