Python: Add SkillsSourceContext to SkillsSource.get_skills#6895
Open
giles17 wants to merge 3 commits into
Open
Python: Add SkillsSourceContext to SkillsSource.get_skills#6895giles17 wants to merge 3 commits into
giles17 wants to merge 3 commits into
Conversation
Thread an invocation context (agent + optional session) through the skill source pipeline so sources and decorators can make context-aware decisions. - Add frozen, experimental SkillsSourceContext(agent, session). - Change SkillsSource.get_skills and all sources/decorators to accept and forward the context. - Make FilteringSkillsSource predicate context-aware: (skill, context) -> bool. - Add optional cache_isolation_key_selector to CachingSkillsSource for per-key cache isolation (None keeps the shared-bucket behavior). - Build the context in SkillsProvider from before_run agent/session. - Update foundry_hosting toolbox source, exports, tests, and docs. Python port of .NET PR microsoft#6797. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Python skills “source pipeline” API to be invocation-context aware by introducing SkillsSourceContext (invoking agent + optional session) and threading it through SkillsSource.get_skills and all source/decorator implementations. This enables context-aware filtering and optional per-key cache isolation while preserving the default shared-cache behavior.
Changes:
- Add experimental, frozen
SkillsSourceContext(agent, session)and updateSkillsSource.get_skills(context)across all sources/decorators. - Extend
FilteringSkillsSourceto use a context-aware predicate:Callable[[Skill, SkillsSourceContext], bool]. - Rework
CachingSkillsSourceto support optional per-key cache isolation (default remains a single shared bucket), and update docs/tests/hosting integration accordingly.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/foundry_hosting/tests/test_toolbox.py | Updates toolbox source tests to pass SkillsSourceContext into get_skills. |
| python/packages/foundry_hosting/agent_framework_foundry_hosting/_toolbox.py | Updates hosted toolbox SkillsSource wrapper to accept/forward SkillsSourceContext. |
| python/packages/core/tests/core/test_skills.py | Updates core skills tests for new get_skills(context) API; adds context propagation + cache isolation tests. |
| python/packages/core/tests/core/test_mcp_skills.py | Updates MCP skills source tests to pass SkillsSourceContext. |
| python/packages/core/AGENTS.md | Documents the new context-aware get_skills contract, predicate signature, and cache isolation behavior. |
| python/packages/core/agent_framework/_skills.py | Implements SkillsSourceContext, updates all sources/decorators to accept/forward context, and adds per-key caching buckets/locks. |
| python/packages/core/agent_framework/init.py | Exports SkillsSourceContext from the public API. |
Address PR review: docstring examples referenced `context` without constructing it. Add a `SkillsSourceContext` construction line (with a placeholder agent) to each source example and a note that the provider normally supplies it. Use `source_context` in the FilteringSkillsSource example to avoid clashing with the predicate's `context` parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address CI failures from the SkillsSourceContext change: - Update the skill_filtering sample to the 2-arg predicate signature (skill, context); the old 1-arg lambda would fail at runtime. - Replace ad-hoc _StubAgent test stubs with the shared MockAgent / MockAgentSession from conftest so all type checkers (incl. ty) accept the SupportsAgentRun-typed agent. Add a small _NamedMockAgent subclass for tests needing distinct agent names, and drop now-unnecessary attr-defined ignores. - Use cast(SupportsAgentRun, ...) in foundry_hosting tests, which have no shared mock infrastructure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
SkillsSource.get_skillstook no arguments, so skill sources and decorators had no access to the invocation context. This prevented context-aware behavior such as filtering skills per agent or isolating the skills cache per agent/tenant.This adds a
SkillsSourceContext(the invoking agent plus optional session) that the skills provider builds and threads through the entire source pipeline, so sources, filters, and caching can make context-aware decisions.Python port of the .NET change in #6797.
Description & Review Guide
What are the major changes?
SkillsSourceContext(agent, session).SkillsSource.get_skillsand all sources/decorators (File,InMemory,Delegating,Deduplicating,Filtering,Caching,Aggregating,MCP) now accept and forward aSkillsSourceContext.FilteringSkillsSourcepredicate is now context-aware:Callable[[Skill, SkillsSourceContext], bool].CachingSkillsSourcegains an optionalcache_isolation_key_selectorfor per-key cache isolation; aNoneselector (the default) keeps the existing shared-cache behavior.SkillsProviderbuilds the context frombefore_run'sagent/sessionand passes it into the pipeline.SkillsSourceContextis exported from the public API;foundry_hosting's toolbox skill source, tests, and docs are updated accordingly.What is the impact of these changes?
@experimentalskills API only. Default behavior is unchanged: context-ignoring leaf sources and the default (unkeyed) cache behave exactly as before.What do you want reviewers to focus on?
CachingSkillsSourcerewrite from a single shared slot to per-key buckets with per-key locks (double-checked locking, retry-on-failure preserved), and that the default path stays equivalent to the previous single-bucket behavior.Related Issue
Fixes #6711
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.