| 66 | |
| 67 | func (n *FunctionCall) Execute(ctx context.Context, scope *engine.Scope) (string, error) { |
| 68 | args := make(map[string]expr.Value, len(n.fn.Info.Arguments)) |
| 69 | for _, arg := range n.fn.Info.Arguments { |
| 70 | v, err := expr.Eval(n.inputBindings[arg.Uid], scope) |
| 71 | if err != nil { |
| 72 | return "", fmt.Errorf("function_call %s: argument %s: %w", n.ID(), arg.Name, err) |
| 73 | } |
| 74 | args[arg.Uid] = v.Cast(arg.DataType) |
| 75 | } |
| 76 | |
| 77 | results, err := n.fn.Call(ctx, args) |
| 78 | if err != nil { |
| 79 | return "", fmt.Errorf("function_call %s: %w", n.ID(), err) |
| 80 | } |
| 81 | |
| 82 | for _, ret := range n.fn.Info.Returns { |
| 83 | if err := engine.ApplyOutput(scope, n.ID(), ret.Uid, n.outputBindings[ret.Uid], results[ret.Uid]); err != nil { |
| 84 | return "", fmt.Errorf("function_call %s: applying output %s: %w", n.ID(), ret.Name, err) |
| 85 | } |
| 86 | } |
| 87 | return n.Next(engine.PortCtrl, scope) |
| 88 | } |
| 89 | |
| 90 | // Tools exposes this function as an LLM-callable tool. |
| 91 | func (n *FunctionCall) Tools() ([]llmproxy.FunctionTool, error) { |
| 92 | properties := make(map[string]any, len(n.fn.Info.Arguments)) |