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.

Implementation:Microsoft Agent framework Content To Function Approval Response

From Leeroopedia
Knowledge Sources
Domains Agent_Architecture, Safety
Last Updated 2026-02-11 17:00 GMT

Overview

Converts a function_approval_request Content object into a function_approval_response Content object, embedding the user's approval or rejection decision so the agent can resume execution.

Description

The Content.to_function_approval_response() method is an instance method on the Content class that transforms an approval request into an approval response. When an agent pauses execution to request human approval for a tool call, the pending request is surfaced as a function_approval_request Content item. This method takes the user's boolean decision and produces a new function_approval_response Content that carries the same function call metadata (ID, function name, arguments, annotations, and raw representation) along with the approval verdict. The response is then sent back to the agent to either execute the approved tool call or skip the rejected one.

The method enforces a type guard: if called on a Content object whose type is not "function_approval_request", it raises a ContentError to prevent misuse.

Usage

Access this method on Content objects obtained from the user_input_requests property of an AgentResponse or AgentResponseUpdate. After presenting the approval request to the user and collecting their decision, call to_function_approval_response(approved=True) to approve or to_function_approval_response(approved=False) to reject the pending tool call. Wrap the resulting Content in a user Message and pass it to the agent's run() method to resume execution.

Code Reference

Source Location

  • Repository: agent-framework
  • File: python/packages/core/agent_framework/_types.py
  • Lines: L1013-1029

Signature

def to_function_approval_response(
    self,
    approved: bool,
) -> Content:

Import

# Access via Content objects from user_input_requests
from agent_framework import Agent, Message

result = await agent.run("some prompt")
for request in result.user_input_requests:
    approval = request.to_function_approval_response(approved=True)

I/O Contract

Inputs

Name Type Required Description
self Content Yes A Content object with type == "function_approval_request". Must originate from user_input_requests on an agent response. Raises ContentError if the content type is not "function_approval_request".
approved bool Yes The user's approval decision. True authorizes the agent to execute the pending tool call. False instructs the agent to reject and skip it.

Outputs

Name Type Description
result Content A new Content object with type == "function_approval_response". Carries the same id, function_call, annotations, additional_properties, and raw_representation as the original request, with the approved field set to the provided boolean value.

Errors

Exception Condition
ContentError Raised when called on a Content object whose type is not "function_approval_request". Message: "Can only convert 'function_approval_request' content to 'function_approval_response' content."

Internal Logic

The method performs the following steps:

  1. Type guard check: Verifies that self.type == "function_approval_request". If not, raises ContentError.
  2. Delegation to factory method: Calls Content.from_function_approval_response() with the following arguments forwarded from the original request:
    • approved -- the user's decision (from the method parameter)
    • id -- the unique identifier of the function call from the original request
    • function_call -- the function call descriptor (name, arguments) from the original request
    • annotations -- any annotations attached to the original request
    • additional_properties -- any extra properties from the original request
    • raw_representation -- the underlying raw representation from the original request
  3. Returns the newly constructed function_approval_response Content object.

Usage Examples

Basic Approval Flow

from agent_framework import Agent, Message

agent = Agent(client=client, model="gpt-4o", tools=[delete_records])
thread = agent.create_thread()

result = await agent.run("Delete all records", thread=thread)

for request in result.user_input_requests:
    user_decision = input(f"Approve {request.function_call.name}? (y/n): ")
    approval = request.to_function_approval_response(approved=(user_decision == "y"))
    result = await agent.run(
        Message("user", [approval]),
        thread=thread,
    )

Programmatic Rejection

# Automatically reject all pending tool calls
result = await agent.run("Drop the database", thread=thread)

for request in result.user_input_requests:
    rejection = request.to_function_approval_response(approved=False)
    result = await agent.run(
        Message("user", [rejection]),
        thread=thread,
    )

Selective Approval with Logging

import logging

logger = logging.getLogger(__name__)

ALLOWED_FUNCTIONS = {"get_weather", "search_documents"}

result = await agent.run("What is the weather and clean temp files?", thread=thread)

for request in result.user_input_requests:
    func_name = request.function_call.name
    is_approved = func_name in ALLOWED_FUNCTIONS
    logger.info(f"Function '{func_name}' approval: {is_approved}")
    approval = request.to_function_approval_response(approved=is_approved)
    result = await agent.run(
        Message("user", [approval]),
        thread=thread,
    )

Related Pages

Implements Principle

Page Connections

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