Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,219 changes: 2,219 additions & 0 deletions agent_skill.md

Large diffs are not rendered by default.

127 changes: 127 additions & 0 deletions contributing/samples/agent_skills_demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Agent Skills Demo

This demo showcases the Agent Skills standard integration with ADK. It demonstrates how to:

1. Load skills from directories using `AgentSkillLoader`
2. Convert skills to ADK tools using `SkillTool`
3. Generate discovery prompts for the LLM
4. Use skills with progressive disclosure

## Running the Demo

```bash
# From the adk-python root directory
adk web contributing/samples/agent_skills_demo
```

## What's Included

### Skills Loaded

The demo loads BigQuery ML skills from `src/google/adk/tools/bigquery/skills/`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The path to the skills directory seems incorrect. The built-in BigQuery skills are located in src/google/adk/skills/, not src/google/adk/tools/bigquery/skills/.

Suggested change
The demo loads BigQuery ML skills from `src/google/adk/tools/bigquery/skills/`:
The demo loads BigQuery ML skills from `src/google/adk/skills/`:


- **bqml** - Machine learning in BigQuery
- **bq-ai-operator** - AI operations (text generation, embeddings)

### Skill Structure (Agent Skills Standard)

Each skill follows the Agent Skills standard format:

```
skill-name/
├── SKILL.md # Short description and instructions
├── references/ # Detailed documentation
│ ├── MODEL_TYPES.md
│ └── BEST_PRACTICES.md
├── scripts/ # Helper scripts
│ └── validate_model.py
└── assets/ # Templates, configs
```

### Progressive Disclosure

Skills support three stages:

1. **Discovery** (Stage 1): Minimal metadata shown in discovery prompt
2. **Activation** (Stage 2): Full instructions loaded on demand
3. **Execution** (Stage 3): Scripts and references loaded as needed

## Example Interactions

### Discover Available Skills

```
User: What ML skills do you have?
Agent: [Reviews discovery prompt and lists available skills]
```

### Activate a Skill

```
User: Tell me about BQML
Agent: [Activates bqml skill, provides detailed instructions]
```

### Load Reference Documentation

```
User: What model types are available?
Agent: [Loads MODEL_TYPES.md reference, explains options]
```

### Run a Script

```
User: Validate my model configuration
Agent: [Runs validate_model.py script]
```

## Code Walkthrough

```python
from google.adk.skills import AgentSkillLoader, SkillTool

# Load skills from directory
loader = AgentSkillLoader()
loader.add_skill_directory("./skills")

# Create tools for agent
skill_tools = [SkillTool(skill) for skill in loader.get_all_skills()]

# Generate system prompt
discovery_prompt = loader.generate_discovery_prompt()

# Create agent with skill tools
agent = LlmAgent(
model="gemini-2.0-flash",
instruction=f"Available skills:\n{discovery_prompt}",
tools=skill_tools,
)
```

## Customization

### Adding Custom Skills

1. Create a skill directory following the Agent Skills standard
2. Add `SKILL.md` with YAML frontmatter
3. Add references, scripts, and assets as needed
4. Update the `SKILLS_DIR` path in `agent.py`

### Skill Configuration

Skills can include ADK-specific configuration in their frontmatter:

```yaml
adk:
config:
timeout_seconds: 300
max_parallel_calls: 5
allowed_callers:
- my_agent
```

## Learn More

