mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
feat: add path in the results of use_skill
This commit is contained in:
@@ -938,10 +938,15 @@ func (a *skillLoaderAdapter) LoadSkills(ctx context.Context, botID string) ([]fl
|
|||||||
}
|
}
|
||||||
entries := make([]flow.SkillEntry, len(items))
|
entries := make([]flow.SkillEntry, len(items))
|
||||||
for i, item := range items {
|
for i, item := range items {
|
||||||
|
skillPath := ""
|
||||||
|
if item.SourcePath != "" {
|
||||||
|
skillPath = stdpath.Dir(item.SourcePath)
|
||||||
|
}
|
||||||
entries[i] = flow.SkillEntry{
|
entries[i] = flow.SkillEntry{
|
||||||
Name: item.Name,
|
Name: item.Name,
|
||||||
Description: item.Description,
|
Description: item.Description,
|
||||||
Content: item.Content,
|
Content: item.Content,
|
||||||
|
Path: skillPath,
|
||||||
Metadata: item.Metadata,
|
Metadata: item.Metadata,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -619,6 +619,7 @@ func (a *Agent) assembleTools(ctx context.Context, cfg RunConfig, emitter tools.
|
|||||||
skillsMap[s.Name] = tools.SkillDetail{
|
skillsMap[s.Name] = tools.SkillDetail{
|
||||||
Description: s.Description,
|
Description: s.Description,
|
||||||
Content: s.Content,
|
Content: s.Content,
|
||||||
|
Path: s.Path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
session := tools.SessionContext{
|
session := tools.SessionContext{
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ func (*SkillProvider) Tools(_ context.Context, session SessionContext) ([]sdk.To
|
|||||||
"skillName": skillName,
|
"skillName": skillName,
|
||||||
"description": skill.Description,
|
"description": skill.Description,
|
||||||
"content": skill.Content,
|
"content": skill.Content,
|
||||||
|
"path": skill.Path,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUseSkillReturnsPath(t *testing.T) {
|
||||||
|
provider := NewSkillProvider(nil)
|
||||||
|
|
||||||
|
toolset, err := provider.Tools(context.Background(), SessionContext{
|
||||||
|
Skills: map[string]SkillDetail{
|
||||||
|
"pdf": {
|
||||||
|
Description: "Read PDF instructions",
|
||||||
|
Content: "Use a PDF-aware workflow.",
|
||||||
|
Path: "/data/.agents/skills/pdf",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Tools returned error: %v", err)
|
||||||
|
}
|
||||||
|
if len(toolset) != 1 {
|
||||||
|
t.Fatalf("expected 1 tool, got %d", len(toolset))
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := toolset[0].Execute(nil, map[string]any{
|
||||||
|
"skillName": "pdf",
|
||||||
|
"reason": "Need to process a PDF attachment",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Execute returned error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
payload, ok := result.(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("result type = %T, want map[string]any", result)
|
||||||
|
}
|
||||||
|
if got := payload["path"]; got != "/data/.agents/skills/pdf" {
|
||||||
|
t.Fatalf("path = %#v, want %q", got, "/data/.agents/skills/pdf")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
type SkillDetail struct {
|
type SkillDetail struct {
|
||||||
Description string
|
Description string
|
||||||
Content string
|
Content string
|
||||||
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamEventType identifies the kind of stream event emitted by tools.
|
// StreamEventType identifies the kind of stream event emitted by tools.
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type SkillEntry struct {
|
|||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
Content string
|
Content string
|
||||||
|
Path string
|
||||||
Metadata map[string]any
|
Metadata map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ type SkillEntry struct {
|
|||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
Content string
|
Content string
|
||||||
|
Path string
|
||||||
Metadata map[string]any
|
Metadata map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,6 +704,7 @@ func normalizeGatewaySkill(entry SkillEntry) (agentpkg.SkillEntry, bool) {
|
|||||||
Name: name,
|
Name: name,
|
||||||
Description: description,
|
Description: description,
|
||||||
Content: content,
|
Content: content,
|
||||||
|
Path: strings.TrimSpace(entry.Path),
|
||||||
Metadata: entry.Metadata,
|
Metadata: entry.Metadata,
|
||||||
}, true
|
}, true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package flow
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestNormalizeGatewaySkillPreservesPath(t *testing.T) {
|
||||||
|
got, ok := normalizeGatewaySkill(SkillEntry{
|
||||||
|
Name: "pdf",
|
||||||
|
Description: "Read PDF instructions",
|
||||||
|
Content: "Use a PDF-aware workflow.",
|
||||||
|
Path: " /data/.agents/skills/pdf ",
|
||||||
|
})
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("normalizeGatewaySkill returned ok=false")
|
||||||
|
}
|
||||||
|
if got.Path != "/data/.agents/skills/pdf" {
|
||||||
|
t.Fatalf("path = %q, want %q", got.Path, "/data/.agents/skills/pdf")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -290,7 +290,7 @@ type skillsTestEnv struct {
|
|||||||
func newSkillsTestEnv(t *testing.T) *skillsTestEnv {
|
func newSkillsTestEnv(t *testing.T) *skillsTestEnv {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
dataRoot, err := os.MkdirTemp("", "memoh-skills-")
|
dataRoot, err := newSkillsTestDataRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("create temp data root: %v", err)
|
t.Fatalf("create temp data root: %v", err)
|
||||||
}
|
}
|
||||||
@@ -382,6 +382,18 @@ func (e *skillsTestEnv) localPath(containerPath string) string {
|
|||||||
return filepath.Join(e.dataRoot, filepath.FromSlash(strings.TrimPrefix(clean, "/")))
|
return filepath.Join(e.dataRoot, filepath.FromSlash(strings.TrimPrefix(clean, "/")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newSkillsTestDataRoot() (string, error) {
|
||||||
|
var lastErr error
|
||||||
|
for _, dir := range []string{"/tmp", ""} {
|
||||||
|
dataRoot, err := os.MkdirTemp(dir, "mh-sk-")
|
||||||
|
if err == nil {
|
||||||
|
return dataRoot, nil
|
||||||
|
}
|
||||||
|
lastErr = err
|
||||||
|
}
|
||||||
|
return "", lastErr
|
||||||
|
}
|
||||||
|
|
||||||
type skillsTestDB struct {
|
type skillsTestDB struct {
|
||||||
userID string
|
userID string
|
||||||
botID string
|
botID string
|
||||||
|
|||||||
Reference in New Issue
Block a user