direct_function

Direct function wrapper utilities for LLM function calling.

This module provides utilities for wrapping “direct” functions that handle LLM function calls. Direct functions have their metadata automatically extracted from function signatures and docstrings, allowing them to be used without accompanying configurations (as FunctionSchemas or in provider-specific formats).

class pipecat.adapters.schemas.direct_function.DirectFunction(*args, **kwargs)[source]

Bases: Protocol

Protocol for a “direct” function that handles LLM function calls.

“Direct” functions’ metadata is automatically extracted from their function signature and docstrings, allowing them to be used without accompanying function configurations (as FunctionSchemas or in provider-specific formats).

class pipecat.adapters.schemas.direct_function.BaseDirectFunctionWrapper(function: Callable)[source]

Bases: object

Base class for a wrapper around a DirectFunction.

Provides functionality to:

  • extract metadata from the function signature and docstring

  • use that metadata to generate a corresponding FunctionSchema

__init__(function: Callable)[source]

Initialize the direct function wrapper.

Parameters:

function – The function to wrap and extract metadata from.

classmethod special_first_param_name() str[source]

Get the name of the special first function parameter.

The special first parameter is ignored by metadata extraction as it’s not relevant to the LLM (e.g., ‘params’ for FunctionCallParams).

Returns:

The name of the special first parameter.

classmethod validate_function(function: Callable) None[source]

Validate that the function meets direct function requirements.

Parameters:

function – The function to validate.

Raises:

Exception – If function doesn’t meet requirements (not async, missing parameters, incorrect first parameter name).

to_function_schema() FunctionSchema[source]

Convert the wrapped function to a FunctionSchema.

Returns:

A FunctionSchema instance with extracted metadata.

class pipecat.adapters.schemas.direct_function.DirectFunctionWrapper(function: Callable)[source]

Bases: BaseDirectFunctionWrapper

Wrapper around a DirectFunction for LLM function calling.

This class:

  • Extracts metadata from the function signature and docstring

  • Generates a corresponding FunctionSchema

  • Helps with function invocation

classmethod special_first_param_name() str[source]

Get the special first parameter name for direct functions.

Returns:

The string “params” which is expected as the first parameter.

async invoke(args: Mapping[str, Any], params: FunctionCallParams)[source]

Invoke the wrapped function with the provided arguments.

Parameters:
  • args – Arguments to pass to the function.

  • params – Function call parameters from the LLM service.

Returns:

The result of the function call.