MCPcopy Create free account
hub / github.com/astercloud/aster / Execute

Method Execute

examples/memory-advanced/main.go:44–65  ·  view source on GitHub ↗
(ctx context.Context, input map[string]any, tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

42}
43
44func (t *userPreferenceTool) Execute(ctx context.Context, input map[string]any, tc *tools.ToolContext) (any, error) {
45 rawPref, _ := input["preference"].(string)
46 if rawPref == "" {
47 return nil, errors.New("preference is required")
48 }
49
50 scope := memory.Scope{
51 UserID: t.userID,
52 Shared: false, // 用户级
53 }
54 ns := scope.Namespace() // "" => 由 BaseNamespace(users/<user-id>) 控制
55
56 payload := map[string]any{
57 "file": "profile/prefs.md",
58 "namespace": ns,
59 "mode": "append",
60 "title": "User preference",
61 "content": rawPref,
62 }
63
64 return t.memoryWrite.Execute(ctx, payload, tc)
65}
66
67func (t *userPreferenceTool) Prompt() string {
68 return `Use this tool to store durable user preferences. You only need to describe the preference; the tool will choose a stable location in memory.`

Callers 1

mainFunction · 0.95

Calls 2

NamespaceMethod · 0.95
ExecuteMethod · 0.65

Tested by

no test coverage detected