Skip to main content
The genai_has_tool_calls function checks whether a GenAI messages array contains any tool calls or function calls. It returns a boolean value indicating if the AI model requested to use external tools or functions during the conversation. You can use this function to filter conversations that use function calling, monitor tool usage patterns, identify integration opportunities, or track feature adoption of function calling capabilities.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, you would check if tool-related fields exist in the messages.
| eval has_tools=if(isnotnull(tool_calls), "true", "false")
In ANSI SQL, you would check for existence of tool calls in the messages array.
SELECT 
  conversation_id,
  EXISTS(
    SELECT 1 FROM UNNEST(messages) 
    WHERE JSON_EXTRACT(content, '$.tool_calls') IS NOT NULL
  ) as has_tools
FROM conversations

Usage

Syntax

genai_has_tool_calls(messages)

Parameters

  • messages (dynamic, required): An array of message objects from a GenAI conversation. Each message typically contains role and content fields.

Returns

Returns a boolean value: true if the messages contain tool calls, false otherwise.

Use case examples

  • Log analysis
  • OpenTelemetry traces
  • Security logs
Analyze the adoption rate of function calling features in your AI application.Query
['sample-http-logs']
| where uri contains '/api/chat'
| extend uses_tools = genai_has_tool_calls(todynamic(response_body)['messages'])
| summarize 
    conversations_with_tools = countif(uses_tools),
    total_conversations = count(),
    adoption_rate = round(100.0 * countif(uses_tools) / count(), 2)
by bin(_time, 1d)
Run in PlaygroundOutput
_timeconversations_with_toolstotal_conversationsadoption_rate
2024-01-15345145023.79
2024-01-16389152325.54
This query tracks function calling adoption over time, helping you understand feature usage trends.