-
Notifications
You must be signed in to change notification settings - Fork 4k
feat: agent skills #9353
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
Open
uinstinct
wants to merge
12
commits into
continuedev:main
Choose a base branch
from
uinstinct:agent-skills
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+222
−15
Open
feat: agent skills #9353
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
207469a
read and inject skills to system message
uinstinct b6eddec
add read skill tool
uinstinct d754331
prevent loading in system message
uinstinct cef4b8d
get config dependent tool definitions async
uinstinct c219e3e
read skill is a tool definition
uinstinct 5f7ecab
fix test lints
uinstinct 0c2ad71
Merge branch 'main' into agent-skills
uinstinct 6df421f
remove system message skill
uinstinct e0753f5
simplify tool frontmatter validation
uinstinct 2ecccb0
Merge branch 'main' into agent-skills
uinstinct 8575945
load skills from .claude directory
uinstinct b9bcd33
add supporting files for skill tool
uinstinct 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { ConfigValidationError } from "@continuedev/config-yaml"; | ||
| import * as YAML from "yaml"; | ||
| import { IDE, Skill } from "../.."; | ||
| import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants"; | ||
|
|
||
| // todo: refactor this to packages/config-yaml (like parseMarkdownRule) | ||
| function parseSkillMarkdown(content: string): Skill { | ||
| const normalizedContent = content.replace(/\r\n/g, "\n"); | ||
|
|
||
| const parts = normalizedContent.split(/^---\s*$/m); | ||
|
|
||
| if (parts.length < 3) { | ||
| throw new Error("Invalid skill markdown file"); | ||
| } | ||
| const frontmatterStr = parts[1]; | ||
| const markdownContent = parts.slice(2).join("---"); | ||
|
|
||
| const frontmatter = YAML.parse(frontmatterStr) || {}; // Handle empty frontmatter | ||
| // todo: validate frontmatter with zod | ||
|
|
||
| return { | ||
| ...frontmatter, | ||
| content: markdownContent, | ||
| }; | ||
| } | ||
|
|
||
| export async function loadMarkdownSkills(ide: IDE) { | ||
| const errors: ConfigValidationError[] = []; | ||
| const skills: Skill[] = []; | ||
|
|
||
| try { | ||
| const yamlAndMarkdownFiles = await getAllDotContinueDefinitionFiles( | ||
| ide, | ||
| { | ||
| includeGlobal: true, | ||
| includeWorkspace: true, | ||
| fileExtType: "markdown", | ||
| }, | ||
| "", // SKILL.md can exist in any .continue subdirectory | ||
| ); | ||
|
|
||
| const skillFiles = yamlAndMarkdownFiles.filter((file) => | ||
| file.path.endsWith("SKILL.md"), | ||
| ); | ||
| for (const file of skillFiles) { | ||
| try { | ||
| const skill = parseSkillMarkdown(file.content); | ||
| skills.push({ ...skill, path: file.path.slice(7) }); | ||
| } catch (error) { | ||
| errors.push({ | ||
| fatal: false, | ||
| message: `Failed to parse markdown skill file: ${error instanceof Error ? error.message : error}`, | ||
| }); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| errors.push({ | ||
| fatal: false, | ||
| message: `Error loading markdown skill files: ${err instanceof Error ? err.message : err}`, | ||
| }); | ||
| } | ||
|
|
||
| return { skills, errors }; | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { Skill } from ".."; | ||
|
|
||
| export function getSystemMessageWithSkills( | ||
| systemMessage: string, | ||
| skills: Skill[], | ||
| ) { | ||
| const lines = [ | ||
| "You have access to skills listed in `<available_skills>`. When a task matches a skill's description, read its SKILL.md file to get detailed instructions.", | ||
| "", | ||
| "<available_skills>", | ||
| ]; | ||
| for (const skill of skills) { | ||
| lines.push(" <skill>"); | ||
| lines.push(` <name>${skill.name}</name>`); | ||
| lines.push(` <description>${skill.description}</description>`); | ||
| lines.push(" </skill>"); | ||
| } | ||
| lines.push("</available_skills>"); | ||
|
|
||
| console.log("debug1 with skills", lines.join("\n")); | ||
uinstinct marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return systemMessage + "\n\n" + lines.join("\n"); | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { Tool } from "../.."; | ||
| import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; | ||
|
|
||
| export const readSkillTool: Tool = { | ||
| type: "function", | ||
| displayTitle: "Read Skill", | ||
| wouldLikeTo: "read skill {{{ skillName }}}", | ||
| isCurrently: "reading skill {{{ skillName }}}", | ||
| hasAlready: "read skill {{{ skillName }}}", | ||
| readonly: true, | ||
| isInstant: true, | ||
| group: BUILT_IN_GROUP_NAME, | ||
| function: { | ||
| name: BuiltInToolNames.ReadSkill, | ||
| description: | ||
| "Use this tool to read the content of a skill by its name. Skills contain detailed instructions for specific tasks. The skill name should match one of the available skills listed in the system message.", | ||
| parameters: { | ||
| type: "object", | ||
| required: ["skillName"], | ||
| properties: { | ||
| skillName: { | ||
| type: "string", | ||
| description: | ||
| "The name of the skill to read. This should match the name field from the available skills.", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { ToolImpl } from "."; | ||
| import { ContinueError, ContinueErrorReason } from "../../util/errors"; | ||
| import { getStringArg } from "../parseArgs"; | ||
|
|
||
| export const readSkillImpl: ToolImpl = async (args, extras) => { | ||
| const skillName = getStringArg(args, "skillName"); | ||
|
|
||
| const skill = extras.config.skills.find((s) => s.name === skillName); | ||
|
|
||
| if (!skill) { | ||
| const availableSkills = extras.config.skills.map((s) => s.name).join(", "); | ||
| throw new ContinueError( | ||
| ContinueErrorReason.SkillNotFound, | ||
| `Skill "${skillName}" not found. Available skills: ${availableSkills || "none"}`, | ||
| ); | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| name: `Skill: ${skill.name}`, | ||
| description: skill.description, | ||
| content: `# ${skill.name}\n\n${skill.description}\n\n## Instructions\n\n${skill.content}`, | ||
| uri: { | ||
| type: "file", | ||
| value: skill.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
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
Oops, something went wrong.
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.