Skip to main content

extract_tool_calls

Function extract_tool_calls 

Source
pub fn extract_tool_calls(
    message: &Message,
    _native_function_calling: bool,
) -> Vec<ToolCall>
Expand description

Extract tool calls from a returned assistant message.

Behaviour:

  • If message.tool_calls is present and non-empty, return those directly (the native path).
  • Otherwise, parse message.content text for XML/JSON-formatted tool calls. This is the fallback path and runs even when native_function_calling is true — some backends populate text despite the request flag.
  • The fallback also runs when native_function_calling is false (the prompt-based path).

In all cases the returned ToolCall values are normalized OpenAI-style objects (id/type/function) so downstream code never needs to distinguish.