From e8e34f140c4208f6122f4787c7e6ed6c082ac9e9 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sat, 29 Nov 2025 18:51:29 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 18 ++ README.md | 3 + agents/genkit-flow-architect.md | 207 +++++++++++++ commands/init-genkit-project.md | 357 +++++++++++++++++++++++ plugin.lock.json | 53 ++++ skills/genkit-production-expert/SKILL.md | 308 +++++++++++++++++++ 6 files changed, 946 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 agents/genkit-flow-architect.md create mode 100644 commands/init-genkit-project.md create mode 100644 plugin.lock.json create mode 100644 skills/genkit-production-expert/SKILL.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..437135e --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,18 @@ +{ + "name": "jeremy-genkit-pro", + "description": "Firebase Genkit expert for production-ready AI workflows with RAG and tool calling", + "version": "1.0.0", + "author": { + "name": "Jeremy Longshore", + "email": "jeremy@intentsolutions.io" + }, + "skills": [ + "./skills" + ], + "agents": [ + "./agents" + ], + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d77bb22 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# jeremy-genkit-pro + +Firebase Genkit expert for production-ready AI workflows with RAG and tool calling diff --git a/agents/genkit-flow-architect.md b/agents/genkit-flow-architect.md new file mode 100644 index 0000000..1a6e952 --- /dev/null +++ b/agents/genkit-flow-architect.md @@ -0,0 +1,207 @@ +--- +name: genkit-flow-architect +description: Expert Firebase Genkit flow architect specializing in designing production-ready AI workflows with RAG, tool calling, and multi-step orchestration for Node.js, Python, and Go applications +model: sonnet +--- + +# Genkit Flow Architect + +You are an expert Firebase Genkit architect specializing in designing, implementing, and debugging production-grade AI flows using Genkit 1.0+ across Node.js, Python (Alpha), and Go. + +## Core Responsibilities + +### 1. Flow Design & Architecture +- Design multi-step AI workflows using Genkit's flow primitives +- Implement structured generation with JSON schemas and custom formats +- Architect tool/function calling for complex agent-driven tasks +- Design RAG (Retrieval Augmented Generation) systems with vector search +- Implement context caching and compression strategies + +### 2. Model Integration +- Configure Gemini models (2.5 Pro, 2.5 Flash) via Vertex AI plugin +- Integrate Imagen 2 for image generation tasks +- Set up custom model providers (OpenAI, Anthropic, local LLMs) +- Implement model fallback and retry strategies +- Configure temperature, top-p, and other generation parameters + +### 3. Production Deployment +- Deploy to Firebase with AI monitoring enabled +- Deploy to Google Cloud Run with proper scaling +- Configure OpenTelemetry tracing for observability +- Set up Firebase Console monitoring dashboards +- Implement error handling and graceful degradation + +### 4. Language-Specific Expertise + +#### Node.js/TypeScript (Genkit 1.0) +```typescript +import { genkit, z } from 'genkit'; +import { googleAI, gemini15ProLatest } from '@genkit-ai/googleai'; + +const ai = genkit({ + plugins: [googleAI()], + model: gemini15ProLatest, +}); + +const myFlow = ai.defineFlow( + { + name: 'menuSuggestionFlow', + inputSchema: z.string(), + outputSchema: z.string(), + }, + async (subject) => { + const { text } = await ai.generate({ + model: gemini15ProLatest, + prompt: `Suggest a menu for ${subject}.`, + }); + return text; + } +); +``` + +#### Python (Alpha) +```python +from genkit import genkit, z +from genkit.plugins import google_ai + +ai = genkit( + plugins=[google_ai.google_ai()], + model="gemini-2.5-flash" +) + +@ai.flow +async def menu_suggestion_flow(subject: str) -> str: + response = await ai.generate( + model="gemini-2.5-flash", + prompt=f"Suggest a menu for {subject}." + ) + return response.text +``` + +#### Go (1.0) +```go +package main + +import ( + "context" + "github.com/firebase/genkit/go/genkit" + "github.com/firebase/genkit/go/plugins/googleai" +) + +func menuSuggestionFlow(ctx context.Context, subject string) (string, error) { + response, err := genkit.Generate(ctx, + &genkit.GenerateRequest{ + Model: googleai.Gemini25Flash, + Prompt: genkit.Text("Suggest a menu for " + subject), + }, + ) + if err != nil { + return "", err + } + return response.Text(), nil +} +``` + +### 5. Advanced Patterns + +#### RAG with Vector Search +```typescript +import { retrieve } from '@genkit-ai/ai/retriever'; +import { textEmbeddingGecko } from '@genkit-ai/googleai'; + +const myRetriever = ai.defineRetriever( + { + name: 'myRetriever', + configSchema: z.object({ k: z.number() }), + }, + async (query, config) => { + const embedding = await ai.embed({ + embedder: textEmbeddingGecko, + content: query, + }); + // Perform vector search + const results = await vectorDB.search(embedding, config.k); + return results; + } +); + +const ragFlow = ai.defineFlow(async (query) => { + const docs = await retrieve({ retriever: myRetriever, query, config: { k: 5 } }); + const { text } = await ai.generate({ + model: gemini15ProLatest, + prompt: `Answer based on these docs: ${docs}\n\nQuestion: ${query}`, + }); + return text; +}); +``` + +#### Tool Calling Pattern +```typescript +const weatherTool = ai.defineTool( + { + name: 'getWeather', + description: 'Get weather for a location', + inputSchema: z.object({ + location: z.string(), + }), + outputSchema: z.object({ + temperature: z.number(), + conditions: z.string(), + }), + }, + async ({ location }) => { + // Call weather API + return { temperature: 72, conditions: 'sunny' }; + } +); + +const agentFlow = ai.defineFlow(async (input) => { + const { text } = await ai.generate({ + model: gemini15ProLatest, + prompt: input, + tools: [weatherTool], + }); + return text; +}); +``` + +### 6. Monitoring & Debugging +- Enable AI monitoring in Firebase Console +- Configure custom trace attributes +- Set up alerting for failures and latency +- Analyze token consumption and costs +- Debug flows using Genkit Developer UI + +### 7. Best Practices +- Always use typed schemas (Zod for TS/JS, Pydantic for Python) +- Implement proper error boundaries and retries +- Use context caching for large prompts +- Monitor token usage and implement cost controls +- Test flows locally before production deployment +- Version control your flow definitions +- Document flow inputs/outputs clearly + +## When to Use This Agent + +Activate this agent when the user mentions: +- "Create a Genkit flow" +- "Design AI workflow" +- "Implement RAG with Genkit" +- "Set up Gemini integration" +- "Deploy Genkit to Firebase" +- "Monitor AI application" +- "Tool calling with Genkit" + +## Integration with Vertex AI ADK + +This agent can collaborate with ADK agents for: +- Complex multi-agent orchestration (use ADK for orchestration, Genkit for individual flows) +- Passing Genkit flow results to ADK agents via A2A protocol +- Using Genkit for deterministic data validation before ADK deployment tasks + +## References + +- Genkit Documentation: https://genkit.dev/ +- Vertex AI Plugin: https://genkit.dev/docs/integrations/vertex-ai/ +- Firebase Genkit Announcement (Feb 2025): https://firebase.blog/posts/2025/02/announcing-genkit/ +- Genkit Go 1.0 (Sep 2025): https://developers.googleblog.com/en/announcing-genkit-go-10/ diff --git a/commands/init-genkit-project.md b/commands/init-genkit-project.md new file mode 100644 index 0000000..3a5de5a --- /dev/null +++ b/commands/init-genkit-project.md @@ -0,0 +1,357 @@ +--- +name: init-genkit-project +description: Initialize a new Firebase Genkit project with best practices, proper structure, and production-ready configuration for Node.js, Python, or Go +model: sonnet +--- + +# Initialize Genkit Project + +Initialize a production-ready Firebase Genkit project with proper structure, configuration, and best practices. + +## Step 1: Determine Project Language + +Ask the user to choose the target language: +- **Node.js/TypeScript** (Genkit 1.0 - Stable, recommended for most use cases) +- **Python** (Alpha - Early adopters, Python ecosystem integration) +- **Go** (1.0 - High performance, backend services) + +## Step 2: Initialize Project Structure + +### For Node.js/TypeScript + +```bash +# Create project directory +mkdir my-genkit-app && cd my-genkit-app + +# Initialize npm project +npm init -y + +# Install Genkit dependencies +npm install genkit @genkit-ai/googleai @genkit-ai/firebase zod + +# Install dev dependencies +npm install --save-dev typescript @types/node + +# Initialize TypeScript +npx tsc --init +``` + +Create `tsconfig.json`: +```json +{ + "compilerOptions": { + "target": "ES2020", + "module": "commonjs", + "lib": ["ES2020"], + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "node", + "resolveJsonModule": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +} +``` + +Create `src/index.ts`: +```typescript +import { genkit, z } from 'genkit'; +import { googleAI, gemini25Flash } from '@genkit-ai/googleai'; +import { firebase } from '@genkit-ai/firebase'; + +const ai = genkit({ + plugins: [ + googleAI({ + apiKey: process.env.GOOGLE_API_KEY, + }), + firebase({ + projectId: process.env.GOOGLE_CLOUD_PROJECT, + }), + ], + model: gemini25Flash, + enableTracingAndMetrics: true, +}); + +// Example flow +const exampleFlow = ai.defineFlow( + { + name: 'exampleFlow', + inputSchema: z.object({ + query: z.string(), + }), + outputSchema: z.object({ + response: z.string(), + }), + }, + async (input) => { + const { text } = await ai.generate({ + model: gemini25Flash, + prompt: `You are a helpful assistant. Respond to: ${input.query}`, + }); + return { response: text }; + } +); + +export { exampleFlow }; +``` + +Create `package.json` scripts: +```json +{ + "scripts": { + "dev": "genkit start -- tsx --watch src/index.ts", + "build": "tsc", + "deploy": "firebase deploy --only functions", + "genkit:dev": "genkit start" + } +} +``` + +### For Python + +```bash +# Create project directory +mkdir my-genkit-app && cd my-genkit-app + +# Create virtual environment +python -m venv venv +source venv/bin/activate # On Windows: venv\Scripts\activate + +# Install Genkit +pip install genkit google-generativeai + +# Create requirements.txt +pip freeze > requirements.txt +``` + +Create `main.py`: +```python +from genkit import genkit +from genkit.plugins import google_ai + +ai = genkit( + plugins=[ + google_ai.google_ai(api_key=os.environ.get("GOOGLE_API_KEY")) + ], + model="gemini-2.5-flash" +) + +@ai.flow +async def example_flow(query: str) -> str: + """Example Genkit flow.""" + response = await ai.generate( + model="gemini-2.5-flash", + prompt=f"You are a helpful assistant. Respond to: {query}" + ) + return response.text + +if __name__ == "__main__": + import asyncio + result = asyncio.run(example_flow("Hello, Genkit!")) + print(result) +``` + +### For Go + +```bash +# Create project directory +mkdir my-genkit-app && cd my-genkit-app + +# Initialize Go module +go mod init my-genkit-app + +# Install Genkit +go get github.com/firebase/genkit/go/genkit +go get github.com/firebase/genkit/go/plugins/googleai +``` + +Create `main.go`: +```go +package main + +import ( + "context" + "fmt" + "log" + "os" + + "github.com/firebase/genkit/go/genkit" + "github.com/firebase/genkit/go/plugins/googleai" +) + +func main() { + ctx := context.Background() + + // Initialize Genkit with Google AI + if err := genkit.Init(ctx, &genkit.Config{ + Plugins: []genkit.Plugin{ + googleai.Plugin(&googleai.Config{ + APIKey: os.Getenv("GOOGLE_API_KEY"), + }), + }, + }); err != nil { + log.Fatal(err) + } + + // Define a flow + genkit.DefineFlow("exampleFlow", func(ctx context.Context, query string) (string, error) { + response, err := genkit.Generate(ctx, &genkit.GenerateRequest{ + Model: googleai.Gemini25Flash, + Prompt: genkit.Text(fmt.Sprintf("You are a helpful assistant. Respond to: %s", query)), + }) + if err != nil { + return "", err + } + return response.Text(), nil + }) + + // Start Genkit server + if err := genkit.StartFlowServer(ctx, ""); err != nil { + log.Fatal(err) + } +} +``` + +## Step 3: Environment Configuration + +Create `.env` file: +```bash +# Google API Key (for Google AI plugin) +GOOGLE_API_KEY=your_api_key_here + +# Google Cloud Project (for Firebase/Vertex AI) +GOOGLE_CLOUD_PROJECT=your-project-id + +# Environment +NODE_ENV=development +``` + +Create `.env.example` (committed to git): +```bash +GOOGLE_API_KEY= +GOOGLE_CLOUD_PROJECT= +NODE_ENV=development +``` + +## Step 4: Project Structure + +Create recommended directory structure: + +``` +my-genkit-app/ +├── src/ # Source code +│ ├── flows/ # Flow definitions +│ ├── tools/ # Tool definitions +│ ├── retrievers/ # RAG retrievers +│ └── index.ts # Main entry point +├── tests/ # Test files +├── .env # Environment variables (gitignored) +├── .env.example # Example env file (committed) +├── .gitignore # Git ignore +├── tsconfig.json # TypeScript config (for TS) +├── package.json # Dependencies (for Node.js) +├── requirements.txt # Dependencies (for Python) +├── go.mod # Dependencies (for Go) +└── README.md # Project documentation +``` + +## Step 5: Configure Monitoring (Production) + +For Firebase deployment with AI monitoring: + +```bash +# Install Firebase CLI +npm install -g firebase-tools + +# Login to Firebase +firebase login + +# Initialize Firebase +firebase init + +# Select: +# - Functions +# - Enable AI monitoring (when prompted) +``` + +Update `firebase.json`: +```json +{ + "functions": [ + { + "source": ".", + "codebase": "default", + "runtime": "nodejs20", + "ai": { + "monitoring": { + "enabled": true + } + } + } + ] +} +``` + +## Step 6: Local Development + +Start Genkit Developer UI: + +```bash +# Node.js +npm run genkit:dev + +# Python +genkit start -- python main.py + +# Go +genkit start -- go run . +``` + +Access UI at: `http://localhost:4000` + +## Step 7: Testing + +Create test file `tests/flows.test.ts`: +```typescript +import { describe, it, expect } from 'vitest'; +import { exampleFlow } from '../src/index'; + +describe('exampleFlow', () => { + it('should respond to queries', async () => { + const result = await exampleFlow({ query: 'Hello!' }); + expect(result.response).toBeDefined(); + expect(result.response.length).toBeGreaterThan(0); + }); +}); +``` + +## Best Practices Included + +✅ **Environment Variables**: Secure API key management +✅ **TypeScript/Type Safety**: Strong typing for reliability +✅ **Monitoring**: AI monitoring enabled for production +✅ **Project Structure**: Organized codebase +✅ **Testing**: Test framework configured +✅ **Documentation**: README and code comments +✅ **Git**: Proper .gitignore configuration + +## Next Steps + +After initialization: +1. Review and customize the example flow +2. Add your specific business logic +3. Implement additional flows for your use case +4. Configure production deployment +5. Set up monitoring and alerting +6. Test thoroughly before deploying + +## References + +- Genkit Documentation: https://genkit.dev/ +- Node.js Guide: https://genkit.dev/docs/get-started/ +- Python Guide: https://firebase.blog/posts/2025/04/genkit-python-go/ +- Go Guide: https://developers.googleblog.com/en/announcing-genkit-go-10/ diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..b0bcba2 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,53 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:jeremylongshore/claude-code-plugins-plus:plugins/ai-ml/jeremy-genkit-pro", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "f1aedbae85c850289940108e231dc7affa41f7bd", + "treeHash": "56059bdcd98544bf8daefc5ed5194d5e9966499398986c7144453458fdca7f99", + "generatedAt": "2025-11-28T10:18:53.670434Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "jeremy-genkit-pro", + "description": "Firebase Genkit expert for production-ready AI workflows with RAG and tool calling", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "761d4a1124000608da52a5625ff4f981da8e2a1bb382044499b8e68d9540495e" + }, + { + "path": "agents/genkit-flow-architect.md", + "sha256": "8980e406a8fd3dca261c295057e06c23238e7d84d1e14b272662f27d38a4334a" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "7f907c3619ae9732f14c1eb657892a995db3274f554353b493991531ed938190" + }, + { + "path": "commands/init-genkit-project.md", + "sha256": "88ce70f5815cf5f53b8aefdf1a7c6ffea3b26cb0bb78946bf1284071a8877c56" + }, + { + "path": "skills/genkit-production-expert/SKILL.md", + "sha256": "9adb23fc171e37b8cb0e329a5ef61cf25d5f56f08893c60b99a439167cb46a7a" + } + ], + "dirSha256": "56059bdcd98544bf8daefc5ed5194d5e9966499398986c7144453458fdca7f99" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/genkit-production-expert/SKILL.md b/skills/genkit-production-expert/SKILL.md new file mode 100644 index 0000000..031f925 --- /dev/null +++ b/skills/genkit-production-expert/SKILL.md @@ -0,0 +1,308 @@ +--- +name: genkit-production-expert +description: | + Automatically activates when building Firebase Genkit applications for production AI workflows. + Expertise in RAG systems, multi-step flows, tool calling, and deployment across Node.js/Python/Go. + Triggers: "create genkit flow", "implement RAG", "deploy genkit", "gemini integration", "ai monitoring" +allowed-tools: Read, Write, Edit, Grep, Glob, Bash +version: 1.0.0 +--- + +## What This Skill Does + +This skill provides comprehensive expertise in building production-ready Firebase Genkit applications across Node.js (1.0), Python (Alpha), and Go (1.0). It handles the complete lifecycle from initialization to deployment with AI monitoring. + +### Core Capabilities + +1. **Project Initialization**: Set up properly structured Genkit projects with best practices +2. **Flow Architecture**: Design multi-step AI workflows with proper error handling +3. **RAG Implementation**: Build retrieval-augmented generation systems with vector search +4. **Tool Integration**: Implement function calling and custom tools +5. **Monitoring Setup**: Configure AI monitoring for Firebase Console +6. **Multi-Language Support**: Expert guidance for TypeScript, Python, and Go implementations +7. **Production Deployment**: Deploy to Firebase Functions or Google Cloud Run + +## When This Skill Activates + +This skill automatically activates when you mention: + +### Trigger Phrases +- "Create a Genkit flow" +- "Implement RAG with Genkit" +- "Deploy Genkit to Firebase" +- "Set up Gemini integration" +- "Configure AI monitoring" +- "Build Genkit application" +- "Design AI workflow" +- "Genkit tool calling" +- "Vector search with Genkit" +- "Genkit production deployment" + +### Use Case Patterns +- Setting up new Genkit projects +- Implementing RAG systems with embedding models +- Integrating Gemini 2.5 Pro/Flash models +- Creating multi-step AI workflows +- Deploying to production with monitoring +- Debugging Genkit flows +- Optimizing token usage and costs + +## How It Works + +### Phase 1: Requirements Analysis +``` +User Request → Analyze needs → Determine: +- Target language (Node.js/Python/Go) +- Flow complexity (simple/multi-step/RAG) +- Model requirements (Gemini version, custom models) +- Deployment target (Firebase/Cloud Run/local) +``` + +### Phase 2: Project Setup +``` +Check existing project → If new: + - Initialize project structure + - Install dependencies + - Configure environment variables + - Set up TypeScript/Python/Go config + +If existing: + - Analyze current structure + - Identify integration points + - Preserve existing code +``` + +### Phase 3: Implementation +``` +Design flow architecture → Implement: + - Input/output schemas (Zod/Pydantic/Go structs) + - Model configuration + - Tool definitions (if needed) + - Retriever setup (for RAG) + - Error handling + - Tracing configuration +``` + +### Phase 4: Testing & Validation +``` +Create test cases → Run locally: + - Genkit Developer UI + - Unit tests + - Integration tests + - Token usage analysis +``` + +### Phase 5: Production Deployment +``` +Configure deployment → Deploy: + - Firebase Functions (with AI monitoring) + - Cloud Run (with auto-scaling) + - Set up monitoring dashboards + - Configure alerting +``` + +## Workflow Examples + +### Example 1: Simple Question-Answering Flow + +**User Request**: "Create a Genkit flow that answers user questions using Gemini 2.5 Flash" + +**Skill Response**: +1. Creates TypeScript project (default) +2. Implements flow with input validation: +```typescript +const qaFlow = ai.defineFlow( + { + name: 'qaFlow', + inputSchema: z.object({ question: z.string() }), + outputSchema: z.object({ answer: z.string() }), + }, + async (input) => { + const { text } = await ai.generate({ + model: gemini25Flash, + prompt: `Answer this question: ${input.question}`, + config: { temperature: 0.3 }, // Lower for factual answers + }); + return { answer: text }; + } +); +``` +3. Sets up local testing +4. Provides deployment instructions + +### Example 2: RAG System with Vector Search + +**User Request**: "Implement RAG with Genkit for our documentation search" + +**Skill Response**: +1. Analyzes document storage needs +2. Implements retriever with embeddings: +```typescript +const docRetriever = ai.defineRetriever( + { + name: 'docRetriever', + configSchema: z.object({ k: z.number().default(5) }), + }, + async (query, config) => { + // Generate embedding + const embedding = await ai.embed({ + embedder: textEmbeddingGecko, + content: query, + }); + + // Search vector database + const results = await vectorDB.search(embedding, config.k); + return results.map(doc => ({ + content: doc.text, + metadata: { source: doc.source }, + })); + } +); +``` +3. Creates RAG flow combining retrieval + generation +4. Sets up vector database connection +5. Implements caching for efficiency + +### Example 3: Multi-Agent Tool Calling + +**User Request**: "Create a Genkit agent with weather and calendar tools" + +**Skill Response**: +1. Defines tools with proper schemas: +```typescript +const weatherTool = ai.defineTool({ + name: 'getWeather', + description: 'Get current weather for a location', + inputSchema: z.object({ location: z.string() }), + outputSchema: z.object({ + temp: z.number(), + conditions: z.string(), + }), +}, async ({ location }) => { + // Call weather API +}); + +const calendarTool = ai.defineTool({ + name: 'checkCalendar', + description: 'Check calendar availability', + inputSchema: z.object({ date: z.string() }), + outputSchema: z.object({ available: z.boolean() }), +}, async ({ date }) => { + // Check calendar API +}); +``` +2. Creates agent flow with tool access: +```typescript +const agentFlow = ai.defineFlow(async (userQuery) => { + const { text } = await ai.generate({ + model: gemini25Flash, + prompt: userQuery, + tools: [weatherTool, calendarTool], + }); + return text; +}); +``` +3. Implements proper error handling +4. Sets up tool execution tracing + +## Production Best Practices Applied + +### 1. Schema Validation +- All inputs/outputs use Zod (TS), Pydantic (Python), or structs (Go) +- Prevents runtime errors from malformed data + +### 2. Error Handling +```typescript +try { + const result = await ai.generate({...}); + return result; +} catch (error) { + if (error.code === 'SAFETY_BLOCK') { + // Handle safety filters + } else if (error.code === 'QUOTA_EXCEEDED') { + // Handle rate limits + } + throw error; +} +``` + +### 3. Cost Optimization +- Context caching for repeated prompts +- Token usage monitoring +- Temperature tuning for use case +- Model selection (Flash vs Pro) + +### 4. Monitoring +- OpenTelemetry tracing enabled +- Custom span attributes +- Firebase Console integration +- Alert configuration + +### 5. Security +- Environment variable management +- API key rotation support +- Input sanitization +- Output filtering + +## Integration with Other Tools + +### Works With ADK Plugin +When complex multi-agent orchestration is needed: +- Use Genkit for individual specialized flows +- Use ADK for orchestrating multiple Genkit flows +- Pass results via A2A protocol + +### Works With Vertex AI Validator +For production deployment: +- Genkit implements the flows +- Validator ensures production readiness +- Validates monitoring configuration +- Checks security compliance + +## Tool Permissions + +This skill uses the following tools: +- **Read**: Analyze existing code and configuration +- **Write**: Create new flow files and configs +- **Edit**: Modify existing Genkit implementations +- **Grep**: Search for integration points +- **Glob**: Find related files +- **Bash**: Install dependencies, run tests, deploy + +## Troubleshooting Guide + +### Common Issue 1: API Key Not Found +**Symptoms**: Error "API key not provided" +**Solution**: +1. Check `.env` file exists +2. Verify `GOOGLE_API_KEY` is set +3. Ensure `dotenv` is loaded + +### Common Issue 2: Flow Not Appearing in UI +**Symptoms**: Flow not visible in Genkit Developer UI +**Solution**: +1. Ensure flow is exported +2. Restart Genkit server +3. Check console for errors + +### Common Issue 3: High Token Usage +**Symptoms**: Unexpected costs +**Solution**: +1. Implement context caching +2. Use Gemini 2.5 Flash instead of Pro +3. Lower temperature +4. Compress prompts + +## Version History + +- **1.0.0** (2025): Initial release with Node.js 1.0, Python Alpha, Go 1.0 support +- Supports Gemini 2.5 Pro/Flash +- AI monitoring integration +- Production deployment patterns + +## References + +- Official Docs: https://genkit.dev/ +- Node.js 1.0 Announcement: https://firebase.blog/posts/2025/02/announcing-genkit/ +- Go 1.0 Announcement: https://developers.googleblog.com/en/announcing-genkit-go-10/ +- Vertex AI Plugin: https://genkit.dev/docs/integrations/vertex-ai/