Support conditional approval from inside AIFunction (trigger approval flow at runtime)
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 894
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 23
Description
## Feature request: Support conditional approval inside AIFunction
**Problem:**
Currently, using `ApprovalRequiredAIFunction` in `Microsoft.Extensions.AI` requires approval every time the function is called, because approval is checked *before* the function is executed. This does not allow for approval checks that need to be determined by logic *inside* the function (e.g., only require approval for sensitive arguments).
**Proposal:**
Add official support for conditional approval, where the function implementation itself can determine (at runtime, based on input) whether approval is required, and trigger the approval flow only in those cases.
**Motivation:**
- Enables more flexible, real-world use cases (e.g. operations on sensitive data, approval for write operation based params etc)
- Reduces friction and avoids unnecessary approvals for low-risk operations
- Better aligns with user expectations for how function invocation and approval UX should work
**Suggested approaches:**
- Add an API or return type that allows the function to indicate approval is required *after* inspecting the input, pausing execution until user approval is obtained.
- Alternatively, allow returning a special result to trigger the approval flow from inside the function and pass the approval result as the param if approved for the same funcation call with same params as before
**Nice to have**
- Allowing users to edit the param before approving
Contributor guide
Assessment
This issue has not been assessed yet.