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:Microsoft Agent framework Approval Request Presentation

From Leeroopedia
Property Value
Principle Name Approval Request Presentation
SDK Microsoft Agent Framework
Repository Microsoft Agent Framework
Source Reference python/packages/core/agent_framework/_types.py:L458-509 (Content class), python/packages/core/agent_framework/_types.py:L971-989 (from_function_approval_request)
Type Pattern Doc (user-defined interface, not a library API)
Domains Agent_Architecture, Safety, Human_in_the_Loop

Overview

Approval Request Presentation is a user-defined pattern in which an application extracts function call details from Content objects of type function_approval_request and displays them to the user for explicit approval before execution proceeds.

Description

When an agent determines that a tool call requires human approval (configured via FunctionInvocationConfiguration), the framework wraps the pending function call in a Content object with type="function_approval_request" and sets user_input_request=True. These approval request objects are surfaced through the AgentResponse.user_input_requests or AgentResponseUpdate.user_input_requests properties.

The application developer is responsible for:

  1. Detecting approval requests by iterating result.user_input_requests.
  2. Extracting the tool name and arguments from request.function_call.name and request.function_call.arguments.
  3. Presenting this information to the user through the application's UI.
  4. Collecting the user's approval or denial decision.
  5. Submitting the decision back to the framework via request.to_function_approval_response(approved=True/False).

This pattern implements a human-in-the-loop safety gate that prevents the LLM from autonomously executing sensitive or dangerous tool calls without explicit user consent.

Key Data Fields

Field Type Description
Content.id str Unique identifier for the approval request, used to correlate the response back to the correct pending call.
Content.function_call Content Mapping).
Content.user_input_request bool Always True for approval requests, signaling the framework to pause execution and wait for user input.
Content.type Literal["function_approval_request"] The content type discriminator for this variant.

Theoretical Basis

This pattern follows the Human-in-the-Loop (HITL) principle from AI safety and responsible AI design. By requiring explicit human approval before an AI agent invokes potentially impactful tools (file operations, API calls, database mutations, etc.), the system creates a controlled checkpoint that:

  • Prevents unintended actions: The user can inspect exactly what the agent wants to do before it happens.
  • Maintains user agency: The human retains ultimate decision-making authority over the agent's behavior.
  • Enables auditability: Each approval request and its outcome can be logged for compliance and debugging.

The pattern also aligns with the Strategy Pattern at the application layer: the framework provides the data contract (the Content approval request structure), but the rendering and approval workflow are left entirely to the application developer to implement according to their specific UI paradigm (CLI prompt, web dialog, mobile notification, etc.).

Usage

Detecting and Presenting Approval Requests

# After calling agent.run() or iterating agent.run(stream=True)
for request in result.user_input_requests:
    # Extract tool information from the nested function_call Content
    tool_name: str = request.function_call.name
    tool_args: str | Mapping = request.function_call.arguments
    request_id: str = request.id

    # Display to user (application-specific UI logic)
    print(f"Agent wants to call: {tool_name}")
    print(f"With arguments: {tool_args}")
    approved: bool = get_user_decision()  # Your UI logic

    # Submit the decision back to the framework
    response_content = request.to_function_approval_response(approved=approved)

CLI Approval Dialog Example

def present_approval_request(request: Content) -> Content:
    """Present an approval request to the user in a CLI context."""
    print("=" * 60)
    print("TOOL APPROVAL REQUIRED")
    print(f"  Tool:      {request.function_call.name}")
    print(f"  Arguments: {request.function_call.arguments}")
    print(f"  Request ID: {request.id}")
    print("=" * 60)

    while True:
        choice = input("Approve? [y/n]: ").strip().lower()
        if choice in ("y", "yes"):
            return request.to_function_approval_response(approved=True)
        elif choice in ("n", "no"):
            return request.to_function_approval_response(approved=False)
        print("Please enter 'y' or 'n'.")

Related Pages

Sources

Type Name URL
Repo Microsoft Agent Framework https://github.com/microsoft/agent-framework

Page Connections

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