genai_extract_tool_calls

This page explains how to use the genai_extract_tool_calls function in APL.

The genai_extract_tool_calls function extracts tool call requests from GenAI messages. When an AI model decides to use external tools or functions, it generates tool call messages. This function retrieves those calls so you can analyze what tools are being invoked.

You can use this function to monitor tool usage patterns, debug function calling, track API integrations, or analyze which tools are most frequently requested by your AI applications.

Usage

Syntax

genai_extract_tool_calls(messages)

Parameters

NameTypeRequiredDescription
messagesdynamicYesAn array of message objects from a GenAI conversation. Each message typically contains role and content fields.

Returns

Returns a dynamic object containing the tool calls from the conversation, or null if no tool calls are found. Tool calls typically include function name, arguments, and call ID.

Example

Extract tool calls from a GenAI conversation to analyze which functions are being invoked.

Query

['otel-demo-genai']
| extend tool_calls = genai_extract_tool_calls(['attributes.gen_ai.input.messages'])
| where isnotnull(tool_calls)
| extend tool_name = tostring(tool_calls[0]['function']['name'])
| summarize call_count = count() by tool_name
| top 5 by call_count

Run in Playground

Output

tool_namecall_count
get_weather245
search_database189
send_email123

This query shows which tools are most frequently called, helping you understand integration usage patterns.

Other query languages