Python: Support skill scripts execution#4558
Python: Support skill scripts execution#4558SergeyMenshykh wants to merge 5 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class support for executing skill scripts in the Python agent framework, covering both file-based scripts (delegated to a configurable executor) and code-defined scripts (registered via a decorator and executed in-process). This extends the existing SkillsProvider progressive-disclosure model to include script execution and introduces new samples demonstrating file skills, mixed skills, and human approval gating.
Changes:
- Core: add
SkillScript,@skill.script, script discovery, and anexecute_skill_scripttool with optional approval gating. - Public API: export new script-related types from
agent_framework.__init__. - Ecosystem: add/refresh samples for file skills, code-defined skills, mixed skills, and script approval; expand test coverage for script behavior.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/core/agent_framework/_skills.py | Adds script model/executor APIs, script discovery, prompt/tool wiring, and runtime execution path. |
| python/packages/core/agent_framework/init.py | Exports new public script-related types. |
| python/packages/core/tests/core/test_skills.py | Adds extensive tests for script discovery/execution, approval mode, and edge cases. |
| python/packages/core/AGENTS.md | Updates package layout docs to include the skills module. |
| python/samples/02-agents/skills/subprocess_script_runner.py | Adds a shared subprocess-based file-script runner callback for samples. |
| python/samples/02-agents/skills/README.md | Adds a top-level index README for the skills learning path and concepts. |
| python/samples/02-agents/skills/file_based_skill/file_based_skill.py | New file-based skill sample demonstrating script execution via callback executor. |
| python/samples/02-agents/skills/file_based_skill/README.md | Documentation for running and understanding the file-based skill sample. |
| python/samples/02-agents/skills/file_based_skill/skills/password-generator/SKILL.md | Adds a file-based skill definition that references a script. |
| python/samples/02-agents/skills/file_based_skill/skills/password-generator/references/PASSWORD_GUIDELINES.md | Adds reference guidelines for the password-generator file skill. |
| python/samples/02-agents/skills/file_based_skill/skills/password-generator/scripts/generate.py | Adds the executable password generator script used by the file-based sample. |
| python/samples/02-agents/skills/mixed_skills/mixed_skills.py | New mixed sample combining code-defined scripts/resources with a file-based scripted skill. |
| python/samples/02-agents/skills/mixed_skills/README.md | Documentation for the mixed skills sample and how it wires both skill types. |
| python/samples/02-agents/skills/mixed_skills/skills/password-generator/SKILL.md | Adds a file-based password-generator skill used by the mixed sample. |
| python/samples/02-agents/skills/mixed_skills/skills/password-generator/references/PASSWORD_GUIDELINES.md | Adds reference guidelines for the mixed-sample password-generator skill. |
| python/samples/02-agents/skills/mixed_skills/skills/password-generator/scripts/generate.py | Adds the password generator script used by the mixed sample. |
| python/samples/02-agents/skills/script_approval/script_approval.py | New sample showing how to require human approval before executing scripts. |
| python/samples/02-agents/skills/script_approval/README.md | Documentation for the script approval workflow sample. |
| python/samples/02-agents/skills/code_skill/code_skill.py | Removes/renames the older code skill sample in favor of the new code-defined-skill sample. |
| python/samples/02-agents/skills/code_skill/README.md | Removes the older code skill sample README. |
| python/samples/02-agents/skills/code_defined_skill/code_defined_skill.py | Adds the updated code-defined skill sample including @skill.script. |
| python/samples/02-agents/skills/code_defined_skill/README.md | Documentation for the code-defined skill sample. |
| python/samples/02-agents/skills/basic_skill/basic_skill.py | Removes the older “basic_skill” sample. |
| python/samples/02-agents/skills/basic_skill/README.md | Removes the older “basic_skill” README. |
| python/samples/02-agents/skills/basic_skill/skills/expense-report/SKILL.md | Removes the older expense-report file skill. |
| python/samples/02-agents/skills/basic_skill/skills/expense-report/references/POLICY_FAQ.md | Removes the older expense-report FAQ resource. |
| python/samples/02-agents/skills/basic_skill/skills/expense-report/assets/expense-report-template.md | Removes the older expense-report template asset. |
| ... | ||
|
|
||
|
|
||
| class CallbackSkillScriptExecutor(SkillScriptExecutor): |
There was a problem hiding this comment.
for me this is not what I think about with the term callback, I would say something like executor or runner would be more applicable, and we might be able to reuse some of the concept from the ShellTool, @dmytrostruk could you have a look as well?
| # region Script Executors | ||
|
|
||
|
|
||
| class SkillScriptExecutor(ABC): |
There was a problem hiding this comment.
how many custom subclasses of this do we realistically expects? in python we can always subclass the below concrete class so might not be necessary...
There was a problem hiding this comment.
I don't expect many executors to be shipped as part of the core package. For now, we'll definitely include CallbackSkillScriptExecutor (subject to renaming) because it's versatile. Later, we may add executors for various Azure offerings that run scripts in a sandboxed environment. Users may also want to create their own executors. I'm open to dropping the abstract base class; however, in that case, CallbackSkillScriptExecutor would need to accept an optional callback, allowing subclasses to override the execute method without providing one.
python/samples/02-agents/skills/file_based_skill/skills/password-generator/scripts/generate.py
Outdated
Show resolved
Hide resolved
python/samples/02-agents/skills/code_defined_skill/code_defined_skill.py
Outdated
Show resolved
Hide resolved
| self.function = function | ||
| self.path = path |
There was a problem hiding this comment.
Should it allow both file based and function based?
| # region Script Executors | ||
|
|
||
|
|
||
| class SkillScriptExecutor(ABC): |
There was a problem hiding this comment.
The name executor may be confused with the executor concept in workflows. Have we considered Runner or Dispatcher?
| # 2. Dynamic Resources — callable function via @skill.resource | ||
| # --------------------------------------------------------------------------- | ||
| @unit_converter_skill.resource(name="conversion-policy", description="Current conversion formatting and rounding policy") | ||
| def conversion_policy(**kwargs: Any) -> str: |
There was a problem hiding this comment.
Will kwargs get advertised to the agent? What happens if the agent overrides the runtime arguments?
Summary
Adds support for executing agent skill scripts — both file-based scripts (delegated to a
SkillScriptExecutor) and code-defined scripts (registered via the@skill.scriptdecorator and executed in-process).Changes
Core (
packages/core/agent_framework/_skills.py)SkillScriptmodel with optionalfunction(code-based) andpath(file-based) fieldsSkillScriptExecutorabstract base class for file-based script execution strategiesCallbackSkillScriptExecutorfor user-provided execution callbacksexecute_skill_scripttool with optional user-approval gate (require_script_approval)Skillmodel with mutablescriptslist@skill.scriptdecorator for registering code-defined scriptsExports (
__init__.py)SkillScript,SkillScriptExecutor,CallbackSkillScriptExecutorTests (
tests/core/test_skills.py)Samples
file_based_skill,code_defined_skill,mixed_skills,script_approval)subprocess_script_runner.pyutility for file-based script execution via subprocessDesign Decisions
SkillScriptExecutor— the framework does not assume a specific execution strategy (subprocess, sandbox, hosted interpreter, etc.)execute_skill_scripttool supports an optional approval gate for safetyCloses: #4349