Skip to content

Commit b2d7921

Browse files
committed
Give skill instructions in system prompt
1 parent 37588f0 commit b2d7921

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

agents/base2/base2.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

agents/types/secret-agent-definition.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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',

common/src/util/skills.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff 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, '&lt;')
@@ -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+
}

packages/agent-runtime/src/templates/strings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { KNOWLEDGE_FILE_NAMES_LOWERCASE } from '@codebuff/common/constants/knowledge'
2+
import { formatSkillsSystemPrompt } from '@codebuff/common/util/skills'
23
import { escapeString } from '@codebuff/common/util/string'
34
import { 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) {

packages/agent-runtime/src/templates/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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',

0 commit comments

Comments
 (0)