Files
enkly-ai/services/agent/internal/infrastructure/toolexec/office_skill.go
enkly 79ce8dc4c0
Some checks failed
Go CI Pipeline / build_and_test (push) Failing after 22m0s
Init Project
2026-10-30 18:06:55 +01:00

61 lines
2.3 KiB
Go

// read_office_skill and search_office_skills are the two office-skill
// tools that aren't a gRPC call or an officekit XML operation.
// read_office_skill is pure, in-memory lookup into pkg/skillkit's
// embedded skill files (the same category as write_todos and
// solve_ml_math — no workspace/knowledge dependency, see executor.go's
// package doc); search_office_skills calls out to the vLLM-hosted
// embedding model (via Executor.SkillIndex) to embed the query, same
// as search_codebase
// calling out to the knowledge service — see rag.go's package doc for
// why this one stays in-process instead.
package toolexec
import (
"context"
"fmt"
"strings"
"enkly/pkg/skillkit"
"enkly/pkg/vllmkit"
)
func readOfficeSkill(call vllmkit.ToolCallRequest) vllmkit.ToolResult {
name := argStr(call.Arguments, "name")
skill, ok := skillkit.Read(name)
if !ok {
available := skillkit.Names()
return errResult(call.Name, "read_office_skill: no skill named %q (available: %s)", name, strings.Join(available, ", "))
}
return vllmkit.ToolResult{Name: call.Name, Content: skill.Body}
}
func (e *Executor) searchOfficeSkills(ctx context.Context, call vllmkit.ToolCallRequest) vllmkit.ToolResult {
query := strings.TrimSpace(argStr(call.Arguments, "query"))
if query == "" {
return errResult(call.Name, "search_office_skills: empty query")
}
if e.SkillIndex == nil {
return errResult(call.Name, "search_office_skills: not available on this deployment (no embedding model configured); use read_office_skill instead")
}
skillFilter := argStr(call.Arguments, "skill")
if skillFilter != "" {
if _, ok := skillkit.Read(skillFilter); !ok {
return errResult(call.Name, "search_office_skills: no skill named %q (available: %s)", skillFilter, strings.Join(skillkit.Names(), ", "))
}
}
matches, err := e.SkillIndex.Search(ctx, query, 4, skillFilter)
if err != nil {
return errResult(call.Name, "search_office_skills: %v", err)
}
if len(matches) == 0 {
return vllmkit.ToolResult{Name: call.Name, Content: "no matching guidance found"}
}
var sb strings.Builder
for _, m := range matches {
fmt.Fprintf(&sb, "### %s — %s (similarity %.3f)\n%s\n\n", m.Skill, m.Heading, m.Score, m.Text)
}
return vllmkit.ToolResult{Name: call.Name, Content: strings.TrimRight(sb.String(), "\n")}
}