Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Googleapis Python genai Manual Function Execution

From Leeroopedia
Knowledge Sources
Domains Function_Calling, Tool_Use
Last Updated 2026-02-15 00:00 GMT

Overview

A pattern for explicitly handling function call requests from a language model, executing them in application code, and returning results for continued generation.

Description

Manual Function Execution gives the application full control over the function calling loop. When the model generates function call requests (instead of text), the application extracts the function name and arguments, executes the function with custom logic (validation, error handling, user confirmation), constructs a function response part, and sends it back to the model for continued generation. This pattern is essential for scenarios requiring human-in-the-loop confirmation, async execution, custom error handling, or result transformation before feeding back to the model.

Usage

Use manual function execution when automatic function calling is insufficient: when functions have side effects requiring user confirmation, when function execution is asynchronous, when results need transformation or filtering before model consumption, or when custom error handling is required. Disable AFC and process response.function_calls directly.

Theoretical Basis

Manual function execution implements an explicit Agent Loop:

# Manual function execution loop (pseudo-code)
contents = [user_query]
while True:
    response = model.generate(contents, tools, afc_disabled=True)
    if response.function_calls:
        for call in response.function_calls:
            # Application controls execution
            if user_confirms(call):
                result = execute(call.name, call.args)
            else:
                result = {"error": "User declined"}
            contents.append(model_turn_with_function_call)
            contents.append(function_response(call.name, result))
    else:
        return response.text

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment