mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 05:14:25 +00:00
feat(agent): format available skills as standard XML with absolute path locations
This commit is contained in:
+39
-6
@@ -149,12 +149,7 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
|
||||
systemPrompt: async () => {
|
||||
let prompt = systemPrompt
|
||||
if (teamSkills.length > 0) {
|
||||
prompt += '\n\nAvailable Skills:\n'
|
||||
for (const s of teamSkills) {
|
||||
prompt += `- ${s.name} (ID: ${s.id}): ${s.description || 'No description'}\n`
|
||||
}
|
||||
prompt +=
|
||||
'\nTo use a skill, first use the "read_skill" tool with the skill ID to read its instructions.'
|
||||
prompt += formatSkillsForPrompt(teamSkills)
|
||||
}
|
||||
return prompt
|
||||
},
|
||||
@@ -216,3 +211,41 @@ export function fieldsToTypeBoxSchema(fields: AutofillField[]) {
|
||||
|
||||
return Type.Object(properties)
|
||||
}
|
||||
|
||||
function escapeXml(str: string): string {
|
||||
return str
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
}
|
||||
|
||||
export function formatSkillsForPrompt(
|
||||
skills: Array<{ id: string; name: string; description?: string | null }>,
|
||||
): string {
|
||||
if (skills.length === 0) {
|
||||
return ''
|
||||
}
|
||||
|
||||
const lines = [
|
||||
'\n\nThe following skills provide specialized instructions for specific tasks.',
|
||||
"Use the read_skill tool to load a skill's file when the task matches its description.",
|
||||
'When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.',
|
||||
'',
|
||||
'<available_skills>',
|
||||
]
|
||||
|
||||
for (const skill of skills) {
|
||||
const filePath = path.join(process.cwd(), '.pi', 'skills', skill.id, 'SKILL.md')
|
||||
lines.push(' <skill>')
|
||||
lines.push(` <name>${escapeXml(skill.name)}</name>`)
|
||||
lines.push(` <description>${escapeXml(skill.description || 'No description')}</description>`)
|
||||
lines.push(` <location>${escapeXml(filePath)}</location>`)
|
||||
lines.push(' </skill>')
|
||||
}
|
||||
|
||||
lines.push('</available_skills>')
|
||||
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user