Skip to content

Commit 663a792

Browse files
authored
Support excluding files from common.ai Agent Skills discovery (#69924)
`AgentSkillsToolset` now accepts an optional `exclude_resources` list of glob patterns, forwarded to `pydantic-ai-skills`' `SkillsToolset`, to keep matched files out of a skill's discovered resources. It mirrors the existing `exclude_tools` escape hatch and is resolved per-run on the worker. pydantic-ai-skills 1.2.0 broadened resource discovery from a fixed seven-extension allowlist to every readable text file in a skill bundle, so `.sql`/`.toml`/`.jinja` assets are exposed with no extra config. That also widens what reaches the model, so `exclude_resources` is the trim knob for secrets or scratch files (e.g. `["*.env", "secrets/*"]`). It removes files from resource discovery only, not from `run_skill_script` filesystem access, so pair it with `exclude_tools={"run_skill_script"}` when files are genuinely sensitive. The `[skills]` floor moves to `pydantic-ai-skills>=1.2.0` (the version that adds the parameter). 1.2.0 was published inside the repo's 4-day exclude-newer window, so a temporary per-package `exclude-newer-package` override lets it resolve; remove it once the window advances past 2026-07-15.
1 parent 14560e4 commit 663a792

7 files changed

Lines changed: 137 additions & 104 deletions

File tree

‎providers/common/ai/docs/index.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Extra Dependencies
246246
``openai`` ``pydantic-ai-slim[openai]``
247247
``mcp`` ``pydantic-ai-slim[mcp]``
248248
``code-mode`` ``pydantic-ai-harness[codemode]>=0.3.0``
249-
``skills`` ``apache-airflow-providers-git>=0.4.0``, ``pydantic-ai-skills>=0.11.0``
249+
``skills`` ``apache-airflow-providers-git>=0.4.0``, ``pydantic-ai-skills>=1.2.0``
250250
``avro`` ``fastavro>=1.10.0; python_version < "3.14"``, ``fastavro>=1.12.1; python_version >= "3.14"``
251251
``parquet`` ``pyarrow>=18.0.0; python_version < '3.14'``, ``pyarrow>=22.0.0; python_version >= '3.14'``
252252
``sql`` ``apache-airflow-providers-common-sql``, ``sqlglot>=30.0.0``

‎providers/common/ai/docs/toolsets.rst‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,16 @@ Parameters
437437
:class:`~airflow.providers.common.ai.skills.GitSkills`.
438438
- ``exclude_tools``: Optional set of skill tool names to hide from the agent
439439
(e.g. ``{"run_skill_script"}`` to disable on-worker script execution).
440+
- ``exclude_resources``: Optional glob patterns to exclude from resource
441+
discovery, added on top of the built-in defaults (``__pycache__``, ``*.pyc``,
442+
``*.pyo``, ``.DS_Store``, ``.git``). A skill exposes every readable text file
443+
it contains as a resource; these patterns keep matched files out of the
444+
resource list and the ``read_skill_resource`` tool (e.g.
445+
``["*.env", "secrets/*"]``). Each pattern matches the full skill-relative path
446+
or any single path component. This hides files from resource discovery only --
447+
it does not stop a skill's ``run_skill_script`` from reading them off disk, so
448+
pair it with ``exclude_tools={"run_skill_script"}`` when the files are
449+
genuinely sensitive.
440450

441451
Using Agent Skills with other frameworks
442452
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

‎providers/common/ai/pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ dependencies = [
9292
# upstream in pydantic/pydantic-ai#5230; revisit this extra once that lands.
9393
"skills" = [
9494
"apache-airflow-providers-git>=0.4.0",
95-
"pydantic-ai-skills>=0.11.0",
95+
"pydantic-ai-skills>=1.2.0",
9696
]
9797
"avro" = [
9898
'fastavro>=1.10.0; python_version < "3.14"',
@@ -136,7 +136,7 @@ dev = [
136136
# Additional devel dependencies (do not remove this line and add extra development dependencies)
137137
"sqlglot>=30.0.0",
138138
"pydantic-ai-slim[mcp]",
139-
"pydantic-ai-skills>=0.11.0",
139+
"pydantic-ai-skills>=1.2.0",
140140
"apache-airflow-providers-common-sql[datafusion]",
141141
"langchain>=1.0.0",
142142
"llama-index-core>=0.13.0",

‎providers/common/ai/src/airflow/providers/common/ai/toolsets/skills.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ class AgentSkillsToolset(AbstractToolset):
5757
:param sources: Skill sources -- local directory paths and/or ``GitSkills``.
5858
:param exclude_tools: Optional set of skill tool names to hide from the agent
5959
(e.g. ``{"run_skill_script"}`` to disable on-worker script execution).
60+
:param exclude_resources: Optional glob patterns to exclude from resource
61+
discovery, added on top of the built-in defaults (``__pycache__``,
62+
``*.pyc``, ``*.pyo``, ``.DS_Store``, ``.git``). A skill exposes every
63+
readable text file it contains as a resource; these patterns keep matched
64+
files out of the resource list and the ``read_skill_resource`` tool
65+
(e.g. ``["*.env", "secrets/*"]``). Patterns match the full skill-relative
66+
path or any single path component. This hides files from resource
67+
discovery only -- it does not stop a skill's ``run_skill_script`` from
68+
reading them off disk, so pair it with ``exclude_tools={"run_skill_script"}``
69+
when the files are genuinely sensitive. Requires ``pydantic-ai-skills>=1.2.0``.
6070
6171
Requires the ``skills`` extra: ``pip install "apache-airflow-providers-common-ai[skills]"``.
6272
"""
@@ -66,9 +76,11 @@ def __init__(
6676
sources: list[SkillSource],
6777
*,
6878
exclude_tools: set[str] | None = None,
79+
exclude_resources: list[str] | None = None,
6980
) -> None:
7081
self._sources = list(sources)
7182
self._exclude_tools = exclude_tools
83+
self._exclude_resources = exclude_resources
7284
self._inner: Any = None
7385
self._cleanup: Callable[[], None] | None = None
7486

@@ -80,7 +92,11 @@ async def for_run(self, ctx: RunContext) -> AbstractToolset:
8092
# Per-run isolation: pydantic-ai shares one toolset instance across runs,
8193
# but we hold per-run clone/cleanup state on __aenter__/__aexit__. Hand
8294
# each run its own instance so concurrent runs never clobber each other.
83-
return AgentSkillsToolset(self._sources, exclude_tools=self._exclude_tools)
95+
return AgentSkillsToolset(
96+
self._sources,
97+
exclude_tools=self._exclude_tools,
98+
exclude_resources=self._exclude_resources,
99+
)
84100

85101
async def __aenter__(self) -> AgentSkillsToolset:
86102
# Resolve + clone at run time, on the worker -- not at DAG-parse time.
@@ -98,6 +114,8 @@ async def __aenter__(self) -> AgentSkillsToolset:
98114
kwargs: dict[str, Any] = {"directories": directories}
99115
if self._exclude_tools:
100116
kwargs["exclude_tools"] = self._exclude_tools
117+
if self._exclude_resources:
118+
kwargs["exclude_resources"] = self._exclude_resources
101119
self._inner = SkillsToolset(**kwargs)
102120
await self._inner.__aenter__()
103121
except BaseException:

‎providers/common/ai/tests/unit/common/ai/toolsets/test_skills.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,56 @@ def fake_skillstoolset(**kwargs):
107107
assert captured["exclude_tools"] == {"run_skill_script"}
108108
assert captured["directories"] == ["/x"]
109109

110+
def test_exclude_resources_passed_to_inner(self):
111+
captured: dict = {}
112+
113+
def fake_skillstoolset(**kwargs):
114+
captured.update(kwargs)
115+
return _FakeInner(**kwargs)
116+
117+
toolset = AgentSkillsToolset(sources=["/x"], exclude_resources=["*.env", "secrets/*"])
118+
with patch(
119+
"airflow.providers.common.ai.toolsets.skills._materialize_skills",
120+
autospec=True,
121+
return_value=(["/x"], lambda: None),
122+
):
123+
with patch("pydantic_ai_skills.SkillsToolset", fake_skillstoolset): # noqa: spec
124+
asyncio.run(_enter_exit(toolset))
125+
126+
assert captured["exclude_resources"] == ["*.env", "secrets/*"]
127+
128+
def test_no_optional_kwargs_when_unset(self):
129+
# Omit exclude_tools/exclude_resources entirely so an older pydantic-ai-skills
130+
# that lacks the kwarg still works when the feature is not used.
131+
captured: dict = {}
132+
133+
def fake_skillstoolset(**kwargs):
134+
captured.update(kwargs)
135+
return _FakeInner(**kwargs)
136+
137+
toolset = AgentSkillsToolset(sources=["/x"])
138+
with patch(
139+
"airflow.providers.common.ai.toolsets.skills._materialize_skills",
140+
autospec=True,
141+
return_value=(["/x"], lambda: None),
142+
):
143+
with patch("pydantic_ai_skills.SkillsToolset", fake_skillstoolset): # noqa: spec
144+
asyncio.run(_enter_exit(toolset))
145+
146+
assert "exclude_tools" not in captured
147+
assert "exclude_resources" not in captured
148+
149+
def test_for_run_propagates_optional_kwargs(self):
150+
# for_run hands each run its own instance; dropping a kwarg here would
151+
# silently expose excluded files in concurrent runs.
152+
toolset = AgentSkillsToolset(
153+
sources=["/x"], exclude_tools={"run_skill_script"}, exclude_resources=["*.env"]
154+
)
155+
per_run = asyncio.run(toolset.for_run(MagicMock())) # noqa: spec (for_run ignores ctx)
156+
assert per_run is not toolset
157+
assert per_run._exclude_tools == {"run_skill_script"}
158+
assert per_run._exclude_resources == ["*.env"]
159+
110160

111161
class TestCleanup:
112162
def test_cleanup_runs_if_inner_construction_fails(self):

‎pyproject.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,12 @@ apache-airflow-task-sdk-integration-tests = false
15601560

15611561
# Manual overrides (kept outside the auto-generated block above so the
15621562
# update_airflow_pyproject_toml.py script doesn't clobber them).
1563+
# Temporary: pydantic-ai-skills 1.2.0 (adds exclude_resources, required by the
1564+
# apache-airflow-providers-common-ai[skills] floor) was published 2026-07-15,
1565+
# inside the "4 days" exclude-newer window. This pins the per-package cutoff just
1566+
# past that release so 1.2.0 resolves while any later release stays quarantined.
1567+
# Remove once the rolling window advances past 2026-07-15.
1568+
pydantic-ai-skills = "2026-07-16T00:00:00Z"
15631569

15641570
[tool.uv.pip]
15651571
# Synchroonize with scripts/ci/prek/upgrade_important_versions.py
@@ -1706,6 +1712,8 @@ apache-airflow-task-sdk-integration-tests = false
17061712

17071713
# Manual overrides — see the matching block under
17081714
# `[tool.uv.exclude-newer-package]` above for rationale.
1715+
# Temporary: see the pydantic-ai-skills note in `[tool.uv.exclude-newer-package]`.
1716+
pydantic-ai-skills = "2026-07-16T00:00:00Z"
17091717

17101718
[tool.uv.sources]
17111719
# These names must match the names as defined in the pyproject.toml of the workspace items,

0 commit comments

Comments
 (0)