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

Function executeFunctionTools

go/llmproxy/agent/runner.go:195–228  ·  view source on GitHub ↗

executeFunctionTools runs the given function tool calls using the tools available to the current agent.

(ctx context.Context, requests []llmproxy.ToolCallRequest, currentAgent *Agent, turn int, emit func(Event))

Source from the content-addressed store, hash-verified

193
194// executeFunctionTools runs the given function tool calls using the tools available to the current agent.
195func executeFunctionTools(ctx context.Context, requests []llmproxy.ToolCallRequest, currentAgent *Agent, turn int, emit func(Event)) (*Handoff, llmproxy.InputItems, error) {
196 newInputItems := llmproxy.InputItems{}
197 for _, req := range requests {
198 tool, ok := FindExternalTool(currentAgent, req.Name)
199 if !ok {
200 return nil, nil, fmt.Errorf("tool %s not found for agent %s", req.Name, currentAgent.Name)
201 }
202 switch ft := tool.(type) {
203 case llmproxy.FunctionTool:
204 // Add tool call itself to conversation input, so model knows what was called
205 newInputItems = append(newInputItems, req)
206 emit(Event{Type: EventToolCall, Turn: turn, ToolCall: &req})
207 // Call the tool function and get the result
208 toolResult, err := ft.ToolCall(ctx, req.Arguments)
209 if err != nil {
210 return nil, nil, fmt.Errorf("error invoking tool %s: %w", req.Name, err)
211 }
212 // Add tool result to conversation input
213 ftr := llmproxy.ToolResult{
214 CallID: req.CallID,
215 Name: ft.ToolName(),
216 Output: toolResult,
217 }
218 newInputItems = append(newInputItems, ftr)
219 emit(Event{Type: EventToolResult, Turn: turn, ToolResult: &ftr})
220 case Handoff:
221 // Handoffs are control flow changes. No tool requests, results or turns.
222 return &ft, nil, nil
223 default:
224 return nil, nil, fmt.Errorf("unsupported function tool type %T for tool %s", ft, req.Name)
225 }
226 }
227 return nil, newInputItems, nil
228}

Callers 1

RunMethod · 0.85

Calls 3

FindExternalToolFunction · 0.85
ToolNameMethod · 0.65
emitFunction · 0.50

Tested by

no test coverage detected