Implement generative AI and agentic solutions 2.2 Build agents by using Foundry

A Python agent built with Microsoft Agent Framework has a refund_payment function tool.

Study guide skill: Build autonomous or semiautonomous workflows with safeguards and approval flow controls

Question B4-024

A Python agent built with Microsoft Agent Framework has a refund_payment function tool. Every call must be approved by a person before it runs. How should you implement this?

Select one answer.

  • A Decorate the function with @tool(approval_mode="always_require"); the framework prompts the end user for approval directly, so the caller doesn't need to handle it
  • B Decorate the function with @tool(approval_mode="always_require"); the same agent run pauses until the approval arrives and then continues
  • C Decorate the function with @tool(approval_mode="always_require"); when the run returns user_input_requests, collect the decision and send it back with to_function_approval_response in a new agent run ✓ Correct answer
  • D Decorate the function with @tool(approval_mode="never_require") and tell the agent in its instructions to ask for confirmation

Answer: C

Setting approval_mode to always_require makes the tool need human approval; the run then completes with a response that says what input is needed instead of a final answer. The caller gets the user's decision and passes it back with to_function_approval_response as part of a new run. The docs say never_require is only for sample brevity and that production should use always_require.

Deep dive

How it works

In Microsoft Agent Framework (Python), you mark a function tool as needing human approval with the @tool decorator: approval_mode="always_require".

What happens next is the part people get wrong. The agent doesn't pause inside the run:

  1. Instead of executing the function, the agent might respond with a request for approval. The run completes with a response that says what input is required from the user, instead of a final answer.
  2. The response carries user_input_requests. The caller (your app) is responsible for getting the decision from the user.
  3. You build the reply with to_function_approval_response on the user input request, and pass it back to the agent as part of a new agent run.

The samples loop on this: while the result still has user_input_requests, collect approvals, run again, and stop when none are left.

On never_require, the docs are explicit: samples use approval_mode="never_require" for brevity, and you should use "always_require" in production.

The other options, and when you'd use them

  • The framework prompts the user itself: The caller is responsible for getting the user's input and passing it back.
  • The same run pauses and continues: The run completes with the input request, and the approval goes back in a new agent run.
  • never_require plus instructions: Instructions don't enforce anything. never_require is for sample brevity, and production should use always_require.

Exam tip

always_require -> run returns user_input_requests -> caller collects the decision -> to_function_approval_response in a new run.

References

Last reviewed:

Ready to test yourself? The quiz asks this and every other AI-103 question, with instant feedback. Practice this in a quiz →

All Generative AI & agents questions · AI-103 study guide

Thanks for your feedback!