- [Agent Skills Standard](https://agentskills.io)
- [ADK Skills Documentation](../../docs/skills_programmatic_tool_calling_design.md)
17 changes: 17 additions & 0 deletions contributing/samples/agent_skills_demo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Agent Skills Demo - demonstrates Agent Skills standard integration."""

from . import agent
163 changes: 163 additions & 0 deletions contributing/samples/agent_skills_demo/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Agent Skills Demo - demonstrates Agent Skills standard integration.

This demo shows how to:
1. Load skills from directories using AgentSkillLoader
2. Convert skills to ADK tools using SkillTool
3. Generate discovery prompts for the LLM
4. Use skills with progressive disclosure
5. Integrate with BigQuery toolset for data operations

Run with: adk web contributing/samples
Then select 'agent_skills_demo' from the list.
"""

from __future__ import annotations

import os
from pathlib import Path

import google.auth

from google.adk.agents.llm_agent import LlmAgent
from google.adk.skills import AgentSkillLoader
from google.adk.skills import SkillTool
from google.adk.tools.bigquery.bigquery_credentials import BigQueryCredentialsConfig
from google.adk.tools.bigquery.bigquery_toolset import BigQueryToolset
from google.adk.tools.bigquery.config import BigQueryToolConfig
from google.adk.tools.bigquery.config import WriteMode

# Default Vertex AI settings
os.environ.setdefault("GOOGLE_GENAI_USE_VERTEXAI", "true")
os.environ.setdefault("GOOGLE_CLOUD_PROJECT", os.getenv("VERTEXAI_PROJECT", ""))
os.environ.setdefault("GOOGLE_CLOUD_LOCATION", os.getenv("VERTEXAI_LOCATION", "us-central1"))

# Path to skills directory (now in main skills module)
SKILLS_DIR = Path(__file__).parent.parent.parent.parent / "src" / "google" / "adk" / "skills"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Constructing the SKILLS_DIR path using relative parent directories is fragile and can break if the file structure changes. A more robust approach is to import the SKILLS_DIR constant directly from the google.adk.skills package, where it is already defined.

Suggested change
SKILLS_DIR = Path(__file__).parent.parent.parent.parent / "src" / "google" / "adk" / "skills"
from google.adk.skills import SKILLS_DIR


# Initialize the skill loader
skill_loader = AgentSkillLoader(validate_names=False)

# Load skills from the BigQuery skills directory
if SKILLS_DIR.exists():
skill_count = skill_loader.add_skill_directory(SKILLS_DIR)
print(f"Loaded {skill_count} skills from {SKILLS_DIR}")
else:
print(f"Warning: Skills directory not found: {SKILLS_DIR}")

# Create skill tools for the agent
skill_tools = [SkillTool(skill) for skill in skill_loader.get_all_skills()]

# Generate discovery prompt for the system instruction
discovery_prompt = skill_loader.generate_discovery_prompt(include_resources=True)

# Setup BigQuery toolset with Application Default Credentials
try:
application_default_credentials, _ = google.auth.default()
credentials_config = BigQueryCredentialsConfig(
credentials=application_default_credentials
)

# Configure BigQuery tools - allow writes for ML model creation
tool_config = BigQueryToolConfig(
write_mode=WriteMode.ALLOWED,
application_name="agent_skills_demo"
)

bigquery_toolset = BigQueryToolset(
credentials_config=credentials_config,
bigquery_tool_config=tool_config
)
print("BigQuery toolset initialized successfully")
except Exception as e:
print(f"Warning: Could not initialize BigQuery toolset: {e}")
bigquery_toolset = None

# Build the system instruction
SYSTEM_INSTRUCTION = f"""You are a data science assistant with access to BigQuery AI and ML skills.

## Available Skills

{discovery_prompt}

## Skill Overview

- **bigquery-ai**: Generative AI operations - text generation with LLMs (Gemini, Claude), embeddings, vector search, and RAG workflows
- **bqml**: Traditional ML - classification, regression, clustering, time series forecasting, recommendations

## How to Use Skills

1. **Discover**: Review the available skills above to find the right one for your task
2. **Activate**: Use the skill tool with action="activate" to get detailed instructions
3. **Load References**: Use action="load_reference" to load detailed documentation for specific topics
4. **Run Scripts**: Use action="run_script" to execute helper scripts for setup and validation

## BigQuery Tools

You also have direct access to BigQuery tools for:
- Executing SQL queries (including CREATE MODEL, ML functions)
- Exploring datasets and tables
- Getting table schemas and metadata

## Guidelines

- For generative AI (text generation, embeddings, semantic search, RAG): Use **bigquery-ai** skill
- For predictive ML (classification, regression, forecasting): Use **bqml** skill
- Always activate a skill before using its detailed features
- Load specific reference docs when you need in-depth information
- Use BigQuery tools to run the actual SQL queries

## Example Workflows

**Generative AI Example:**
User: "How do I build a RAG system in BigQuery?"
1. Activate bigquery-ai skill
2. Load RAG_WORKFLOW.md reference
3. Use BigQuery tools to create models and run queries

**Traditional ML Example:**
User: "How do I train a churn prediction model?"
1. Activate bqml skill
2. Load MODEL_TYPES.md reference for classifier options
3. Use BigQuery tools to create and evaluate the model
"""

# Combine all tools
all_tools = skill_tools.copy()
if bigquery_toolset:
all_tools.append(bigquery_toolset)

# Create the agent with Gemini 2.5 Pro
root_agent = LlmAgent(
model="gemini-2.5-pro",
name="agent_skills_demo",
description="A demo agent showcasing Agent Skills standard integration with ADK and BigQuery tools.",
instruction=SYSTEM_INSTRUCTION,
tools=all_tools,
)

# Print summary on load
if __name__ == "__main__" or True:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The condition if __name__ == "__main__" or True: will always evaluate to true, causing the summary to be printed every time this module is imported. This was likely intended for debugging and should be corrected to if __name__ == "__main__": to ensure it only runs when the script is executed directly.

Suggested change
if __name__ == "__main__" or True:
if __name__ == "__main__":

print("\n" + "=" * 60)
print("Agent Skills Demo")
print("=" * 60)
print(f"\nModel: gemini-2.5-pro")
print(f"Loaded skills: {skill_loader.get_skill_names()}")
print(f"Skill tools: {[t.name for t in skill_tools]}")
print(f"BigQuery toolset: {'enabled' if bigquery_toolset else 'disabled'}")
print("\nRun with: adk web contributing/samples")
print("Then select 'agent_skills_demo' from the list")
print("=" * 60 + "\n")
Loading