adk-skill
AgentSkills parser, index, matcher, and runtime injection helpers for ADK-Rust.
Stability: Stable — follows semantic versioning, so breaking changes wait for the next major release. See STABILITY.md.
Overview
adk-skill is the engine for specification-driven agent skills, implementing the agentskills.io specification. It discovers, parses, indexes, and selects skills defined as Markdown with YAML frontmatter, and injects the selected instructions into an agent's context.
This crate is provider-agnostic and can be used through:
adk-agentwith itsskillsfeature (LlmAgentBuilder::with_skills,with_auto_skills,with_skills_from_root)adk-runnerwith itsskillsfeature (Runner::with_auto_skills)adk-cli(adk-rust skills list,validate,match, and, withvertex-skill-registry,searchandpull)- Direct API calls from custom runtimes
Installation
[]
= "3.0.0"
Or use the meta-crate, where the skills feature (included in standard) re-exports it and turns
on the skills features of adk-agent and adk-runner:
[]
= { = "3.0.0", = ["skills"] }
| Feature | Description |
|---|---|
progressive-disclosure |
SkillToolset: list_skills, load_skill, and load_skill_resource tools instead of injecting a body into every matching message |
vertex-skill-registry |
Read-only Vertex AI Skill Registry client (registry module) with verified, bounded archive extraction |
No feature is enabled by default.
Supported File Conventions
agentskills.io Skills (.skills/**/*.md, .claude/skills/**/*.md)
Each skill is a Markdown file with YAML frontmatter following the agentskills.io standard. This structure allows for both human-readable instructions and machine-readable governance.
name: zenith-voice-receptionist
description: Official voice persona for Mario's Plumbing Co. receptionist.
version: "1.1.0"
license: MIT
compatibility: Gemini Live (gemini-3.1-flash-live-preview)
allowed-tools:
- - - -
Specification Fields
| Field | Required | Description |
|---|---|---|
name |
Yes | Unique identifier (lowercase, numbers, hyphens). |
description |
Yes | Concise summary of the skill's purpose for agent selection. |
version |
No | Semantic version of the skill. |
license |
No | License identifier (e.g., MIT, Apache-2.0). |
compatibility |
No | Environment or model constraints. |
tags |
No | List of discovery and filtering labels. |
allowed-tools |
No | Tools the agent is permitted to use for this skill: a list, or one string of names separated by spaces or commas (allowed-tools: Read Grep). |
references |
No | Supporting resources (JSON, CSV) the skill uses. |
trigger |
No | Marks a skill meant to be invoked explicitly by name; exposed as SkillDocument::trigger. select_skills and the injector do not act on it. |
hint |
No | UI guidance for user input. |
metadata |
No | Arbitrary key-value map for extensions. |
triggers |
No | File glob patterns for activation, such as ["*.rs", "Cargo.toml"]; exposed as SkillDocument::triggers. |
Parsing Strictness
adk-skill validates a file according to its location:
- Strict Mode (
.skills/**/*.md,.claude/skills/**/*.md):- Mandatory:
nameanddescriptionmust be present and non-empty. - Validation: A file without them fails with a
SkillErrorand is not indexed. - Optional: All other fields (version, license, tools, etc.) are optional and default to empty or
None. - Files inside
references/,agents/, andscripts/subdirectories are skill resources, not skills, and are skipped.
- Mandatory:
- Permissive Mode (Convention Files):
- Files like
AGENTS.mdorSOUL.mdtreat frontmatter as entirely optional. - If frontmatter is missing, the parser derives the skill name from the filename and assigns default convention tags.
- Files like
Instruction Convention Files
The index loader also discovers and ingests these markdown files:
AGENTS.mdandAGENT.mdCLAUDE.mdGEMINI.mdCOPILOT.mdSKILLS.mdSOUL.md(repository root only)
For these files, frontmatter is optional:
- If valid frontmatter is present, it is used.
- Otherwise the file is parsed as plain markdown instructions and converted into a skill document with convention tags (for example
agents-md,claude-md).
Logic-as-Data
adk-skill treats agent behavior as configuration. By parsing allowed-tools and
references, a runtime can instantiate the toolset for an agent session from the active skill:
- Role-Based Access Control: Limit an agent's capabilities based on the active skill.
- Pluggable Personalities: Swap personas by changing the active skill.
- Resource Injection: Load the reference data a specific flow needs.
What The Crate Does
1. Discovery
- Scans
<root>/.skills/and<root>/.claude/skills/recursively for frontmatter skills. - Scans
<root>recursively for supported convention files. - Skips common heavy directories (
.git,target,node_modules,dist,build, etc.). - Returns deterministic sorted file paths with de-duplication.
API: discover_skill_files(root), discover_instruction_files(root), and the _with_extras
variants that add directories outside the root.
2. Parsing + Validation
- Strict path (
.skills/**): parses required frontmatter as YAML with validation. - Convention path (
AGENTS.md,CLAUDE.md, etc.): parses plain markdown (or frontmatter if provided). - Returns actionable errors with file path context for strict frontmatter paths.
API: parse_skill_markdown(path, content), parse_instruction_markdown(path, content)
3. Indexing
- Builds
SkillIndexfrom discovered files. - Computes:
- content hash (
SHA-256) last_modified(Unix timestamp seconds when available)- stable document id:
normalized-name + first-12-hash-chars
- content hash (
- Sorts documents deterministically by
(name, path).
API: load_skill_index(root), load_skill_index_with_extras(root, extra_dirs)
4. Selection (Scoring)
select_skills is a deterministic, token-based relevance engine. For every query token found
in a skill field, the score increases by that field's weight:
| Field | Weight |
|---|---|
| Name | +4.0 |
| Description | +2.5 |
| Tags | +2.0 |
| Body | +1.0 |
Normalization: the raw score is divided by the square root of the number of unique tokens
in the body (at least 1): FinalScore = RawScore / sqrt(unique_body_tokens), so a long
instruction body does not drown out a concise skill. Tokenization is Unicode-aware, so skills
written in CJK, Cyrillic, or accented Latin scripts match.
SelectionPolicy then filters and ranks the scores:
- Tag filters: a skill with any tag in
exclude_tagsis dropped; withinclude_tagsset, only skills carrying one of them remain. - Threshold: a skill scoring below
min_scoreis discarded. - Ranking: matches are sorted by descending score, ties broken by name and then by file
path, and the first
top_kare returned.
SelectionPolicy defaults:
top_k = 1min_score = 1.0include_tags = []exclude_tags = []
The selection uses no random seed or model, so the same query against the same index always
yields the same scores, and every SkillMatch carries the document's content-derived id.
API: select_skills(index, query, policy)
5. The Context Coordinator
ContextCoordinator runs selection → tool validation → context construction and returns
a SkillContext holding the system instruction and the resolved Arc<dyn Tool> instances
together. It checks every tool in a skill's allowed-tools against the host's
ToolRegistry (re-exported from adk-core): ValidationMode::Strict (default) rejects a
skill that names a missing tool, and ValidationMode::Permissive omits the missing tool. The
model is therefore never told to use a tool that is not bound.
resolve tries ResolutionStrategy::ByName, ByQuery, and ByTag in order and returns the
first context that resolves.
use ;
use ;
use Arc;
/// A registry with no tools: only skills without `allowed-tools` resolve in strict mode.
;
6. Injection
Injection helpers prepend the selected skill body to user content using:
[skill:<name>]
<skill body>
[/skill]
Then original user text follows.
Behavior:
- Injection runs only when
Content.role == "user". - Query text is extracted from text parts and joined with newlines.
- Only the top match is injected.
- Injected body is truncated to
max_injected_chars(2000 inSkillInjectorConfig::default()).
APIs:
select_skill_prompt_block(...)apply_skill_injection(...)SkillInjector/SkillInjectorConfigSkillInjector::build_plugin(...)SkillInjector::build_plugin_manager(...)
Quick Start
tempfile is used here to give each example its own skills root.
Write, Load, and Match Skills
SkillWriter writes into the .skills directory load_skill_index discovers. Writes go through
a unique sibling temporary file, are synchronized, and atomically replace the destination on Unix
and Windows, so a crash mid-write cannot leave a half-written skill that breaks the index load.
use ;
A skill name becomes a filename, so validate_skill_name enforces the specification's
[a-z0-9-] rule (1–64 characters, no leading or trailing hyphen). That check is also the
path-safety boundary: ../escape and nested/name are rejected before any file is touched.
Use with_metadata_entry to record provenance, such as the incidents and timestamp behind a
skill an agent derived from experience, so a change in behaviour is auditable.
Inject Into User Content
use Content;
use ;
Build A Plugin Manager
use ;
SkillInjector holds an index snapshotted at construction, and build_plugin captures it by
handle — a plugin already handed to a runner keeps using the index it was built from.
reloaded rescans the root; it returns an error when the injector was built with
from_index, since there is no root to rescan.
Progressive Disclosure (Google ADK-style)
Enable the optional progressive-disclosure feature to expose skills as a
context-aware Toolset rather than injecting an instruction body into every
matching user message. It provides three always-available tools:
list_skills— L1: names and descriptions only.load_skill— L2: loads one skill's instructions and activates its declaredallowed-toolsfor the next model turn.load_skill_resource— L3: reads a file from a skill'sreferences/,assets/, orscripts/directory.
SkillToolset automatically injects the progressive-disclosure protocol into
each model request, so individual agents do not need to repeat it in their
instructions. The protocol is generated at runtime from the tools actually
available to the toolset. Use build_skill_system_instruction(...) to generate
a variant for a prefixed or filtered toolset, or
DEFAULT_SKILL_SYSTEM_INSTRUCTION for the default exported value.
The activation record contains the skill's content ID and hash, so a changed or
removed skill cannot silently retain its old permissions. Resources require
activation by default and reject path traversal. Set
ResourceAccessPolicy::GoogleCompatible only when direct resource reads are
required for interoperability.
The block is ignore because it needs the progressive-disclosure feature and adk-agent.
use ;
use ;
use ;
use Arc;
SkillInjector and ContextCoordinator remain available, and the toolset can coexist with
them.
When both progressive-disclosure and vertex-skill-registry are enabled,
attach a SkillRegistryClient through SkillToolset::with_registry_client. This adds the
registry's semantic search_skills tool and fetches a selected package only on load_skill.
Local names take precedence. load_skill and load_skill_resource accept only a name that
passes validate_skill_name, or the client's own {parent}/skills/{name}, so a model cannot
reach another project's registry with the agent's credentials. Registry activations retain
their fully qualified resource name and content hash, so they can be validated on later
model turns.
Vertex AI Skill Registry (vertex-skill-registry)
The registry module is a read-only client for the Vertex AI Skill Registry (v1beta1):
SkillRegistryClient::new_with_adc(SkillRegistryConfig::new(project, location)) gets, lists,
searches, and downloads skill packages. fetch_skill_content verifies the archive's SHA-256
digest and extracts it in memory within the MAX_ARCHIVE_BYTES, MAX_UNCOMPRESSED_BYTES,
MAX_ENTRIES, MAX_COMPRESSION_RATIO, and MAX_DIRECTORY_DEPTH bounds. Skill and revision
names that are not a bare ID or a well-formed resource name are rejected before any request.
Creating, updating, and deleting skills is left to platform tooling.
Error Model
Main error type: SkillError
IoYaml { message }— the YAML library's message; frontmatter is read withserde-saphyr, and no YAML library type appears in the APIInvalidFrontmatter { path, message }MissingField { path, field }InvalidSkillsRoot(path)Validation(message)IndexError(message)- With
vertex-skill-registry:Registry(Box<AdkError>),RegistryPayloadDecode,RegistryChecksumMismatch, and theArchive*variants for archives that break an extraction bound
SkillError converts into AdkError with a skill.* error code.
Type alias: SkillResult<T> = Result<T, SkillError>
Current Limits
- No embedding/vector retrieval (lexical matching only).
SkillInjector::reloadedrescans the whole root; there is no file-watching or incremental reload.- Progressive disclosure reads skill scripts as resources but does not execute them; use an
adk-sandboxoradk-codeintegration to run them.
Application Integration Patterns
- Confidence threshold: in high-stakes applications, raise
min_scoreso the agent acts only on a strong match. - Ambiguity handling: with
top_k > 1, close scores can be presented to the user as a choice instead of injecting one skill. - Generalist fallback: keep a broad skill with a tag such as
fallback, and listResolutionStrategy::ByTag("fallback")afterByQuery, so it resolves when no skill matches. - Observability: log
SkillMatch.scorewithSkillMatch.skill.idand.hash, so a change in selection can be traced to a change in a skill.
Optimizing Selection Score
The selection engine uses weighted token matches, so metadata steers discovery:
- Name (+4.0): use specific, unique terms.
- Description (+2.5): include the keywords users' queries contain; keep descriptions of different skills distinct so two skills do not match the same queries.
- Tags (+2.0): add synonyms or broad categories (e.g.,
[plumbing, drainage]). - Body (+1.0): keep it concise; a longer body increases the normalization divisor
(
sqrt(unique_body_tokens)). allowed-tools: declare the tools a skill needs, so the coordinator and the progressive-disclosure toolset bind only those.
Related Examples
skills_multilingualin adk-playground — Unicode-aware selection across Chinese, Russian, and Englishexamples/skill_memory_improvements—.skillsindexing and lexical matching
Development
License
Apache-2.0
Part of ADK-Rust
This crate is part of the ADK-Rust framework for building AI agents in Rust.