CallTool 调用单个工具
(ctx context.Context, name string, input map[string]any, tc *tools.ToolContext)
| 61 | |
| 62 | // CallTool 调用单个工具 |
| 63 | func (b *ToolBridge) CallTool(ctx context.Context, name string, input map[string]any, tc *tools.ToolContext) (*CallToolResult, error) { |
| 64 | tool, err := b.GetTool(name) |
| 65 | if err != nil { |
| 66 | return &CallToolResult{ |
| 67 | Name: name, |
| 68 | Success: false, |
| 69 | Error: err.Error(), |
| 70 | }, nil |
| 71 | } |
| 72 | |
| 73 | result, err := tool.Execute(ctx, input, tc) |
| 74 | if err != nil { |
| 75 | return &CallToolResult{ |
| 76 | Name: name, |
| 77 | Success: false, |
| 78 | Error: err.Error(), |
| 79 | }, nil |
| 80 | } |
| 81 | |
| 82 | return &CallToolResult{ |
| 83 | Name: name, |
| 84 | Success: true, |
| 85 | Result: result, |
| 86 | }, nil |
| 87 | } |
| 88 | |
| 89 | // CallToolJSON 使用 JSON 字符串调用工具 |
| 90 | func (b *ToolBridge) CallToolJSON(ctx context.Context, name string, inputJSON string, tc *tools.ToolContext) (*CallToolResult, error) { |