Repository navigation
feat(sdk): implement support for custom skills #19031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
79310d5
feat(sdk): implement support for custom skills
mbleigh de62430
perf(sdk): load skills in parallel during initialization
mbleigh 4231e6e
refactor(sdk): simplify SkillReference to use 'dir' only
mbleigh 51bc140
Merge branch 'main' into sdk-04-custom-skills
mbleigh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,5 @@ | |
|
|
||
| export * from './agent.js'; | ||
| export * from './tool.js'; | ||
| export * from './skills.js'; | ||
| export * from './types.js'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
| import { GeminiCliAgent } from './agent.js'; | ||
| import { skillDir, skillRoot } from './skills.js'; | ||
| import * as path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { dirname } from 'node:path'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
|
|
||
| // Set this to true locally when you need to update snapshots | ||
| const RECORD_MODE = process.env['RECORD_NEW_RESPONSES'] === 'true'; | ||
|
|
||
| const getGoldenPath = (name: string) => | ||
| path.resolve(__dirname, '../test-data', `${name}.json`); | ||
|
|
||
| const SKILL_DIR = path.resolve(__dirname, '../test-data/skills/pirate-skill'); | ||
| const SKILL_ROOT = path.resolve(__dirname, '../test-data/skills'); | ||
|
|
||
| describe('GeminiCliAgent Skills Integration', () => { | ||
| it('loads and activates a skill from a directory', async () => { | ||
| const goldenFile = getGoldenPath('skill-dir-success'); | ||
|
|
||
| const agent = new GeminiCliAgent({ | ||
| instructions: 'You are a helpful assistant.', | ||
| skills: [skillDir(SKILL_DIR)], | ||
| // If recording, use real model + record path. | ||
| // If testing, use auto model + fake path. | ||
| model: RECORD_MODE ? 'gemini-2.0-flash' : undefined, | ||
| recordResponses: RECORD_MODE ? goldenFile : undefined, | ||
| fakeResponses: RECORD_MODE ? undefined : goldenFile, | ||
| }); | ||
|
|
||
| // 1. Ask to activate the skill | ||
| const events = []; | ||
| // The prompt explicitly asks to activate the skill by name | ||
| const stream = agent.sendStream( | ||
| 'Activate the pirate-skill and then tell me a joke.', | ||
| ); | ||
|
|
||
| for await (const event of stream) { | ||
| events.push(event); | ||
| } | ||
|
|
||
| const textEvents = events.filter((e) => e.type === 'content'); | ||
| const responseText = textEvents | ||
| .map((e) => (typeof e.value === 'string' ? e.value : '')) | ||
| .join(''); | ||
|
|
||
| // Expect pirate speak | ||
| expect(responseText.toLowerCase()).toContain('arrr'); | ||
| }, 60000); | ||
|
|
||
| it('loads and activates a skill from a root', async () => { | ||
| const goldenFile = getGoldenPath('skill-root-success'); | ||
|
|
||
| const agent = new GeminiCliAgent({ | ||
| instructions: 'You are a helpful assistant.', | ||
| skills: [skillRoot(SKILL_ROOT)], | ||
| // If recording, use real model + record path. | ||
| // If testing, use auto model + fake path. | ||
| model: RECORD_MODE ? 'gemini-2.0-flash' : undefined, | ||
| recordResponses: RECORD_MODE ? goldenFile : undefined, | ||
| fakeResponses: RECORD_MODE ? undefined : goldenFile, | ||
| }); | ||
|
|
||
| // 1. Ask to activate the skill | ||
| const events = []; | ||
| const stream = agent.sendStream( | ||
| 'Activate the pirate-skill and confirm it is active.', | ||
| ); | ||
|
|
||
| for await (const event of stream) { | ||
| events.push(event); | ||
| } | ||
|
|
||
| const textEvents = events.filter((e) => e.type === 'content'); | ||
| const responseText = textEvents | ||
| .map((e) => (typeof e.value === 'string' ? e.value : '')) | ||
| .join(''); | ||
|
|
||
| // Expect confirmation or pirate speak | ||
| expect(responseText.toLowerCase()).toContain('arrr'); | ||
| }, 60000); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| export type SkillReference = | ||
| | { type: 'dir'; path: string } | ||
|
mbleigh marked this conversation as resolved.
Resolved
|
||
| | { type: 'root'; path: string }; | ||
|
|
||
| /** | ||
| * Reference a directory containing a single skill. | ||
| * The directory must contain a SKILL.md file. | ||
| * | ||
| * @param path Path to the skill directory | ||
| */ | ||
| export function skillDir(path: string): SkillReference { | ||
| return { type: 'dir', path }; | ||
| } | ||
|
|
||
| /** | ||
| * Reference a root directory containing multiple skills. | ||
| * The directory should contain subdirectories, each with a SKILL.md file. | ||
| * | ||
| * @param path Path to the skills root directory | ||
| */ | ||
| export function skillRoot(path: string): SkillReference { | ||
| return { type: 'root', path }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| {"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"functionCall":{"name":"activate_skill","args":{"name":"pirate-skill"}}}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7160,"candidatesTokenCount":8,"totalTokenCount":7168,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7160}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":8}]}}]} | ||
| {"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"Arrr, why"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10048,"totalTokenCount":10048,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10048}]}},{"candidates":[{"content":{"parts":[{"text":" don't pirates play poker? Because they always have a hidden ace up their sleeves"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10048,"totalTokenCount":10048,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10048}]}},{"candidates":[{"content":{"parts":[{"text":"!\\n"}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7284,"candidatesTokenCount":23,"totalTokenCount":7307,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7284}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":23}]}}]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| {"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"functionCall":{"name":"activate_skill","args":{"name":"pirate-skill"}}}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7170,"candidatesTokenCount":8,"totalTokenCount":7178,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7170}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":8}]}}]} | ||
| {"method":"generateContentStream","response":[{"candidates":[{"content":{"parts":[{"text":"Ar"}],"role":"model"}}],"usageMetadata":{"promptTokenCount":10058,"totalTokenCount":10058,"promptTokensDetails":[{"modality":"TEXT","tokenCount":10058}]}},{"candidates":[{"content":{"parts":[{"text":"rr, the pirate skill be active, matey!"}],"role":"model"},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":7294,"candidatesTokenCount":12,"totalTokenCount":7306,"promptTokensDetails":[{"modality":"TEXT","tokenCount":7294}],"candidatesTokensDetails":[{"modality":"TEXT","tokenCount":12}]}}]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| name: pirate-skill | ||
| description: Speak like a pirate. | ||
| --- | ||
| You are a pirate. Respond to everything in pirate speak. Always mention "Arrr". |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.