1.8 KiB
1.8 KiB
Genkit Best Practices
Project Structure
- Organized Layout: Keep flows and tools in separate directories (e.g.,
src/flows,src/tools) to maintain a clean codebase. - Index Exports: Use
index.tsfiles to export flows and tools, making it easier to import them into your main configuration.
Model Selection (Google AI)
- Gemini Models: If using Google AI, ALWAYS use the latest generation (
gemini-3-*orgemini-2.5-*).- NEVER use
gemini-2.0-*orgemini-1.5-*series, as they are decommissioned and won't work. - Recommended:
gemini-2.5-flashorgemini-3-flash-previewfor general use,gemini-3.1-pro-previewfor complex tasks.
- NEVER use
Model Selection (Other Providers)
- Consult Documentation: For other providers (OpenAI, Anthropic, etc.), refer to the provider's official documentation for the latest recommended model versions.
Schema Definition
- Use
zfromgenkit: Always importzfrom thegenkitpackage to ensure compatibility.import { z } from "genkit"; - Descriptive Schemas: Use
.describe()on Zod fields. LLMs use these descriptions to understand how to populate the fields.
Flow & Tool Design
- Modularize: Keep flows and tools in separate files/modules and import them into your main Genkit configuration.
- Single Responsibility: Tools should do one thing well. Complex logic should be broken down.
Configuration
- Environment Variables: Store sensitive keys (like API keys) in environment variables or
.envfiles. Do not hardcode them.
Development
- Use Dev Mode: Run your app with
genkit start -- <start cmd>to enable the Developer UI. - It is recommended to configure a watcher to auto-reload your app (e.g.
node --watchortsx --watch)