Skip to content

Conversation

@apascal07
Copy link
Collaborator

@apascal07 apascal07 commented Dec 4, 2025

New Multipart Tool APIs:

// Define a multipart tool that returns output + content parts
imageGen := genkit.DefineMultipartTool(g, "generateImage", "Generates an image",
    func(ctx *ai.ToolContext, input ImageInput) (*ai.MultipartToolResponse, error) {
        imageBytes := generateImage(input.Prompt)
        return &ai.MultipartToolResponse{
            Output: map[string]any{"status": "success"},
            Content: []*ai.Part{
                ai.NewMediaPart("image/png", base64.StdEncoding.EncodeToString(imageBytes)),
            },
        }, nil
    },
)

Updated Tool Definition with Options:

DefineToolWithInputSchema and NewToolWithInputSchema are now deprecated. Use DefineTool/NewTool with ai.WithInputSchema() instead:

// Before (deprecated)
tool := genkit.DefineToolWithInputSchema(g, "search", "Search tool", inputSchema, fn)

// After
tool := genkit.DefineTool(g, "search", "Search tool", fn, ai.WithInputSchema(inputSchema))

Key Changes:

  • MultipartToolResponse: New type with Output (any) and Content ([]*Part) fields
  • DefineMultipartTool / NewMultipartTool: Create tools that return rich content
  • WithInputSchema option: New options pattern for custom input schemas that is shared with DefinePrompt
  • Deprecated: DefineToolWithInputSchema and NewToolWithInputSchema
  • Tool.RunRawMultipart(): New method to get full multipart response from any tool

Checklist (if applicable):

@apascal07 apascal07 requested a review from pavelgj December 4, 2025 16:17
@apascal07 apascal07 marked this pull request as draft December 8, 2025 16:39
@apascal07 apascal07 marked this pull request as ready for review December 9, 2025 18:58
@apascal07 apascal07 merged commit 81d60b5 into main Dec 16, 2025
6 checks passed
@apascal07 apascal07 deleted the ap/go-multipart-tools branch December 16, 2025 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants