Repository navigation
Python: Add opt-in FunctionInvocationContext injection for skill scripts - #8749
Conversation
Inline skill scripts and file-based script runners can now declare a FunctionInvocationContext parameter to receive the enclosing tool invocation context. Scripts without such a parameter keep their existing behavior. Update samples and docs accordingly. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Context detection incorrectly treats ordinary generic annotations containing FunctionInvocationContext as injectable parameters.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds opt-in FunctionInvocationContext injection for skill scripts while preserving legacy execution behavior.
Changes:
- Adds context-aware inline and file script execution.
- Updates samples and documentation.
- Adds extensive sync, async, streaming, approval, and compatibility tests.
| File | Description |
|---|---|
python/packages/core/agent_framework/_skills.py |
Implements context detection and injection. |
python/packages/core/tests/core/test_skills.py |
Adds comprehensive regression coverage. |
python/packages/core/AGENTS.md |
Documents context-aware scripts and runners. |
python/samples/02-agents/skills/README.md |
Documents runtime context usage. |
python/samples/02-agents/skills/code_defined_skill/README.md |
Explains context in code-defined skills. |
python/samples/02-agents/skills/code_defined_skill/code_defined_skill.py |
Demonstrates inline context injection. |
python/samples/02-agents/skills/class_based_skill/README.md |
Explains context in class-based skills. |
python/samples/02-agents/skills/class_based_skill/class_based_skill.py |
Demonstrates method context injection. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 482299dfa131
Model: gpt-5.6-sol-fast
Overview
This PR adds opt-in context injection for inline skill callbacks and file runners while preserving legacy run overrides, path revalidation, and approval behavior. Tests cover supported annotation forms, callable runner variants, context isolation, and reserved-argument rejection. However, all-or-nothing annotation resolution leaves an uncovered postponed-annotation case that silently treats a declared context parameter as model input, violating the intended trust boundary.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/core/agent_framework/_skills.py
…nto sergeymenshykh-skill-collision-handling # Conflicts: # python/packages/core/agent_framework/_skills.py
There was a problem hiding this comment.
MAF Automated Review — Iteration 2
Result: No findings
Scope: 19 net-new commit(s): 30b9b8e06766, 622737258c73, 7fb41d673c97, 4f4e72284c9c, 2055e666e1ac, 62337887116c, b20927b921d4, 2191c60c5e7d, 717557a3791a, 91fd47035684, f83a892f9f0e, 0843a9c0537b, e2c6df28daa9, 72272613d0c0, 5ee3e87d6768, 8ff549d3f721, 024dd9908bc1, 2c46deb91e70, 19797cba63be
Model: gpt-5.6-sol-fast
Overview
The PR adds opt-in invocation-context injection while preserving legacy script and runner dispatch. Registration-time validation, reserved-argument checks, approval ordering, path validation, and broad sync/async and concurrency coverage constrain the changed behavior. No new Critical, High, or Medium defect survived reconciliation against the implementation, tests, current incremental diff, and existing feedback.
Reviewed the supplied incremental change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Only treat FunctionInvocationContext itself, optionally combined with None, as the context parameter. Container, callable, and Annotated annotations are no longer recognized. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Remove run_with_context and let SkillsProvider pass the FunctionInvocationContext to run() implementations that declare an annotated parameter. Unannotated overrides keep receiving host values as keyword arguments. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Avoid incompatible override diagnostics in zuban while retaining coverage for forwarding invocation context through run(). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Motivation & Context
Tools can declare a
FunctionInvocationContextparameter to access the current invocation. This PR brings the same opt-in pattern to skill scripts.Description & Review Guide
SkillsProviderpasses the invocation throughSkillScript.run(...). A customrun()opts in by declaring a parameter annotated withFunctionInvocationContext;run()implementations without that annotation keep receiving host values as keyword arguments.FunctionInvocationContextparameter. The framework injects it, and it is hidden from the script schema. Runners must give it a default value.InlineSkillScript.runandFileSkillScript.rungain an optional keyword-onlycontextparameter; explicit application values passed ascontextare still forwarded unchanged.run()overrides without a context parameter behave as before.run(), callbacks, and runners.Related Issue
N/A
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.