|
| 1 | +# Design: First-Party (1P) Skills for ADK Toolsets |
| 2 | + |
| 3 | +## Problem |
| 4 | + |
| 5 | +ADK toolsets like `BigQueryToolset` provide raw tools (e.g., `execute_sql`, |
| 6 | +`list_dataset_ids`) but no guidance on how to use them effectively. Developers |
| 7 | +must re-invent prompt engineering for each toolset, embedding workflow |
| 8 | +knowledge directly in agent instructions. This leads to: |
| 9 | + |
| 10 | +- Duplicated effort across agent builders. |
| 11 | +- Inconsistent quality of analysis workflows. |
| 12 | +- No standard way to share toolset expertise. |
| 13 | +- Agent instructions that grow unwieldy as guidance accumulates. |
| 14 | + |
| 15 | +## Solution |
| 16 | + |
| 17 | +Pre-packaged skills that follow the |
| 18 | +[agentskills.io specification](https://agentskills.io/specification), |
| 19 | +consumed via ADK's existing `SkillToolset`. Zero new APIs, zero new classes. |
| 20 | + |
| 21 | +A 1P skill is simply a spec-compliant skill directory that ships with ADK |
| 22 | +alongside its corresponding toolset. Users add both the toolset (for tools) |
| 23 | +and a `SkillToolset` (for guided workflows) to their agent. |
| 24 | + |
| 25 | +```python |
| 26 | +# Before: raw toolset, no guidance |
| 27 | +root_agent = LlmAgent(tools=[bigquery_toolset]) |
| 28 | + |
| 29 | +# After: toolset + 1P skill for guided workflows |
| 30 | +bq_skill_toolset = SkillToolset(skills=[get_bigquery_skill()]) |
| 31 | +root_agent = LlmAgent(tools=[bigquery_toolset, bq_skill_toolset]) |
| 32 | +``` |
| 33 | + |
| 34 | +## How It Works |
| 35 | + |
| 36 | +### Progressive Disclosure |
| 37 | + |
| 38 | +The skill content is loaded in three levels, keeping context efficient: |
| 39 | + |
| 40 | +1. **L1 - Metadata** (always in context): Skill name and description are |
| 41 | + returned by `list_skills`. The LLM sees what skills are available without |
| 42 | + loading full instructions. |
| 43 | + |
| 44 | +2. **L2 - Instructions** (loaded on activation): When the LLM calls |
| 45 | + `load_skill(name="bigquery-data-analysis")`, it receives the SKILL.md |
| 46 | + body with step-by-step workflow guidance. |
| 47 | + |
| 48 | +3. **L3 - References** (loaded on demand): When the LLM needs detailed |
| 49 | + patterns, it calls `load_skill_resource` to load specific reference |
| 50 | + files (e.g., `sql_patterns.md`, `error_handling.md`). |
| 51 | + |
| 52 | +### Runtime Flow |
| 53 | + |
| 54 | +``` |
| 55 | +1. Agent starts -> SkillToolset injects skill system instruction |
| 56 | +2. User asks question -> LLM sees list_skills tool available |
| 57 | +3. LLM calls list_skills -> sees "bigquery-data-analysis" skill |
| 58 | +4. LLM calls load_skill("bigquery-data-analysis") -> gets workflow steps |
| 59 | +5. LLM follows steps, using BigQuery tools (execute_sql, etc.) |
| 60 | +6. LLM calls load_skill_resource for detailed patterns as needed |
| 61 | +``` |
| 62 | + |
| 63 | +### Directory Structure |
| 64 | + |
| 65 | +``` |
| 66 | +src/google/adk/tools/bigquery/ |
| 67 | +├── bigquery_toolset.py # Existing: raw tools |
| 68 | +├── bigquery_skill.py # New: get_bigquery_skill() loader |
| 69 | +└── skills/ |
| 70 | + └── bigquery-data-analysis/ # Spec-compliant skill directory |
| 71 | + ├── SKILL.md # Frontmatter + workflow instructions |
| 72 | + └── references/ |
| 73 | + ├── sql_patterns.md |
| 74 | + ├── schema_exploration.md |
| 75 | + └── error_handling.md |
| 76 | +``` |
| 77 | + |
| 78 | +## API Usage |
| 79 | + |
| 80 | +### Before (tools only) |
| 81 | + |
| 82 | +```python |
| 83 | +from google.adk.agents.llm_agent import LlmAgent |
| 84 | +from google.adk.tools.bigquery.bigquery_toolset import BigQueryToolset |
| 85 | + |
| 86 | +bigquery_toolset = BigQueryToolset(credentials_config=creds) |
| 87 | + |
| 88 | +root_agent = LlmAgent( |
| 89 | + model="gemini-2.5-flash", |
| 90 | + name="analyst", |
| 91 | + instruction="""You are a data analyst. When analyzing data: |
| 92 | + 1. First explore schemas with list_dataset_ids, list_table_ids... |
| 93 | + 2. Use get_table_info before writing queries... |
| 94 | + 3. Always use LIMIT on exploratory queries... |
| 95 | + 4. Use CTEs for complex queries... |
| 96 | + 5. Handle errors by checking get_job_info... |
| 97 | + ... (many lines of hand-written guidance)""", |
| 98 | + tools=[bigquery_toolset], |
| 99 | +) |
| 100 | +``` |
| 101 | + |
| 102 | +### After (tools + 1P skill) |
| 103 | + |
| 104 | +```python |
| 105 | +from google.adk.agents.llm_agent import LlmAgent |
| 106 | +from google.adk.tools.bigquery.bigquery_toolset import BigQueryToolset |
| 107 | +from google.adk.tools.bigquery.bigquery_skill import get_bigquery_skill |
| 108 | +from google.adk.tools.skill_toolset import SkillToolset |
| 109 | + |
| 110 | +bigquery_toolset = BigQueryToolset(credentials_config=creds) |
| 111 | +bq_skill_toolset = SkillToolset(skills=[get_bigquery_skill()]) |
| 112 | + |
| 113 | +root_agent = LlmAgent( |
| 114 | + model="gemini-2.5-flash", |
| 115 | + name="analyst", |
| 116 | + instruction="You are a data analyst. Use your tools and skills.", |
| 117 | + tools=[bigquery_toolset, bq_skill_toolset], |
| 118 | +) |
| 119 | +``` |
| 120 | + |
| 121 | +The curated guidance moves from fragile inline instructions into a |
| 122 | +structured, versioned, spec-compliant skill that the agent discovers |
| 123 | +and loads at runtime. |
| 124 | + |
| 125 | +## Extension Guide |
| 126 | + |
| 127 | +Other teams can follow the same pattern for their toolsets: |
| 128 | + |
| 129 | +### 1. Create a Spec-Compliant Skill Directory |
| 130 | + |
| 131 | +``` |
| 132 | +src/google/adk/tools/<toolset>/skills/<skill-name>/ |
| 133 | +├── SKILL.md # Required: YAML frontmatter + instructions |
| 134 | +└── references/ # Optional: detailed reference materials |
| 135 | + └── ... |
| 136 | +``` |
| 137 | + |
| 138 | +The directory name must match the `name` field in SKILL.md frontmatter. |
| 139 | + |
| 140 | +### 2. Add a Convenience Loader |
| 141 | + |
| 142 | +```python |
| 143 | +# src/google/adk/tools/<toolset>/<toolset>_skill.py |
| 144 | + |
| 145 | +import pathlib |
| 146 | +from google.adk.skills import Skill, load_skill_from_dir |
| 147 | + |
| 148 | +_SKILL_DIR = pathlib.Path(__file__).parent / "skills" / "<skill-name>" |
| 149 | + |
| 150 | +def get_<toolset>_skill() -> Skill: |
| 151 | + return load_skill_from_dir(_SKILL_DIR) |
| 152 | +``` |
| 153 | + |
| 154 | +### 3. Users Combine Toolset + SkillToolset |
| 155 | + |
| 156 | +```python |
| 157 | +from google.adk.tools.<toolset> import <Toolset> |
| 158 | +from google.adk.tools.<toolset>.<toolset>_skill import get_<toolset>_skill |
| 159 | +from google.adk.tools.skill_toolset import SkillToolset |
| 160 | + |
| 161 | +toolset = <Toolset>(...) |
| 162 | +skill_toolset = SkillToolset(skills=[get_<toolset>_skill()]) |
| 163 | +agent = LlmAgent(tools=[toolset, skill_toolset]) |
| 164 | +``` |
| 165 | + |
| 166 | +### Candidate Toolsets |
| 167 | + |
| 168 | +- **Spanner**: Schema design, transaction patterns, query optimization. |
| 169 | +- **Bigtable**: Row key design, filter patterns, scan optimization. |
| 170 | +- **PubSub**: Topic/subscription setup, message handling, dead-letter queues. |
| 171 | + |
| 172 | +## Spec Compliance |
| 173 | + |
| 174 | +The skill directory maps to [agentskills.io](https://agentskills.io/specification) |
| 175 | +fields as follows: |
| 176 | + |
| 177 | +| Spec Field | Source | |
| 178 | +|------------|--------| |
| 179 | +| `name` | SKILL.md frontmatter `name` (must match directory name) | |
| 180 | +| `description` | SKILL.md frontmatter `description` | |
| 181 | +| `license` | SKILL.md frontmatter `license` | |
| 182 | +| `metadata` | SKILL.md frontmatter `metadata` | |
| 183 | +| `instructions` | SKILL.md body (after frontmatter) | |
| 184 | +| `references` | `references/` directory (loaded by `load_skill_resource`) | |
| 185 | +| `assets` | `assets/` directory (not used by this skill) | |
| 186 | +| `scripts` | `scripts/` directory (not used by this skill) | |
| 187 | + |
| 188 | +ADK's `load_skill_from_dir()` validates name-directory match, parses YAML |
| 189 | +frontmatter, and loads all resource directories. `SkillToolset` provides |
| 190 | +the standard tools for skill discovery, loading, and resource access. |
0 commit comments