File tree Expand file tree Collapse file tree 5 files changed +34
-1
lines changed
packages/agent-runtime/src/templates Expand file tree Collapse file tree 5 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ export function createBase2(
6363 'propose_write_file' ,
6464 ! noAskUser && 'ask_user' ,
6565 'set_output' ,
66+ 'skill' ,
6667 ) ,
6768 spawnableAgents : buildArray (
6869 ! isMax && 'file-picker' ,
@@ -232,6 +233,7 @@ ${isDefault || isMax
232233
233234${ PLACEHOLDER . FILE_TREE_PROMPT_SMALL }
234235${ PLACEHOLDER . KNOWLEDGE_FILES_CONTENTS }
236+ ${ PLACEHOLDER . SKILLS_PROMPT }
235237${ PLACEHOLDER . SYSTEM_INFO_PROMPT }
236238
237239# Initial Git Changes
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export type AllToolNames =
77 | 'add_subgoal'
88 | 'browser_logs'
99 | 'create_plan'
10+ | 'skill'
1011 | 'spawn_agent_inline'
1112 | 'update_subgoal'
1213
@@ -31,6 +32,7 @@ const placeholderNames = [
3132 'KNOWLEDGE_FILES_CONTENTS' ,
3233 'PROJECT_ROOT' ,
3334 'REMAINING_STEPS' ,
35+ 'SKILLS_PROMPT' ,
3436 'SYSTEM_INFO_PROMPT' ,
3537 'TOOLS_PROMPT' ,
3638 'USER_CWD' ,
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import type { SkillsMap } from '../types/skill'
33/**
44 * Escapes special XML characters in a string.
55 */
6- function escapeXml ( str : string ) : string {
6+ export function escapeXml ( str : string ) : string {
77 return str
88 . replace ( / & / g, '&' )
99 . replace ( / < / g, '<' )
@@ -30,3 +30,29 @@ export function formatAvailableSkillsXml(skills: SkillsMap): string {
3030
3131 return `<available_skills>\n${ skillsXml } \n</available_skills>`
3232}
33+
34+ /**
35+ * Formats skills as a system prompt section for injection into agent prompts.
36+ * Returns a markdown section with available skills and instructions on using the skill tool.
37+ * Returns empty string if no skills are available.
38+ */
39+ export function formatSkillsSystemPrompt ( skills : SkillsMap | undefined ) : string {
40+ if ( ! skills ) {
41+ return ''
42+ }
43+
44+ const skillEntries = Object . values ( skills )
45+ if ( skillEntries . length === 0 ) {
46+ return ''
47+ }
48+
49+ const skillsXml = formatAvailableSkillsXml ( skills )
50+
51+ return `# Available Skills
52+
53+ The following skills are available to help you complete tasks. Each skill provides specialized instructions and behaviors.
54+
55+ ${ skillsXml }
56+
57+ Use the \`skill\` tool to load a skill's full instructions when relevant to the current task. Skills are loaded on-demand - only load them when you need their specific guidance. Always load any relevant skills immediately: You should bias toward loading too many skills as early as possible.`
58+ }
Original file line number Diff line number Diff line change 11import { KNOWLEDGE_FILE_NAMES_LOWERCASE } from '@codebuff/common/constants/knowledge'
2+ import { formatSkillsSystemPrompt } from '@codebuff/common/util/skills'
23import { escapeString } from '@codebuff/common/util/string'
34import { z } from 'zod/v4'
45
@@ -131,6 +132,7 @@ export async function formatPrompt(
131132 return `\`\`\`${ path } \n${ content . trim ( ) } \n\`\`\``
132133 } )
133134 . join ( '\n\n' ) ,
135+ [ PLACEHOLDER . SKILLS_PROMPT ] : ( ) => formatSkillsSystemPrompt ( fileContext . skills ) ,
134136 }
135137
136138 for ( const varName of placeholderValues ) {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ const placeholderNames = [
2121 'KNOWLEDGE_FILES_CONTENTS' ,
2222 'PROJECT_ROOT' ,
2323 'REMAINING_STEPS' ,
24+ 'SKILLS_PROMPT' ,
2425 'SYSTEM_INFO_PROMPT' ,
2526 'USER_CWD' ,
2627 'USER_INPUT_PROMPT' ,
You can’t perform that action at this time.
0 commit comments