Python: [BREAKING] Extract caching from SkillsProvider into a CachingSkillsSource decorator#6847
Merged
Merged
Conversation
…illsSource decorator Adds a composable CachingSkillsSource(DelegatingSkillsSource) decorator that caches the inner source's skills list, and rewires SkillsProvider to wrap its resolved source in it by default (skipped when disable_caching=True). Removes the provider's baked-in caching (_cached_context field and _get_or_create_context). Mirrors .NET microsoft#6768. 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 refactors Python skills caching by moving it out of SkillsProvider and into a composable CachingSkillsSource decorator, aligning the Python skills-source pipeline with the decorator-based approach used elsewhere (and mirroring the related .NET work).
Changes:
- Added
CachingSkillsSource(aDelegatingSkillsSourcedecorator) that caches the inner source’s skills list and shares a single in-flight fetch across concurrent callers. - Updated
SkillsProviderto wrap its resolved source inCachingSkillsSourceby default (unlessdisable_caching=True) and to rebuild instructions/tools from (possibly cached) skills on each run. - Updated tests and documentation to reflect the new caching behavior and exported
CachingSkillsSourcefromagent_framework.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/core/tests/core/test_skills.py | Adds focused unit tests for CachingSkillsSource caching/retry/concurrency behavior and updates provider caching tests to reflect the new decorator-based approach. |
| python/packages/core/AGENTS.md | Documents the composable SkillsSource decorator pipeline and clarifies that caching now lives in the source pipeline (default-wrapped by SkillsProvider unless opted out). |
| python/packages/core/agent_framework/_skills.py | Implements CachingSkillsSource and removes provider-internal context caching in favor of source-pipeline caching. |
| python/packages/core/agent_framework/init.py | Exports CachingSkillsSource as part of the public package surface. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eavanvalkenburg
approved these changes
Jul 1, 2026
Contributor
|
LGTM. This PR also add cache isolation key selector https://github.com/microsoft/agent-framework/pull/6797/changes#diff-a80018eeb1587fa83185680bb40b0a428a32fb71d302eed0224f7ade8d3ebfeb for .NET cache source. Same needed to be done on python as well. Not necessary in this PR. |
SergeyMenshykh
approved these changes
Jul 1, 2026
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
SkillsProvidercurrently bakes caching into itself: the_cached_contextfield, the
_get_or_create_context()method, and adisable_cachingbranch inbefore_run. This mixes context construction with caching and prevents cachingfrom being a composable layer in the skills-source pipeline (alongside
Aggregating/Filtering/Deduplicating/DelegatingSkillsSource).This change extracts caching into a dedicated
CachingSkillsSourcedecorator socaching becomes a swappable pipeline layer rather than logic welded into the
provider. It mirrors the .NET work in #6768 to keep the two implementations
aligned, and is a prerequisite for #6711 (adding context to skill-source
retrieval).
Description & Review Guide
What are the major changes?
CachingSkillsSource(DelegatingSkillsSource)decorator (experimental,SKILLSfeature) that caches the inner source's skills list. It shares asingle in-flight fetch across concurrent callers (via an
asyncio.Lockwitha double-checked cache) and only stores the result on success, so a failed
fetch is not cached and the next call retries.
SkillsProvidernow wraps its resolved source in aCachingSkillsSourcebydefault and rebuilds instructions/tools from the (source-cached) skills each
run. The provider's internal cache (
_cached_context,_get_or_create_context) is removed;before_runis now branch-free.disable_caching=True(onSkillsProvider(...)andfrom_paths(...)) nowskips wrapping the source instead of toggling an internal flag — preserving
the existing public kwarg and its meaning. It is the Python equivalent of
.NET's builder
DisableCaching().CachingSkillsSourceis exported fromagent_framework.What is the impact of these changes?
CachingSkillsSourceexplicitlyin a pipeline, and
disable_caching=Trueopts out of the default wrap.instructions/tools, which are cheap, deterministic functions of the skills
and are rebuilt each run). The expensive discovery in
get_skills()is stillcached. This is a
[BREAKING — experimental]change to skills internals.What do you want reviewers to focus on?
CachingSkillsSource.get_skillsand thatthe default-wrap vs
disable_cachingbehavior faithfully mirrors .NET .NET: [BREAKING] Extract caching from AgentSkillsProvider into CachingAgentSkillsSource #6768.Related Issue
Fixes #6767
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.