Skip to content

Python: Forward runtime kwargs to skill resource functions#4417

Merged
SergeyMenshykh merged 13 commits intomicrosoft:mainfrom
SergeyMenshykh:support-kwargs-by-skill.resource
Mar 5, 2026
Merged

Python: Forward runtime kwargs to skill resource functions#4417
SergeyMenshykh merged 13 commits intomicrosoft:mainfrom
SergeyMenshykh:support-kwargs-by-skill.resource

Conversation

@SergeyMenshykh
Copy link
Member

@SergeyMenshykh SergeyMenshykh commented Mar 3, 2026

Note: This PR is based on #4387 and should be merged after it.

Summary

Enables @skill.resource decorated functions to receive runtime keyword arguments passed via agent.run(), matching the existing @tool kwargs pattern.

Problem

Currently, skill resource functions (decorated with @skill.resource) are always called with zero arguments. In contrast, regular @tool functions can receive runtime kwargs passed via agent.run(user_id="123") through **kwargs. This makes it impossible to inject request-scoped context (app version, auth tokens, correlation IDs) into skill resources.

Changes

Core (_skills.py)

  • Added **kwargs: Any to _read_skill_resource() method signature
  • Detects if resource functions accept **kwargs via inspect.signature (same pattern as FunctionTool)
  • Forwards kwargs to resource functions that accept them; functions without **kwargs are unaffected (backward compatible)

Tests (test_skills.py)

  • Sync resource function receiving kwargs
  • Async resource function receiving kwargs
  • Backward compatibility: resource function without **kwargs still works when extra args are passed

Sample (code_skill.py)

  • Updated project_info_skill's environment() resource to accept **kwargs and use app_version
  • Updated main() to pass app_version="2.4.1" via agent.run()
  • Added Pattern 3 documentation for dynamic resources with kwargs

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Copilot AI review requested due to automatic review settings March 3, 2026 12:33
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Mar 3, 2026
@github-actions github-actions bot changed the title Forward runtime kwargs to skill resource functions Python: Forward runtime kwargs to skill resource functions Mar 3, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Mar 3, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _skills.py289897%577, 616–617, 690, 695, 847–848, 1058
TOTAL22611279587% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4702 25 💤 0 ❌ 0 🔥 1m 16s ⏱️

@SergeyMenshykh SergeyMenshykh marked this pull request as draft March 3, 2026 12:37
@SergeyMenshykh SergeyMenshykh self-assigned this Mar 3, 2026
@SergeyMenshykh SergeyMenshykh moved this to In Progress in Agent Framework Mar 3, 2026
Copy link
Contributor

Copilot AI left a comment

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 significantly refactors the Agent Skills system by: (1) replacing FileAgentSkillsProvider with a unified SkillsProvider that supports both file-based and code-defined skills, (2) introducing Skill and SkillResource classes as public API, and (3) enabling @skill.resource-decorated functions to receive runtime kwargs passed via agent.run(), matching the existing @tool kwargs pattern.

Changes:

  • Core refactor of _skills.py: replaces FileAgentSkillsProvider/_FileAgentSkill with SkillsProvider/Skill/SkillResource classes; adds **kwargs forwarding to callable resource functions; changes resource discovery from markdown-link parsing to filesystem scanning
  • Comprehensive test rewrite in test_skills.py: updates all existing tests for the new API and adds new test cases for code-defined skills, kwargs forwarding, and edge cases
  • New code_skill sample and README demonstrating code-defined skills with dynamic resources and kwargs injection; updates basic_skill sample to use the renamed SkillsProvider

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/packages/core/agent_framework/_skills.py Full refactor: new Skill/SkillResource/SkillsProvider classes; kwargs forwarding in _read_skill_resource; filesystem-based resource discovery
python/packages/core/agent_framework/__init__.py Exports Skill, SkillResource, SkillsProvider; removes FileAgentSkillsProvider
python/packages/core/tests/core/test_skills.py Updated tests for new API + new tests for code-defined skills and kwargs
python/samples/02-agents/skills/code_skill/code_skill.py New sample demonstrating three skill patterns including kwargs-enabled resources
python/samples/02-agents/skills/code_skill/README.md Documentation for new code_skill sample
python/samples/02-agents/skills/basic_skill/basic_skill.py Updated to use renamed SkillsProvider
python/samples/02-agents/skills/basic_skill/README.md Updated references to SkillsProvider and corrected file/directory names

@SergeyMenshykh SergeyMenshykh marked this pull request as ready for review March 5, 2026 10:09
@SergeyMenshykh SergeyMenshykh moved this from In Progress to In Review in Agent Framework Mar 5, 2026
@SergeyMenshykh SergeyMenshykh enabled auto-merge March 5, 2026 16:04
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Mar 5, 2026
Merged via the queue into microsoft:main with commit 8bf4235 Mar 5, 2026
31 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Agent Framework Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants