feat: adapt preloaded skills to smart-reasoning agent

This commit is contained in:
nullkey
2026-02-04 03:40:09 +08:00
committed by lyingbug
parent 33f7e7da66
commit 3f21345546
32 changed files with 2194 additions and 719 deletions
+17 -6
View File
@@ -202,16 +202,27 @@ func formatSkillsMetadata(skillsMetadata []*skills.SkillMetadata) string {
}
var builder strings.Builder
builder.WriteString("\n### Available Skills\n\n")
builder.WriteString("The following skills are available. When a user request matches a skill's description, ")
builder.WriteString("use the `read_skill` tool to load its full instructions before proceeding.\n\n")
builder.WriteString("\n### Available Skills (IMPORTANT - READ CAREFULLY)\n\n")
builder.WriteString("**You MUST actively consider using these skills for EVERY user request.**\n\n")
builder.WriteString("#### Skill Matching Protocol (MANDATORY)\n\n")
builder.WriteString("Before responding to ANY user query, follow this checklist:\n\n")
builder.WriteString("1. **SCAN**: Read each skill's description and trigger conditions below\n")
builder.WriteString("2. **MATCH**: Check if the user's intent matches ANY skill's triggers (keywords, scenarios, or task types)\n")
builder.WriteString("3. **LOAD**: If a match is found, call `read_skill(skill_name=\"...\")` BEFORE generating your response\n")
builder.WriteString("4. **APPLY**: Follow the skill's instructions to provide a higher-quality, structured response\n\n")
builder.WriteString("**⚠️ CRITICAL**: Skill usage is MANDATORY when applicable. Do NOT skip skills to save time or tokens.\n\n")
builder.WriteString("#### Available Skills\n\n")
for i, skill := range skillsMetadata {
builder.WriteString(fmt.Sprintf("%d. **%s**: %s\n", i+1, skill.Name, skill.Description))
builder.WriteString(fmt.Sprintf("%d. **%s**\n", i+1, skill.Name))
builder.WriteString(fmt.Sprintf(" %s\n\n", skill.Description))
}
builder.WriteString("\nUse `read_skill` with the skill name to load detailed instructions when needed.\n")
builder.WriteString("Use `execute_skill_script` to run utility scripts bundled with a skill.\n")
builder.WriteString("#### Tool Reference\n\n")
builder.WriteString("- `read_skill(skill_name)`: Load full skill instructions (MUST call before using a skill)\n")
builder.WriteString("- `execute_skill_script(skill_name, script_path, args, input)`: Run utility scripts bundled with a skill\n")
return builder.String()
}
+4 -3
View File
@@ -236,7 +236,7 @@ func (l *Loader) LoadSkillFile(skillName, relativePath string) (*SkillFile, erro
return &SkillFile{
Name: relativePath,
Path: fullPath,
Path: absFilePath, // Use absolute path for sandbox execution
Content: string(content),
IsScript: IsScript(relativePath),
}, nil
@@ -287,7 +287,7 @@ func (l *Loader) GetSkillByName(name string) (*Skill, bool) {
return skill, ok
}
// GetSkillBasePath returns the base path for a skill
// GetSkillBasePath returns the base path for a skill (always absolute)
func (l *Loader) GetSkillBasePath(skillName string) (string, error) {
skill, ok := l.discoveredSkills[skillName]
if !ok {
@@ -297,7 +297,8 @@ func (l *Loader) GetSkillBasePath(skillName string) (string, error) {
return "", fmt.Errorf("skill not found: %s", skillName)
}
}
return skill.BasePath, nil
// Return absolute path for consistent sandbox execution
return filepath.Abs(skill.BasePath)
}
// Reload clears the cache and rediscovers all skills
+2 -1
View File
@@ -172,7 +172,7 @@ func (m *Manager) ListSkillFiles(ctx context.Context, skillName string) ([]strin
}
// ExecuteScript executes a script from a skill in the sandbox
func (m *Manager) ExecuteScript(ctx context.Context, skillName, scriptPath string, args []string) (*sandbox.ExecuteResult, error) {
func (m *Manager) ExecuteScript(ctx context.Context, skillName, scriptPath string, args []string, stdin string) (*sandbox.ExecuteResult, error) {
if !m.enabled {
return nil, fmt.Errorf("skills are not enabled")
}
@@ -207,6 +207,7 @@ func (m *Manager) ExecuteScript(ctx context.Context, skillName, scriptPath strin
Script: file.Path,
Args: args,
WorkDir: basePath,
Stdin: stdin,
}
// Execute in sandbox
+2 -2
View File
@@ -23,8 +23,8 @@ const (
// Reserved words that cannot be used in skill names
var reservedWords = []string{"anthropic", "claude"}
// namePattern validates skill names: lowercase letters, numbers, and hyphens only
var namePattern = regexp.MustCompile(`^[a-z0-9-]+$`)
// namePattern validates skill names: unicode letters, numbers only
var namePattern = regexp.MustCompile(`^[\p{L}\p{N}-]+$`)
// xmlTagPattern detects XML tags in content
var xmlTagPattern = regexp.MustCompile(`<[^>]+>`)
+4 -3
View File
@@ -44,6 +44,7 @@ type ExecuteSkillScriptInput struct {
SkillName string `json:"skill_name" jsonschema:"Name of the skill containing the script"`
ScriptPath string `json:"script_path" jsonschema:"Relative path to the script within the skill directory (e.g. scripts/analyze.py)"`
Args []string `json:"args,omitempty" jsonschema:"Optional command-line arguments to pass to the script"`
Input string `json:"input,omitempty" jsonschema:"Optional input data to pass to the script via stdin"`
}
// ExecuteSkillScriptTool allows the agent to execute skill scripts in a sandbox
@@ -98,10 +99,10 @@ func (t *ExecuteSkillScriptTool) Execute(ctx context.Context, args json.RawMessa
}
// Execute the script in sandbox
logger.Infof(ctx, "[Tool][ExecuteSkillScript] Executing script: %s/%s with args: %v",
input.SkillName, input.ScriptPath, input.Args)
logger.Infof(ctx, "[Tool][ExecuteSkillScript] Executing script: %s/%s with args: %v, input length: %d",
input.SkillName, input.ScriptPath, input.Args, len(input.Input))
result, err := t.skillManager.ExecuteScript(ctx, input.SkillName, input.ScriptPath, input.Args)
result, err := t.skillManager.ExecuteScript(ctx, input.SkillName, input.ScriptPath, input.Args, input.Input)
if err != nil {
logger.Errorf(ctx, "[Tool][ExecuteSkillScript] Script execution failed: %v", err)
return &types.ToolResult{