| 42 | } |
| 43 | |
| 44 | func (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 | |
| 67 | func (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.` |