ReadTemplate returns a tool that retrieves details about a specific template, including its configurable rich parameters. The agent uses this after list_templates and before create_workspace. db must not be nil.
(db database.Store, organizationID uuid.UUID, options ReadTemplateOptions)
| 27 | // uses this after list_templates and before create_workspace. |
| 28 | // db must not be nil. |
| 29 | func ReadTemplate(db database.Store, organizationID uuid.UUID, options ReadTemplateOptions) fantasy.AgentTool { |
| 30 | return fantasy.NewAgentTool( |
| 31 | "read_template", |
| 32 | "Get details about a workspace template, including its "+ |
| 33 | "configurable parameters and available presets. Use this "+ |
| 34 | "after finding a template with list_templates and before "+ |
| 35 | "creating a workspace with create_workspace.", |
| 36 | func(ctx context.Context, args readTemplateArgs, _ fantasy.ToolCall) (fantasy.ToolResponse, error) { |
| 37 | templateIDStr := strings.TrimSpace(args.TemplateID) |
| 38 | if templateIDStr == "" { |
| 39 | return fantasy.NewTextErrorResponse("template_id is required"), nil |
| 40 | } |
| 41 | templateID, err := uuid.Parse(templateIDStr) |
| 42 | if err != nil { |
| 43 | return fantasy.NewTextErrorResponse( |
| 44 | xerrors.Errorf("invalid template_id: %w", err).Error(), |
| 45 | ), nil |
| 46 | } |
| 47 | |
| 48 | if !isTemplateAllowed(options.AllowedTemplateIDs, templateID) { |
| 49 | return fantasy.NewTextErrorResponse("template not found"), nil |
| 50 | } |
| 51 | |
| 52 | ctx, err = asOwner(ctx, db, options.OwnerID) |
| 53 | if err != nil { |
| 54 | return fantasy.NewTextErrorResponse(err.Error()), nil |
| 55 | } |
| 56 | |
| 57 | template, err := db.GetTemplateByID(ctx, templateID) |
| 58 | if err != nil { |
| 59 | return fantasy.NewTextErrorResponse("template not found"), nil |
| 60 | } |
| 61 | |
| 62 | if template.OrganizationID != organizationID { |
| 63 | return fantasy.NewTextErrorResponse("template not found"), nil |
| 64 | } |
| 65 | |
| 66 | params, err := db.GetTemplateVersionParameters(ctx, template.ActiveVersionID) |
| 67 | if err != nil { |
| 68 | return fantasy.NewTextErrorResponse( |
| 69 | xerrors.Errorf("failed to get template parameters: %w", err).Error(), |
| 70 | ), nil |
| 71 | } |
| 72 | |
| 73 | presets, err := db.GetPresetsByTemplateVersionID(ctx, template.ActiveVersionID) |
| 74 | if err != nil { |
| 75 | return fantasy.NewTextErrorResponse( |
| 76 | xerrors.Errorf("failed to get template presets: %w", err).Error(), |
| 77 | ), nil |
| 78 | } |
| 79 | |
| 80 | templateInfo := map[string]any{ |
| 81 | "id": template.ID.String(), |
| 82 | "name": template.Name, |
| 83 | "active_version_id": template.ActiveVersionID.String(), |
| 84 | } |
| 85 | if display := strings.TrimSpace(template.DisplayName); display != "" { |
| 86 | templateInfo["display_name"] = display |