AttachFile returns a tool that stores a workspace file as a durable chat attachment so the user can download it directly from the conversation.
(options AttachFileOptions)
| 24 | // AttachFile returns a tool that stores a workspace file as a durable chat |
| 25 | // attachment so the user can download it directly from the conversation. |
| 26 | func AttachFile(options AttachFileOptions) fantasy.AgentTool { |
| 27 | return fantasy.NewAgentTool( |
| 28 | "attach_file", |
| 29 | "Attach a workspace file to the current chat so the user can download it directly from the conversation. "+ |
| 30 | "Use this when the user should receive an artifact such as a screenshot, log, patch, or document. "+ |
| 31 | "Pass an absolute file path. The file must already exist in the workspace.", |
| 32 | func(ctx context.Context, args AttachFileArgs, _ fantasy.ToolCall) (fantasy.ToolResponse, error) { |
| 33 | if options.GetWorkspaceConn == nil { |
| 34 | return fantasy.NewTextErrorResponse("workspace connection resolver is not configured"), nil |
| 35 | } |
| 36 | if options.StoreFile == nil { |
| 37 | return fantasy.NewTextErrorResponse("file storage is not configured"), nil |
| 38 | } |
| 39 | conn, err := options.GetWorkspaceConn(ctx) |
| 40 | if err != nil { |
| 41 | return fantasy.NewTextErrorResponse(err.Error()), nil |
| 42 | } |
| 43 | return executeAttachFileTool(ctx, conn, args, options.StoreFile) |
| 44 | }, |
| 45 | ) |
| 46 | } |
| 47 | |
| 48 | func executeAttachFileTool( |
| 49 | ctx context.Context, |