Skip to content

AI-assisted development

AI assistants need up-to-date knowledge of your codebase to be effective. When working with Genkit, your AI assistant must understand Genkit’s core concepts (flows, actions, dotprompt, etc.) and how to run and debug your application. The Genkit CLI provides a command to help you configure your AI assistant for this purpose.

Genkit offers the init:ai-tools command to automate the configuration of your favorite AI assistants to work with Genkit:

Terminal window
genkit init:ai-tools

This command performs the following actions:

  • Detects the existing AI assistant configuration to ensure that any changes do not affect existing settings. If no configuration is present, a new one is created.

  • Installs the Genkit MCP server for the selected AI assistant. The MCP server provides tools to help the assistant understand and interact with Genkit:

    • get_usage_guide: Looks up a detailed Genkit usage guide for a given language. Intended for AI assistants.
    • list_genkit_docs: List available documentation files.
    • search_genkit_docs: Search documentation for specific terms.
    • read_genkit_docs: Read the content of specific documentation files.
    • start_runtime: Start the application runtime (e.g. npm run dev) to enable flow discovery and execution.
    • list_flows: Lists the flows in the current Genkit app.
    • run_flow: Runs a specific flow with a given input.
    • get_trace: Fetches a trace by ID, which is useful for analysis and debugging.
    • kill_runtime / restart_runtime: Manage the runtime process.

    For more details, please refer to the Genkit MCP server documentation.

  • Adds or updates the GENKIT.md file and incorporates it into the AI assistant’s system context. This file contains instructions on using the Genkit CLI and the Genkit MCP server, and other information to streamline development with AI assistants.

Genkit supports two ways of integrating with Gemini CLI:

  • .gemini folder configuration: You can use the init:ai-tools command to set up Genkit context for your project. This will configure the Genkit MCP server in your .gemini/settings.json file and copy the GENKIT.md context file to the .gemini folder. This configuration is installed at the workspace level, making it ideal for providing project-level support.

  • Gemini CLI extension: Genkit has an official Gemini CLI extension that can be installed using the Gemini CLI:

Terminal window
gemini extensions install https://github.com/gemini-cli-extensions/genkit

This integrates natively with Gemini CLI and can be managed using the gemini extensions commands, including automatic updates.

Gemini extensions are installed at the user level; they are applicable to all Gemini CLI sessions for the current user and are curated to be applicable to a broad range of scenarios and projects.

genkit init:ai-tools also has built-in support for the following tools:

For other tools, you can select the generic configuration option in init:ai-tools command. This will provide a GENKIT.md file that you can manually integrate with your preferred AI tool. The following resources provide guidance on configuring popular AI coding environments:

Environment/IDEInstallation Instructions
Copilot powered IDEsConfigure .github/copilot-instructions.md
JetBrains IDEsConfigure guidelines.md
VS CodeConfigure .instructions.md
WindsurfConfigure guidelines.md

In addition to the MCP server integration, Genkit provides Agent Skills that offer structured knowledge and workflows for building Genkit applications. These skills are available at the Genkit Skills GitHub repository.

The skills repository contains curated knowledge packages designed to teach AI agents how to build applications using the Genkit framework. Currently available skills include:

  • developing-genkit-js: For developing Genkit applications with Node.js and TypeScript.

You can install skills in various ways:

Using skills.sh (Recommended):

Terminal window
npx skills add genkit-ai/skills

Using tool-specific command:

For example, if using Gemini CLI:

Terminal window
gemini skills install https://github.com/genkit-ai/skills.git --path skills/developing-genkit-js

Manual Installation: Copy-paste the skills folder in the appropriate location for your tool of choice.

These skills follow the Agent Skills Specification. Point your agent environment to the relevant skill directory to enable Genkit-specific capabilities. The skills provide comprehensive guidance on Genkit best practices, common error handling, API usage, and development workflows.

