Skip to content

feat(skills): lazily load L2 instructions and L3 resources from disk - #7615

Open
patil-prajwal wants to merge 1 commit into
google:mainfrom
patil-prajwal:feat/lazy-load-skills-from-dir
Open

patil-prajwal wants to merge 1 commit into
google:mainfrom
patil-prajwal:feat/lazy-load-skills-from-dir

Conversation

@patil-prajwal

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

2. Or, if no issue exists, describe the change:

Problem:
_load_skill_from_dir eagerly reads the full markdown body of SKILL.md (L2 instructions) and recursively reads the content of all files in references/, assets/, and scripts/ (L3 resources) into memory at startup. For agents loading dozens of skills or large references, this introduces unnecessary I/O and memory overhead when only L1 metadata (name, description) is needed for initial registration.

Solution:

  1. Parse only the YAML frontmatter of SKILL.md in chunks (_parse_skill_md_frontmatter) during discovery.
  2. Scan resource directory entries (_scan_dir) without reading file contents into memory.
  3. Defer reading L2 instructions and L3 resources until accessed, caching results in Skill / Resources on first access.
  4. Maintain 100% backward compatibility for both attribute access (skill.instructions, skill.resources.references) and lookup methods (get_reference, list_references, get_script, etc.).

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Summary:

  • Added test__load_skill_from_dir_defers_instructions_and_resources_until_accessed in tests/unittests/skills/test__utils.py verifying zero file reads occur at load time and reads only happen on access.
  • Passed scripts/compliance_checks.py, ruff check, and all skills unittests.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants