Execute returns an AgentTool that runs a shell command in the workspace via the agent HTTP API.
(options ExecuteOptions)
| 90 | // Execute returns an AgentTool that runs a shell command in the |
| 91 | // workspace via the agent HTTP API. |
| 92 | func Execute(options ExecuteOptions) fantasy.AgentTool { |
| 93 | return fantasy.NewAgentTool( |
| 94 | ExecuteToolName, |
| 95 | "Execute a shell command in the workspace. Runs the command and waits for completion up to the timeout (default 10s, override with the timeout parameter e.g. '30s', '5m'). If the command exceeds the timeout, the response includes a background_process_id; use process_output with that ID to re-attach and wait for the result. Use run_in_background=true for persistent processes (dev servers, file watchers) or when you want to continue other work while the command runs. Never use shell '&' for backgrounding.", |
| 96 | func(ctx context.Context, args ExecuteArgs, _ fantasy.ToolCall) (fantasy.ToolResponse, error) { |
| 97 | if options.GetWorkspaceConn == nil { |
| 98 | return fantasy.NewTextErrorResponse("workspace connection resolver is not configured"), nil |
| 99 | } |
| 100 | conn, err := options.GetWorkspaceConn(ctx) |
| 101 | if err != nil { |
| 102 | return fantasy.NewTextErrorResponse(err.Error()), nil |
| 103 | } |
| 104 | return executeTool(ctx, conn, args, options.DefaultTimeout), nil |
| 105 | }, |
| 106 | ) |
| 107 | } |
| 108 | |
| 109 | func executeTool( |
| 110 | ctx context.Context, |