MCPcopy Index your code
hub / github.com/docker/docker-agent / executeToolCommands

Function executeToolCommands

pkg/runtime/commands.go:215–240  ·  view source on GitHub ↗

executeToolCommands executes !tool_name(arg=value) patterns and replaces them with output.

(ctx context.Context, rt Runtime, instruction string)

Source from the content-addressed store, hash-verified

213
214// executeToolCommands executes !tool_name(arg=value) patterns and replaces them with output.
215func executeToolCommands(ctx context.Context, rt Runtime, instruction string) string {
216 commands := parseToolCommands(instruction)
217 if len(commands) == 0 {
218 return instruction
219 }
220
221 agentTools, err := rt.CurrentAgentTools(ctx)
222 if err != nil {
223 slog.WarnContext(ctx, "Failed to get agent tools for command execution", "error", err)
224 return instruction
225 }
226
227 toolMap := make(map[string]tools.Tool, len(agentTools))
228 for _, t := range agentTools {
229 toolMap[t.Name] = t
230 }
231
232 // Process in reverse order to maintain correct indices
233 result := instruction
234 for _, cmd := range slices.Backward(commands) {
235 replacement := executeSingleToolCommand(ctx, toolMap, cmd.toolName, cmd.argsStr)
236 result = result[:cmd.start] + replacement + result[cmd.end:]
237 }
238
239 return result
240}
241
242// executeSingleToolCommand executes a single tool command and returns the output.
243func executeSingleToolCommand(ctx context.Context, toolMap map[string]tools.Tool, toolName, argsStr string) string {

Callers 1

ResolveCommandFunction · 0.85

Calls 3

parseToolCommandsFunction · 0.85
executeSingleToolCommandFunction · 0.85
CurrentAgentToolsMethod · 0.65

Tested by

no test coverage detected