Execute 执行工具
(ctx context.Context, input map[string]any, tctx *tools.ToolContext)
| 356 | |
| 357 | // Execute 执行工具 |
| 358 | func (t *LogicMemoryUpdateTool) Execute(ctx context.Context, input map[string]any, tctx *tools.ToolContext) (any, error) { |
| 359 | action, _ := input["action"].(string) |
| 360 | namespace, _ := input["namespace"].(string) |
| 361 | |
| 362 | // 如果没有提供 namespace,尝试从上下文获取 |
| 363 | if namespace == "" && tctx != nil { |
| 364 | if tctx.ThreadID != "" { |
| 365 | namespace = "thread:" + tctx.ThreadID |
| 366 | } else if tctx.AgentID != "" { |
| 367 | namespace = "agent:" + tctx.AgentID |
| 368 | } |
| 369 | } |
| 370 | if namespace == "" { |
| 371 | return nil, errors.New("namespace is required") |
| 372 | } |
| 373 | |
| 374 | key, _ := input["key"].(string) |
| 375 | if key == "" { |
| 376 | return nil, errors.New("key is required") |
| 377 | } |
| 378 | |
| 379 | switch action { |
| 380 | case "record": |
| 381 | return t.record(ctx, namespace, key, input) |
| 382 | case "delete": |
| 383 | return t.delete(ctx, namespace, key) |
| 384 | default: |
| 385 | return nil, fmt.Errorf("unknown action: %s", action) |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | // Prompt 返回工具使用说明 |
| 390 | func (t *LogicMemoryUpdateTool) Prompt() string { |