Skip to content

Python: [BREAKING] Make all SkillsProvider tools require approval by default#6754

Open
giles17 wants to merge 5 commits into
microsoft:mainfrom
giles17:skills-approval-default
Open

Python: [BREAKING] Make all SkillsProvider tools require approval by default#6754
giles17 wants to merge 5 commits into
microsoft:mainfrom
giles17:skills-approval-default

Conversation

@giles17

@giles17 giles17 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

Skill tools previously ran without any approval gate by default: only run_skill_script could be gated, and only when the caller opted in via require_script_approval=True. The content-reading tools (load_skill, read_skill_resource) were never gated. This is a port of the .NET change (#6729) that makes SkillsProvider secure-by-default, so an agent cannot load skill content or execute skill scripts from a (potentially untrusted) source without host approval, while still allowing unattended runs through explicit auto-approval rules.

This follows the existing Python FileAccessProvider approval pattern rather than copying the .NET API surface.

Description & Review Guide

  • What are the major changes?

    • All three tools exposed by SkillsProvider (load_skill, read_skill_resource, run_skill_script) are now registered with approval_mode="always_require" unconditionally.
    • Added two static auto-approval rules — SkillsProvider.read_only_tools_auto_approval_rule (approves load_skill + read_skill_resource) and SkillsProvider.all_tools_auto_approval_rule (approves all three) — for use with ToolApprovalMiddleware(auto_approval_rules=[...]). Both reject calls carrying a server_label so they stay scoped to this provider's local tools.
    • Added tool-name class constants LOAD_SKILL_TOOL_NAME, READ_SKILL_RESOURCE_TOOL_NAME, RUN_SKILL_SCRIPT_TOOL_NAME.
    • Removed the require_script_approval option from SkillsProvider.__init__ and SkillsProvider.from_paths.
    • Added a new skills_auto_approval sample; updated the script_approval sample to the approval-by-default model; updated skills sample READMEs and packages/core/AGENTS.md.
  • What is the impact of these changes?

    • Breaking: require_script_approval is gone. Existing code passing it must remove it; skill tools now require approval by default, and unattended runs must opt in via an auto-approval rule on ToolApprovalMiddleware.
  • What do you want reviewers to focus on?

    • Whether the auto-approval rule API (static methods + server_label guard, mirroring FileAccessProvider) is the right Python shape versus the .NET Func<> properties.

Related Issue

Fixes #6728

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

…default

All tools exposed by SkillsProvider (load_skill, read_skill_resource,
run_skill_script) now require approval by default. Previously only
run_skill_script could be gated, and only when require_script_approval=True.

- Register all three tools with approval_mode="always_require"
- Add read_only_tools_auto_approval_rule and all_tools_auto_approval_rule
  static rules plus tool-name constants (mirrors FileAccessProvider)
- Remove the require_script_approval option from __init__ and from_paths
- Add skills_auto_approval sample; update script_approval sample/docs

Closes microsoft#6728

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 26, 2026 00:52
@moonbox3 moonbox3 added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible labels Jun 26, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 5 | Confidence: 89% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by giles17's agents

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _skills.py10324096%295, 542, 1055, 1070, 1072–1073, 1433–1434, 1446–1447, 1678, 1707, 2261, 2711–2712, 2809, 2817, 2822, 2825, 2830, 2850, 2862, 2867, 2963, 2971, 2976, 2979, 2984, 3004, 3013, 3018, 3279–3280, 3629, 3856–3857, 3884–3885, 3892–3893
TOTAL42576508788% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8340 37 💤 0 ❌ 0 🔥 2m 9s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes Python SkillsProvider secure-by-default by requiring host approval for all skill tools (load_skill, read_skill_resource, run_skill_script), and adds opt-in auto-approval rules to support unattended scenarios (mirroring the existing FileAccessProvider approval pattern and the .NET change in #6729).

Changes:

  • Register all SkillsProvider tools with approval_mode="always_require" and remove the require_script_approval configuration option (breaking change).
  • Add SkillsProvider.read_only_tools_auto_approval_rule and SkillsProvider.all_tools_auto_approval_rule plus tool-name constants for rule authoring.
  • Add/update samples + docs to demonstrate the new approval-by-default model and auto-approval configuration.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
python/packages/core/agent_framework/_skills.py Makes all skill tools approval-required by default; adds auto-approval rules and tool-name constants.
python/packages/core/tests/core/test_skills.py Updates/extends tests to validate approval-by-default and the new rule/constant APIs.
python/packages/core/AGENTS.md Documents the new approval-by-default behavior and how to run unattended via ToolApprovalMiddleware.
python/samples/02-agents/skills/skills_auto_approval/skills_auto_approval.py New sample showing read-only auto-approval + manual approval for script execution.
python/samples/02-agents/skills/skills_auto_approval/README.md New sample documentation for configuring auto-approval rules for skill tools.
python/samples/02-agents/skills/script_approval/script_approval.py Updates the manual approval sample to reflect approval-by-default and removal of require_script_approval.
python/samples/02-agents/skills/script_approval/README.md Updates documentation to the new “skill tool approval” model and correct env var names.
python/samples/02-agents/skills/README.md Adds the new skills_auto_approval sample and updates descriptions accordingly.

Comment thread python/packages/core/agent_framework/_skills.py
Comment thread python/samples/02-agents/skills/skills_auto_approval/skills_auto_approval.py Outdated
- Collect a response for every approval request and send them in a single
  agent.run so the approval loop always makes progress (no infinite loop when
  a request lacks a function_call); reject non-function requests instead of
  skipping them. Applied to both the skills_auto_approval and script_approval
  samples.
- Extract ToolApprovalMiddleware into a local variable in skills_auto_approval
  for readability.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@giles17 giles17 marked this pull request as ready for review June 26, 2026 01:10

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 5 | Confidence: 92%

✓ Correctness

This PR cleanly implements the breaking change to make all SkillsProvider tools require approval by default. The implementation follows the established FileAccessProvider pattern faithfully: ClassVar frozensets are properly initialized, the _is_local_tool_call helper correctly guards against hosted-tool name collisions via additional_properties.get("server_label"), and the require_script_approval parameter is fully removed from all call sites. The auto-approval rules use short-circuit and correctly, the TYPE_CHECKING import with from __future__ import annotations is sound, and tests comprehensively validate the new behavior. No correctness issues found.

✓ Security Reliability

The PR correctly implements secure-by-default approval for all SkillsProvider tools. The implementation mirrors the existing FileAccessProvider pattern, tools are unconditionally registered with approval_mode='always_require', and the auto-approval rules properly guard against hosted-tool name collisions via server_label checks. The additional_properties attribute is always initialized as a dict so .get() calls are safe. The sample code handles edge cases (no function_call) properly, preventing infinite loops. No security or reliability issues found.

✓ Test Coverage

Test coverage for this PR is thorough and follows the same pattern as the existing FileAccessProvider tests. The auto-approval rules are tested as pure functions with positive cases, negative cases, and the server_label guard. The breaking removal of require_script_approval is properly reflected by removing all references and updating affected tests. The one minor gap is the absence of an integration test showing the rules work end-to-end when wired to ToolApprovalMiddleware with SkillsProvider, but this matches the project's existing pattern where FileAccessProvider similarly relies on generic middleware tests plus isolated rule tests.

✓ Failure Modes

The production code changes are clean and correct. The require_script_approval parameter is fully removed with no orphaned references. The auto-approval rules safely handle edge cases: additional_properties is always a dict (confirmed at _types.py:534-536), so _is_local_tool_call won't crash; None in frozenset(...) correctly returns False; and ClassVar frozenset initialization references already-defined class-level strings. The _create_tools method unconditionally sets approval_mode="always_require" on all three tools. No silent failure modes or lost errors were identified in the changed production code.

✗ Design Approach

I found one design-level issue: the secure-by-default change is implemented consistently inside SkillsProvider, but the PR does not carry that new approval contract through the other published skills samples that still use SkillsProvider without any approval handling. That leaves concrete sample code paths returning approval requests instead of the documented final answers.

Flagged Issues

  • The new approval_mode="always_require" default strands existing skills samples that construct a plain Agent(..., context_providers=[SkillsProvider(...)]) and immediately print await agent.run(...). Specifically, python/samples/02-agents/skills/code_defined_skill/code_defined_skill.py:147-158 and python/samples/02-agents/skills/file_based_skill/file_based_skill.py:68-79 do not install ToolApprovalMiddleware or run a manual approval loop. With the new defaults, those flows now surface function_approval_request content instead of the documented final answers. Please update the remaining skills samples to add approval handling.

Automated review by giles17's agents

Comment thread python/packages/core/agent_framework/_skills.py
@github-actions

Copy link
Copy Markdown
Contributor

Flagged issue

The new approval_mode="always_require" default strands existing skills samples that construct a plain Agent(..., context_providers=[SkillsProvider(...)]) and immediately print await agent.run(...). Specifically, python/samples/02-agents/skills/code_defined_skill/code_defined_skill.py:147-158 and python/samples/02-agents/skills/file_based_skill/file_based_skill.py:68-79 do not install ToolApprovalMiddleware or run a manual approval loop. With the new defaults, those flows now surface function_approval_request content instead of the documented final answers. Please update the remaining skills samples to add approval handling.


Source: automated DevFlow PR review

The secure-by-default change makes all SkillsProvider tools require approval,
which left the other skills samples emitting approval requests instead of the
documented answers. Add ToolApprovalMiddleware with the all-tools auto-approval
rule (and a session, which the middleware requires) so these samples run
unattended as before:

- code_defined_skill, file_based_skill, class_based_skill, mixed_skills,
  skill_filtering, mcp_based_skill
- providers/foundry/foundry_chat_client_with_toolbox_skills

The dedicated script_approval (manual) and skills_auto_approval (selective)
samples continue to demonstrate interactive approval handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread python/packages/core/agent_framework/_skills.py Outdated
Comment thread python/packages/core/agent_framework/_skills.py Outdated
giles17 and others added 2 commits June 26, 2026 10:42
Apply maintainer suggestions dropping "host" from the skill-approval
docstrings, and align the matching SkillsProvider docstring/AGENTS.md note for
consistency.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@giles17 giles17 enabled auto-merge June 26, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Make all AgentSkillsProvider tools require approval by default and add auto-approval rules

5 participants