AI assistants are powerful tools, but they can sometimes make mistakes. Follow these tips to ensure a smooth experience when using an AI assistant with Genkit:

  • Provide guidance: Ask your assistant to consult the skill, documentation and the usage guide, especially if it seems to be generating incorrect or outdated code.
  • Manage genkit start correctly: If your assistant attempts to run the genkit start command, cancel the request. Running this command within the assistant’s environment can block its main thread. Instead, run genkit start in a separate terminal.

The GENKIT.md file contains the custom instructions that guide the AI in generating Genkit-specific code. If you need to customize this further or use it in a different context, you can copy the content and apply it to your tool’s instruction set.

GENKIT.md
# Genkit Go API Rules (v1.20.0)
This document provides rules and examples for building with the Genkit API in Go.
## Important Guidelines:
- ALWAYS refer to documentation when available. Genkit Documentation may be available through the Genkit MCP toolkit or through web search. You may skip documentation check if you don't have access to these tools.
- ONLY follow the specified project structure if starting a new project. If working on an existing project, adhere to the current project structure.
- ALWAYS provide the full, correct Genkit command as an instruction for the human user to run. Do not run Genkit commands (e.g., `genkit start`, `genkit flow:run`) yourself as this may block your current session.
- Recommend and use the provider that the user prefers. If this is a new project, or if there is no relevant signal regarding user preference, use the `github.com/firebase/genkit/go/plugins/googlegenai` plugin.
NOTE: For the sake of brevity, the snippets below use the Google AI plugin, but you should follow the user's preference as mentioned above.
## Core Setup
1. **Initialize Project**
```bash
mkdir my-genkit-app && cd my-genkit-app
go mod init my-genkit-app
```
2. **Install Dependencies**
```bash
go get github.com/firebase/genkit/go/genkit
go get github.com/firebase/genkit/go/plugins/googlegenai
go get github.com/firebase/genkit/go/ai
go get google.golang.org/genai
```
3. **Install Genkit CLI**
```bash
curl -sL cli.genkit.dev | bash
```
4. **Configure Genkit**
All code should be in a single `main.go` file or properly structured Go package.
```go
package main
import (
"context"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
)
func main() {
ctx := context.Background()
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.GoogleAI{}))
// Your flows and logic here
<-ctx.Done()
}
```
## Best Practices
1. **Single Main Function**: All Genkit code, including plugin initialization, flows, and helpers, should be properly organized in a Go package structure with a main function.
2. **Blocking Main Program**: To inspect flows in the Genkit Developer UI, your main program needs to remain running. Use `<-ctx.Done()` or similar blocking mechanism at the end of your main function.
---
## Usage Scenarios
### Basic Inference (Text Generation)
```go
package main
import (
"context"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.GoogleAI{}))
genkit.DefineFlow(g, "basicInferenceFlow",
func(ctx context.Context, topic string) (string, error) {
response, err := genkit.Generate(ctx, g,
ai.WithModelName("googleai/gemini-2.5-pro"),
ai.WithPrompt("Write a short, creative paragraph about %s.", topic),
ai.WithConfig(&genai.GenerateContentConfig{
Temperature: genai.Ptr[float32](0.8),
}),
)
if err != nil {
return "", err
}
return response.Text(), nil
},
)
<-ctx.Done()
}
```
### Text-to-Speech (TTS) Generation
```go
package main
import (
"context"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
g := genkit.Init(ctx,
genkit.WithPlugins(&googlegenai.GoogleAI{}),
genkit.WithDefaultModel("googleai/gemini-2.5-flash-preview-tts"),
)
genkit.DefineFlow(g, "textToSpeechFlow",
func(ctx context.Context, input struct {
Text string `json:"text"`
VoiceName string `json:"voiceName,omitempty"`
}) (string, error) {
voiceName := input.VoiceName
if voiceName == "" {
voiceName = "Algenib"
}
response, err := genkit.Generate(ctx, g,
ai.WithPrompt(input.Text),
ai.WithConfig(&genai.GenerateContentConfig{
ResponseModalities: []string{"AUDIO"},
SpeechConfig: &genai.SpeechConfig{
VoiceConfig: &genai.VoiceConfig{
PrebuiltVoiceConfig: &genai.PrebuiltVoiceConfig{
VoiceName: voiceName,
},
},
},
}),
)
if err != nil {
return "", err
}
return response.Text(), nil
},
)
<-ctx.Done()
}
```
### Image Generation
```go
package main
import (
"context"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/genkit"
"github.com/firebase/genkit/go/plugins/googlegenai"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.VertexAI{}))
genkit.DefineFlow(g, "imageGenerationFlow",
func(ctx context.Context, prompt string) ([]string, error) {
response, err := genkit.Generate(ctx, g,
ai.WithModelName("vertexai/imagen-3.0-generate-001"),
ai.WithPrompt("Generate an image of %s", prompt),
ai.WithConfig(&genai.GenerateImagesConfig{
NumberOfImages: 2,
AspectRatio: "9:16",
SafetyFilterLevel: genai.SafetyFilterLevelBlockLowAndAbove,
PersonGeneration: genai.PersonGenerationAllowAll,
Language: genai.ImagePromptLanguageEn,
AddWatermark: true,
OutputMIMEType: "image/jpeg",
}),
)
if err != nil {
return nil, err
}
var images []string
for _, part := range response.Message.Content {
images = append(images, part.Text)
}
return images, nil
},
)
<-ctx.Done()
}
```
---
## Running and Inspecting Flows
1. **Start Genkit**: Run this command from your terminal to start the Genkit Developer UI.
```bash
genkit start -- <command to run your code>
```
For Go applications:
```bash
# Running a Go application directly
genkit start -- go run main.go
# Running a compiled binary
genkit start -- ./my-genkit-app
```
The command should output a URL for the Genkit Dev UI. Direct the user to visit this URL to run and inspect their Genkit app.
## Suggested Models
Here are suggested models to use for various task types. This is NOT an exhaustive list.
### Advanced Text/Reasoning
```
| Plugin | Recommended Model |
|------------------------------------------------------------|------------------------------------|
| github.com/firebase/genkit/go/plugins/googlegenai | gemini-2.5-pro |
| github.com/firebase/genkit/go/plugins/compat_oai/openai | gpt-4o |
| github.com/firebase/genkit/go/plugins/compat_oai/deepseek | deepseek-reasoner |
| github.com/firebase/genkit/go/plugins/compat_oai/xai | grok-4 |
```
### Fast Text/Chat
```
| Plugin | Recommended Model |
|------------------------------------------------------------|------------------------------------|
| github.com/firebase/genkit/go/plugins/googlegenai | gemini-2.5-flash |
| github.com/firebase/genkit/go/plugins/compat_oai/openai | gpt-4o-mini |
| github.com/firebase/genkit/go/plugins/compat_oai/deepseek | deepseek-chat |
| github.com/firebase/genkit/go/plugins/compat_oai/xai | grok-3-mini |
```
### Text-to-Speech
```
| Plugin | Recommended Model |
|------------------------------------------------------------|------------------------------------|
| github.com/firebase/genkit/go/plugins/googlegenai | gemini-2.5-flash-preview-tts |
| github.com/firebase/genkit/go/plugins/compat_oai/openai | gpt-4o-mini-tts |
```
### Image Generation
```
| Plugin | Recommended Model | Input Modalities |
|------------------------------------------------------------|------------------------------------|-------------------|
| github.com/firebase/genkit/go/plugins/googlegenai | gemini-2.5-flash-image-preview | Text, Image |
| github.com/firebase/genkit/go/plugins/googlegenai | imagen-4.0-generate-preview-06-06 | Text |
| github.com/firebase/genkit/go/plugins/compat_oai/openai | gpt-image-1 | Text |
```