MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / Tools

Method Tools

go/engine/node/functioncall.go:92–141  ·  view source on GitHub ↗

Tools exposes this function as an LLM-callable tool.

()

Source from the content-addressed store, hash-verified

90// Tools exposes this function as an LLM-callable tool.
91func (n *FunctionCall) Tools() ([]llmproxy.FunctionTool, error) {
92 properties := make(map[string]any, len(n.fn.Info.Arguments))
93 argByName := make(map[string]workflowapi.Variable, len(n.fn.Info.Arguments))
94 for _, a := range n.fn.Info.Arguments {
95 properties[a.Name] = map[string]any{"type": JSONTypeFor(a.DataType)}
96 argByName[a.Name] = a
97 }
98 returnByUid := make(map[string]workflowapi.Variable, len(n.fn.Info.Returns))
99 for _, r := range n.fn.Info.Returns {
100 returnByUid[r.Uid] = r
101 }
102
103 ft := llmproxy.FunctionTool{
104 ExternalToolBase: llmproxy.ExternalToolBase{
105 Name: n.fn.Info.Name,
106 Description: n.toolDescription,
107 Parameters: schemautil.StrictObject(properties),
108 },
109 ToolCall: func(ctx context.Context, arguments json.RawMessage) (any, error) {
110 var in map[string]any
111 if len(arguments) > 0 {
112 if err := json.Unmarshal(arguments, &in); err != nil {
113 return nil, fmt.Errorf("function_call %s: parse arguments: %w", n.ID(), err)
114 }
115 }
116 args := make(map[string]expr.Value, len(argByName))
117 for argName, meta := range argByName {
118 raw, ok := in[argName]
119 if !ok {
120 return nil, fmt.Errorf("function_call %s: missing argument %q", n.ID(), argName)
121 }
122 v, err := expr.Coerce(meta.DataType, raw)
123 if err != nil {
124 return nil, fmt.Errorf("function_call %s: argument %q: %w", n.ID(), argName, err)
125 }
126 args[meta.Uid] = v
127 }
128 results, err := n.fn.Call(ctx, args)
129 if err != nil {
130 return nil, fmt.Errorf("function_call %s: %w", n.ID(), err)
131 }
132 out := make(map[string]any, len(results))
133 for uid, v := range results {
134 out[returnByUid[uid].Name] = v.Raw
135 }
136 return out, nil
137 },
138 }
139 return []llmproxy.FunctionTool{ft}, nil
140}

Callers

nothing calls this directly

Calls 2

CallMethod · 0.80
IDMethod · 0.65

Tested by

no test coverage detected