| name | genkit-architect |
| description | Expert guidance on building AI features with Google Genkit (v1.21.0+) |
Genkit Architect
This skill provides patterns and best practices for implementing Genkit flows, models, and tools.
Folder Structure (Backend)
Recommended structure for a Node.js/Express app:
backend/
āāā src/
ā āāā flows/ # Define flows here
ā ā āāā email-classifier.ts
ā ā āāā rfq-extraction.ts
ā āāā genkit.config.ts # Main configuration
ā āāā index.ts # App entry point
1. Defining a Flow
Use defineFlow with Zod schemas for strict type safety.
import { defineFlow } from '@genkit-ai/flow';
import { z } from 'zod';
import { generate } from '@genkit-ai/ai';
import { googleAI, gemini15Flash } from '@genkit-ai/googleai';
export const myFlow = defineFlow(
{
name: 'myFlow',
inputSchema: z.object({ topic: z.string() }),
outputSchema: z.object({ advice: z.string() }),
},
async (input) => {
const llmResponse = await generate({
model: gemini15Flash,
prompt: `Give advice about ${input.topic}`,
config: { temperature: 0.7 },
});
return { advice: llmResponse.text() };
}
);
2. Configuration (genkit.config.ts)
import { configureGenkit } from '@genkit-ai/core';
import { googleAI } from '@genkit-ai/googleai';
import { dotprompt } from '@genkit-ai/dotprompt';
export default configureGenkit({
plugins: [
googleAI(),
dotprompt(),
],
logLevel: 'debug',
enableTracingAndMetrics: true,
});
3. Invoking Flows
Inside your Express routes or services:
import { runFlow } from '@genkit-ai/flow';
import { myFlow } from './flows/my-flow';
const result = await runFlow(myFlow, { topic: "Node.js" });
console.log(result.advice);
Best Practices
- Zod Everything: Always define input/output schemas. Genkit uses them to validate LLM output.
- Separate Prompts: Use Dotprompt (
.prompt files) for complex prompts to keep code clean.
- Error Handling: Wrap
runFlow in try/catch. Genkit throws structured errors.
- Tracing: Enbale tracing in dev to debug flow modifications.