@intentsolutionsio/jeremy-genkit-pro 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,356 @@
1
+ ---
2
+ name: init-genkit-project
3
+ description: Initialize a new Firebase Genkit project with best practices, proper...
4
+ model: sonnet
5
+ ---
6
+ # Initialize Genkit Project
7
+
8
+ Initialize a production-ready Firebase Genkit project with proper structure, configuration, and best practices.
9
+
10
+ ## Step 1: Determine Project Language
11
+
12
+ Ask the user to choose the target language:
13
+ - **Node.js/TypeScript** (Genkit 1.0 - Stable, recommended for most use cases)
14
+ - **Python** (Alpha - Early adopters, Python ecosystem integration)
15
+ - **Go** (1.0 - High performance, backend services)
16
+
17
+ ## Step 2: Initialize Project Structure
18
+
19
+ ### For Node.js/TypeScript
20
+
21
+ ```bash
22
+ # Create project directory
23
+ mkdir my-genkit-app && cd my-genkit-app
24
+
25
+ # Initialize npm project
26
+ npm init -y
27
+
28
+ # Install Genkit dependencies
29
+ npm install genkit @genkit-ai/googleai @genkit-ai/firebase zod
30
+
31
+ # Install dev dependencies
32
+ npm install --save-dev typescript @types/node
33
+
34
+ # Initialize TypeScript
35
+ npx tsc --init
36
+ ```
37
+
38
+ Create `tsconfig.json`:
39
+ ```json
40
+ {
41
+ "compilerOptions": {
42
+ "target": "ES2020",
43
+ "module": "commonjs",
44
+ "lib": ["ES2020"],
45
+ "outDir": "./dist",
46
+ "rootDir": "./src",
47
+ "strict": true,
48
+ "esModuleInterop": true,
49
+ "skipLibCheck": true,
50
+ "forceConsistentCasingInFileNames": true,
51
+ "moduleResolution": "node",
52
+ "resolveJsonModule": true
53
+ },
54
+ "include": ["src/**/*"],
55
+ "exclude": ["node_modules", "dist"]
56
+ }
57
+ ```
58
+
59
+ Create `src/index.ts`:
60
+ ```typescript
61
+ import { genkit, z } from 'genkit';
62
+ import { googleAI, gemini25Flash } from '@genkit-ai/googleai';
63
+ import { firebase } from '@genkit-ai/firebase';
64
+
65
+ const ai = genkit({
66
+ plugins: [
67
+ googleAI({
68
+ apiKey: process.env.GOOGLE_API_KEY,
69
+ }),
70
+ firebase({
71
+ projectId: process.env.GOOGLE_CLOUD_PROJECT,
72
+ }),
73
+ ],
74
+ model: gemini25Flash,
75
+ enableTracingAndMetrics: true,
76
+ });
77
+
78
+ // Example flow
79
+ const exampleFlow = ai.defineFlow(
80
+ {
81
+ name: 'exampleFlow',
82
+ inputSchema: z.object({
83
+ query: z.string(),
84
+ }),
85
+ outputSchema: z.object({
86
+ response: z.string(),
87
+ }),
88
+ },
89
+ async (input) => {
90
+ const { text } = await ai.generate({
91
+ model: gemini25Flash,
92
+ prompt: `You are a helpful assistant. Respond to: ${input.query}`,
93
+ });
94
+ return { response: text };
95
+ }
96
+ );
97
+
98
+ export { exampleFlow };
99
+ ```
100
+
101
+ Create `package.json` scripts:
102
+ ```json
103
+ {
104
+ "scripts": {
105
+ "dev": "genkit start -- tsx --watch src/index.ts",
106
+ "build": "tsc",
107
+ "deploy": "firebase deploy --only functions",
108
+ "genkit:dev": "genkit start"
109
+ }
110
+ }
111
+ ```
112
+
113
+ ### For Python
114
+
115
+ ```bash
116
+ # Create project directory
117
+ mkdir my-genkit-app && cd my-genkit-app
118
+
119
+ # Create virtual environment
120
+ python -m venv venv
121
+ source venv/bin/activate # On Windows: venv\Scripts\activate
122
+
123
+ # Install Genkit
124
+ pip install genkit google-generativeai
125
+
126
+ # Create requirements.txt
127
+ pip freeze > requirements.txt
128
+ ```
129
+
130
+ Create `main.py`:
131
+ ```python
132
+ from genkit import genkit
133
+ from genkit.plugins import google_ai
134
+
135
+ ai = genkit(
136
+ plugins=[
137
+ google_ai.google_ai(api_key=os.environ.get("GOOGLE_API_KEY"))
138
+ ],
139
+ model="gemini-2.5-flash"
140
+ )
141
+
142
+ @ai.flow
143
+ async def example_flow(query: str) -> str:
144
+ """Example Genkit flow."""
145
+ response = await ai.generate(
146
+ model="gemini-2.5-flash",
147
+ prompt=f"You are a helpful assistant. Respond to: {query}"
148
+ )
149
+ return response.text
150
+
151
+ if __name__ == "__main__":
152
+ import asyncio
153
+ result = asyncio.run(example_flow("Hello, Genkit!"))
154
+ print(result)
155
+ ```
156
+
157
+ ### For Go
158
+
159
+ ```bash
160
+ # Create project directory
161
+ mkdir my-genkit-app && cd my-genkit-app
162
+
163
+ # Initialize Go module
164
+ go mod init my-genkit-app
165
+
166
+ # Install Genkit
167
+ go get github.com/firebase/genkit/go/genkit
168
+ go get github.com/firebase/genkit/go/plugins/googleai
169
+ ```
170
+
171
+ Create `main.go`:
172
+ ```go
173
+ package main
174
+
175
+ import (
176
+ "context"
177
+ "fmt"
178
+ "log"
179
+ "os"
180
+
181
+ "github.com/firebase/genkit/go/genkit"
182
+ "github.com/firebase/genkit/go/plugins/googleai"
183
+ )
184
+
185
+ func main() {
186
+ ctx := context.Background()
187
+
188
+ // Initialize Genkit with Google AI
189
+ if err := genkit.Init(ctx, &genkit.Config{
190
+ Plugins: []genkit.Plugin{
191
+ googleai.Plugin(&googleai.Config{
192
+ APIKey: os.Getenv("GOOGLE_API_KEY"),
193
+ }),
194
+ },
195
+ }); err != nil {
196
+ log.Fatal(err)
197
+ }
198
+
199
+ // Define a flow
200
+ genkit.DefineFlow("exampleFlow", func(ctx context.Context, query string) (string, error) {
201
+ response, err := genkit.Generate(ctx, &genkit.GenerateRequest{
202
+ Model: googleai.Gemini25Flash,
203
+ Prompt: genkit.Text(fmt.Sprintf("You are a helpful assistant. Respond to: %s", query)),
204
+ })
205
+ if err != nil {
206
+ return "", err
207
+ }
208
+ return response.Text(), nil
209
+ })
210
+
211
+ // Start Genkit server
212
+ if err := genkit.StartFlowServer(ctx, ""); err != nil {
213
+ log.Fatal(err)
214
+ }
215
+ }
216
+ ```
217
+
218
+ ## Step 3: Environment Configuration
219
+
220
+ Create `.env` file:
221
+ ```bash
222
+ # Google API Key (for Google AI plugin)
223
+ GOOGLE_API_KEY=your_api_key_here
224
+
225
+ # Google Cloud Project (for Firebase/Vertex AI)
226
+ GOOGLE_CLOUD_PROJECT=your-project-id
227
+
228
+ # Environment
229
+ NODE_ENV=development
230
+ ```
231
+
232
+ Create `.env.example` (committed to git):
233
+ ```bash
234
+ GOOGLE_API_KEY=
235
+ GOOGLE_CLOUD_PROJECT=
236
+ NODE_ENV=development
237
+ ```
238
+
239
+ ## Step 4: Project Structure
240
+
241
+ Create recommended directory structure:
242
+
243
+ ```
244
+ my-genkit-app/
245
+ ├── src/ # Source code
246
+ │ ├── flows/ # Flow definitions
247
+ │ ├── tools/ # Tool definitions
248
+ │ ├── retrievers/ # RAG retrievers
249
+ │ └── index.ts # Main entry point
250
+ ├── tests/ # Test files
251
+ ├── .env # Environment variables (gitignored)
252
+ ├── .env.example # Example env file (committed)
253
+ ├── .gitignore # Git ignore
254
+ ├── tsconfig.json # TypeScript config (for TS)
255
+ ├── package.json # Dependencies (for Node.js)
256
+ ├── requirements.txt # Dependencies (for Python)
257
+ ├── go.mod # Dependencies (for Go)
258
+ └── README.md # Project documentation
259
+ ```
260
+
261
+ ## Step 5: Configure Monitoring (Production)
262
+
263
+ For Firebase deployment with AI monitoring:
264
+
265
+ ```bash
266
+ # Install Firebase CLI
267
+ npm install -g firebase-tools
268
+
269
+ # Login to Firebase
270
+ firebase login
271
+
272
+ # Initialize Firebase
273
+ firebase init
274
+
275
+ # Select:
276
+ # - Functions
277
+ # - Enable AI monitoring (when prompted)
278
+ ```
279
+
280
+ Update `firebase.json`:
281
+ ```json
282
+ {
283
+ "functions": [
284
+ {
285
+ "source": ".",
286
+ "codebase": "default",
287
+ "runtime": "nodejs20",
288
+ "ai": {
289
+ "monitoring": {
290
+ "enabled": true
291
+ }
292
+ }
293
+ }
294
+ ]
295
+ }
296
+ ```
297
+
298
+ ## Step 6: Local Development
299
+
300
+ Start Genkit Developer UI:
301
+
302
+ ```bash
303
+ # Node.js
304
+ npm run genkit:dev
305
+
306
+ # Python
307
+ genkit start -- python main.py
308
+
309
+ # Go
310
+ genkit start -- go run .
311
+ ```
312
+
313
+ Access UI at: `http://localhost:4000`
314
+
315
+ ## Step 7: Testing
316
+
317
+ Create test file `tests/flows.test.ts`:
318
+ ```typescript
319
+ import { describe, it, expect } from 'vitest';
320
+ import { exampleFlow } from '../src/index';
321
+
322
+ describe('exampleFlow', () => {
323
+ it('should respond to queries', async () => {
324
+ const result = await exampleFlow({ query: 'Hello!' });
325
+ expect(result.response).toBeDefined();
326
+ expect(result.response.length).toBeGreaterThan(0);
327
+ });
328
+ });
329
+ ```
330
+
331
+ ## Best Practices Included
332
+
333
+ ✅ **Environment Variables**: Secure API key management
334
+ ✅ **TypeScript/Type Safety**: Strong typing for reliability
335
+ ✅ **Monitoring**: AI monitoring enabled for production
336
+ ✅ **Project Structure**: Organized codebase
337
+ ✅ **Testing**: Test framework configured
338
+ ✅ **Documentation**: README and code comments
339
+ ✅ **Git**: Proper .gitignore configuration
340
+
341
+ ## Next Steps
342
+
343
+ After initialization:
344
+ 1. Review and customize the example flow
345
+ 2. Add your specific business logic
346
+ 3. Implement additional flows for your use case
347
+ 4. Configure production deployment
348
+ 5. Set up monitoring and alerting
349
+ 6. Test thoroughly before deploying
350
+
351
+ ## References
352
+
353
+ - Genkit Documentation: https://genkit.dev/
354
+ - Node.js Guide: https://genkit.dev/docs/get-started/
355
+ - Python Guide: https://firebase.blog/posts/2025/04/genkit-python-go/
356
+ - Go Guide: https://developers.googleblog.com/en/announcing-genkit-go-10/
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@intentsolutionsio/jeremy-genkit-pro",
3
+ "version": "2.1.0",
4
+ "description": "Firebase Genkit expert for production-ready AI workflows with RAG and tool calling",
5
+ "keywords": [
6
+ "firebase",
7
+ "genkit",
8
+ "ai-flows",
9
+ "rag",
10
+ "monitoring",
11
+ "gemini",
12
+ "vertex-ai",
13
+ "vector-search",
14
+ "production-ai",
15
+ "claude-code",
16
+ "claude-plugin",
17
+ "tonsofskills"
18
+ ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/jeremylongshore/claude-code-plugins-plus-skills.git",
22
+ "directory": "plugins/ai-ml/jeremy-genkit-pro"
23
+ },
24
+ "homepage": "https://tonsofskills.com/plugins/jeremy-genkit-pro",
25
+ "bugs": "https://github.com/jeremylongshore/claude-code-plugins-plus-skills/issues",
26
+ "license": "MIT",
27
+ "author": {
28
+ "name": "Jeremy Longshore",
29
+ "email": "jeremy@intentsolutions.io"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "files": [
35
+ "README.md",
36
+ ".claude-plugin",
37
+ "skills",
38
+ "commands",
39
+ "agents"
40
+ ],
41
+ "scripts": {
42
+ "postinstall": "node -e \"console.log(\\\"\\\\n→ This npm package is a tracking/proof artifact. Install the plugin via:\\\\n ccpi install jeremy-genkit-pro\\\\n or /plugin install jeremy-genkit-pro@claude-code-plugins-plus in Claude Code\\\\n\\\")\""
43
+ }
44
+ }
@@ -0,0 +1,81 @@
1
+ ---
2
+ name: genkit-production-expert
3
+ description: |
4
+ Build production Firebase Genkit applications including RAG systems, multi-step flows, and tool calling for Node.js/Python/Go. Deploy to Firebase Functions or Cloud Run with AI monitoring. Use when asked to "create genkit flow" or "implement RAG". Trigger with relevant phrases based on skill purpose.
5
+ allowed-tools: Read, Write, Edit, Grep, Glob, Bash(cmd:*)
6
+ version: 2.1.0
7
+ author: Jeremy Longshore <jeremy@intentsolutions.io>
8
+ license: MIT
9
+ effort: medium
10
+ compatible-with: claude-code, codex, openclaw
11
+ tags: [ai, deployment, monitoring, python]
12
+ ---
13
+ # Genkit Production Expert
14
+
15
+ ## Overview
16
+
17
+ Build production-grade Firebase Genkit applications including RAG systems, multi-step flows, and tool-calling agents for Node.js, Python, and Go. This skill covers the full lifecycle from project scaffolding and schema validation through flow implementation, local testing with the Genkit Developer UI, and deployment to Firebase Functions or Cloud Run with AI monitoring and OpenTelemetry tracing.
18
+
19
+ ## Prerequisites
20
+
21
+ - Node.js 18+ (TypeScript), Python 3.10+ (Python), or Go 1.21+ (Go) runtime
22
+ - Genkit CLI and core packages (`npm install genkit @genkit-ai/googleai` for TypeScript)
23
+ - Google Cloud project with Vertex AI API enabled for Gemini model access
24
+ - Firebase CLI for Firebase Functions deployments (`npm install -g firebase-tools`)
25
+ - Zod (TypeScript), Pydantic (Python), or Go structs for input/output schema validation
26
+ - Environment variables configured for API keys (never hardcoded; use Secret Manager)
27
+
28
+ ## Instructions
29
+
30
+ 1. Analyze the requirements to determine target language, flow complexity (simple, multi-step, or RAG), model selection (Gemini 2.5 Flash vs Pro), and deployment target
31
+ 2. Initialize the project structure with appropriate config files (`tsconfig.json`, `genkit.config.ts`, or equivalent)
32
+ 3. Install Genkit core, provider plugins, and schema validation dependencies
33
+ 4. Define input/output schemas using Zod, Pydantic, or Go structs to enforce type safety at runtime
34
+ 5. Implement the Genkit flow using `ai.defineFlow()` with model configuration, temperature tuning, and token limits
35
+ 6. Add tool definitions using `ai.defineTool()` with scoped schemas for each external capability the flow requires
36
+ 7. For RAG flows: implement a retriever using `ai.defineRetriever()` with embedding generation (text-embedding-gecko) and vector database integration
37
+ 8. Configure error handling for safety blocks (`SAFETY_BLOCK`), quota exceeded (`QUOTA_EXCEEDED`), and provider timeouts
38
+ 9. Enable OpenTelemetry tracing with custom span attributes for cost and latency tracking
39
+ 10. Test locally using the Genkit Developer UI, then deploy to Firebase Functions or Cloud Run with auto-scaling configuration
40
+
41
+ See `${CLAUDE_SKILL_DIR}/references/how-it-works.md` for the phased workflow and `${CLAUDE_SKILL_DIR}/references/production-best-practices-applied.md` for the production checklist.
42
+
43
+ ## Output
44
+
45
+ - Complete Genkit flow implementation with typed schemas and model bindings
46
+ - Tool definitions with Zod/Pydantic-validated inputs and outputs
47
+ - Retriever configuration for RAG flows (embeddings, vector search, context injection)
48
+ - Deployment configuration: Firebase Functions (`firebase.json`) or Cloud Run service YAML
49
+ - Monitoring setup: OpenTelemetry tracing, Firebase Console integration, alert policies
50
+ - Cost optimization report: model selection rationale, token usage estimates, caching strategy
51
+
52
+ ## Error Handling
53
+
54
+ | Error | Cause | Solution |
55
+ |-------|-------|----------|
56
+ | `SAFETY_BLOCK` response | Model safety filters triggered on input or output | Review prompt content; adjust safety settings; add input sanitization before generation |
57
+ | `QUOTA_EXCEEDED` | API rate limit or daily token quota reached | Implement exponential backoff with jitter; request quota increase; cache repeated prompts |
58
+ | Schema validation failure | Runtime input does not match Zod/Pydantic schema | Add descriptive error messages to schema; validate inputs before calling `ai.generate()` |
59
+ | Retriever returns empty results | Vector database query found no matches above similarity threshold | Lower similarity threshold; verify embeddings are indexed; check embedding model version match |
60
+ | Deployment timeout | Cold start exceeds Firebase Functions 60s limit | Increase memory allocation; use Cloud Run for long-running flows; enable min instances > 0 |
61
+
62
+ See `${CLAUDE_SKILL_DIR}/references/errors.md` for additional error scenarios.
63
+
64
+ ## Examples
65
+
66
+ **Scenario 1: Question-Answering Flow** -- Create a Genkit flow using Gemini 2.5 Flash with Zod input/output schemas. Set temperature to 0.3 for factual responses. Deploy to Firebase Functions with token usage monitoring. Expected latency: under 2 seconds per query.
67
+
68
+ **Scenario 2: RAG Document Search** -- Implement a retriever with text-embedding-gecko embeddings connected to Firestore vector search. Build a RAG flow that retrieves top-5 relevant documents, injects them as context, and generates grounded answers with source citations. Include context caching for repeated queries.
69
+
70
+ **Scenario 3: Multi-Tool Agent** -- Define weather and calendar tools with typed schemas. Create an agent flow that routes user queries to appropriate tools, handles multi-turn conversations, and traces each tool execution for debugging. Deploy to Cloud Run with auto-scaling (2-10 instances).
71
+
72
+ See `${CLAUDE_SKILL_DIR}/references/workflow-examples.md` for complete code examples.
73
+
74
+ ## Resources
75
+
76
+ - [Firebase Genkit Documentation](https://firebase.google.com/docs/genkit) -- flows, tools, retrievers, deployment
77
+ - [Genkit GitHub Repository](https://github.com/genkit-ai/genkit) -- source code and examples
78
+ - [Zod Schema Library](https://zod.dev) -- TypeScript schema validation
79
+ - [OpenTelemetry for Node.js](https://opentelemetry.io/docs/languages/js/) -- tracing and observability
80
+ - Gemini model selection guide: Flash for throughput, Pro for reasoning quality
81
+ - Context caching and token optimization strategies for cost management
@@ -0,0 +1,71 @@
1
+ # ARD: Genkit Production Expert
2
+
3
+ > Part of [Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)
4
+
5
+ ## System Context
6
+
7
+ The Genkit Production Expert operates within a developer's project to create, configure, and deploy Firebase Genkit flows. It interacts with the local codebase for implementation and Google Cloud services for model access and deployment.
8
+
9
+ ```
10
+ Developer Request
11
+
12
+ [Genkit Production Expert]
13
+ ├── Reads: project config, existing flows, schemas
14
+ ├── Writes: flows, tools, retrievers, deploy config
15
+ └── Calls: genkit CLI, npm/pip, firebase deploy, gcloud
16
+
17
+ Deployed Genkit Flow
18
+ ├── Firebase Functions / Cloud Run
19
+ ├── Gemini API (Vertex AI)
20
+ ├── Vector Search (Firestore)
21
+ └── OpenTelemetry Tracing
22
+ ```
23
+
24
+ ## Data Flow
25
+
26
+ 1. **Input**: User request specifying the flow type (simple/multi-step/RAG/agent), target language (TypeScript/Python/Go), model preference, and deployment target (Firebase Functions/Cloud Run)
27
+ 2. **Processing**: Scaffold project structure, define typed schemas, implement the flow with model bindings, add tool definitions or retrievers as needed, configure error handling and tracing, then deploy with auto-scaling parameters
28
+ 3. **Output**: Complete flow implementation with schemas, deployment configuration (firebase.json or Cloud Run YAML), monitoring setup (OpenTelemetry traces, Firebase Console integration), and cost optimization report
29
+
30
+ ## Key Design Decisions
31
+
32
+ | Decision | Choice | Rationale |
33
+ |----------|--------|-----------|
34
+ | Schema-first design | Define Zod/Pydantic schemas before flow logic | Catches type errors at runtime boundaries, not deep inside flow execution |
35
+ | Gemini 2.5 Flash default | Flash for throughput, Pro for complex reasoning | 10x cheaper than Pro; sufficient for most flow types; upgrade only when quality demands |
36
+ | OpenTelemetry native | Built-in Genkit tracing over custom logging | Standard observability protocol; integrates with Cloud Monitoring without custom code |
37
+ | Firebase Functions for simple flows | Functions over Cloud Run for single-purpose flows | Zero infrastructure management, automatic scaling, sub-second deployment |
38
+ | Cloud Run for long flows | Cloud Run when execution exceeds 60s Functions limit | Configurable timeout up to 60 minutes; supports streaming responses |
39
+ | Error categorization | Distinct handling for SAFETY_BLOCK, QUOTA_EXCEEDED, schema errors | Each error type needs different recovery: retry, fallback, or user notification |
40
+ | Context caching for RAG | Cache embedding results for repeated document queries | Reduces token costs and latency for frequently accessed knowledge bases |
41
+
42
+ ## Tool Usage Pattern
43
+
44
+ | Tool | Purpose |
45
+ |------|---------|
46
+ | Read | Inspect existing Genkit config, flow files, schema definitions, and package.json/requirements.txt |
47
+ | Write | Create new flow files, schema definitions, retriever implementations, and deployment configs |
48
+ | Edit | Patch existing flows to add tools, fix schemas, update model config, or add error handling |
49
+ | Grep | Search for import patterns, model usage, schema references, and configuration values |
50
+ | Glob | Discover project layout — flow files, test files, config files across the repository |
51
+ | Bash(cmd:*) | Run genkit CLI, npm/pip install, firebase deploy, test execution, and gcloud commands |
52
+
53
+ ## Error Handling Strategy
54
+
55
+ | Error Class | Detection | Recovery |
56
+ |------------|-----------|----------|
57
+ | SAFETY_BLOCK | Gemini response contains `finishReason: SAFETY` | Log the blocked content category; retry with adjusted safety settings or sanitized input |
58
+ | QUOTA_EXCEEDED | 429 status or `RESOURCE_EXHAUSTED` error | Implement exponential backoff with jitter; queue requests; request quota increase |
59
+ | Schema validation failure | Zod/Pydantic throws validation error before `ai.generate()` | Return descriptive error message identifying the invalid field; do not call the model |
60
+ | Retriever empty results | Vector search returns zero documents above threshold | Lower similarity threshold; verify embeddings are indexed; check embedding model version |
61
+ | Deployment timeout | Firebase Functions cold start exceeds 60s | Increase memory allocation (512MB+); set min instances > 0; migrate to Cloud Run for long flows |
62
+
63
+ ## Extension Points
64
+
65
+ - Custom model providers: add non-Google providers (OpenAI, Anthropic) via Genkit's plugin system
66
+ - Evaluation pipelines: integrate Genkit's `ai.evaluate()` for automated flow quality scoring
67
+ - Context caching: add prompt caching for repeated queries to reduce token costs
68
+ - Streaming responses: enable SSE streaming for chat-style flows on Cloud Run
69
+ - Multi-flow orchestration: chain multiple flows using Genkit's flow-to-flow calling pattern
70
+ - Custom retrievers: extend beyond Firestore vector search to Pinecone, Weaviate, or Elasticsearch
71
+ - Cost dashboards: generate Cloud Monitoring dashboards specific to token usage and model cost per flow
@@ -0,0 +1,70 @@
1
+ # PRD: Genkit Production Expert
2
+
3
+ **Version:** 2.1.0
4
+ **Author:** Jeremy Longshore <jeremy@intentsolutions.io>
5
+ **Status:** Active
6
+ **Marketplace:** [tonsofskills.com](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io)
7
+ **Portfolio:** [jeremylongshore.com](https://jeremylongshore.com)
8
+
9
+ ---
10
+
11
+ ## Problem Statement
12
+
13
+ Firebase Genkit applications require integrating multiple concerns — flow definition, schema validation, model configuration, tool calling, RAG retrieval, and deployment — across three languages (Node.js, Python, Go). Developers struggle to connect these pieces correctly: schemas don't match flow signatures, retrievers return empty results due to embedding mismatches, safety filters block legitimate content, and cold starts cause deployment timeouts. Without expert guidance, teams ship Genkit flows that lack type safety, monitoring, and cost controls.
14
+
15
+ ## Target Users
16
+
17
+ | User | Context | Primary Need |
18
+ |------|---------|-------------|
19
+ | Backend Developer | Building a new AI feature with Genkit for a production app | Complete flow implementation with typed schemas, error handling, and deployment config |
20
+ | AI Engineer | Implementing RAG with vector search and document retrieval | Retriever setup with embeddings, Firestore vector integration, and context caching |
21
+ | Full-Stack Developer | Adding tool-calling agents to an existing Node.js/Python app | Tool definitions with validated schemas and multi-turn conversation support |
22
+ | DevOps Engineer | Deploying Genkit flows to Firebase Functions or Cloud Run | Deployment configuration with auto-scaling, monitoring, and cost optimization |
23
+
24
+ ## Success Criteria
25
+
26
+ 1. Generate a complete Genkit flow with typed input/output schemas that passes validation without modification
27
+ 2. RAG flows return relevant documents with source citations on first implementation attempt
28
+ 3. Deployed flows have OpenTelemetry tracing and token usage monitoring configured out of the box
29
+ 4. Cold start time under 5 seconds for Firebase Functions deployments with appropriate memory allocation
30
+ 5. SAFETY_BLOCK errors handled gracefully with fallback response instead of crash
31
+ 6. Cost optimization applied: Flash model used by default, Pro only when explicitly needed
32
+
33
+ ## Functional Requirements
34
+
35
+ 1. Analyze requirements to determine target language, flow complexity (simple/multi-step/RAG), model selection, and deployment target
36
+ 2. Initialize project structure with proper config files (`tsconfig.json`, `genkit.config.ts`, or language equivalent)
37
+ 3. Define input/output schemas using Zod (TypeScript), Pydantic (Python), or Go structs for runtime type safety
38
+ 4. Implement Genkit flows using `ai.defineFlow()` with model configuration, temperature, and token limits
39
+ 5. Define tools using `ai.defineTool()` with scoped schemas for external capabilities
40
+ 6. For RAG: implement retrievers with `ai.defineRetriever()`, embedding generation, and vector database integration
41
+ 7. Configure error handling for safety blocks, quota exceeded, and provider timeouts
42
+ 8. Enable OpenTelemetry tracing with custom span attributes for cost and latency tracking
43
+ 9. Deploy to Firebase Functions or Cloud Run with auto-scaling configuration
44
+
45
+ ## Non-Functional Requirements
46
+
47
+ - All API keys stored in Secret Manager; never hardcoded in source or environment variables
48
+ - Schema validation must occur at runtime, not just compile time
49
+ - Flows must handle `SAFETY_BLOCK` responses gracefully without crashing
50
+ - Token usage must be tracked per-flow for cost attribution
51
+ - Retry logic with exponential backoff for all model API calls
52
+ - All flows must be testable locally via the Genkit Developer UI before deployment
53
+ - Generated code must follow the conventions of the target language (TypeScript/Python/Go)
54
+
55
+ ## Dependencies
56
+
57
+ - Node.js 18+ (TypeScript), Python 3.10+ (Python), or Go 1.21+ (Go) runtime
58
+ - Genkit CLI and core packages (`genkit`, `@genkit-ai/googleai` for TypeScript)
59
+ - Google Cloud project with Vertex AI API enabled for Gemini model access
60
+ - Firebase CLI for Firebase Functions deployments
61
+ - Zod, Pydantic, or Go structs for schema validation
62
+
63
+ ## Out of Scope
64
+
65
+ - Infrastructure provisioning with Terraform (handled by genkit-infra-expert)
66
+ - Fine-tuning or training custom models
67
+ - Non-Google model providers (OpenAI, Anthropic) — Genkit supports them but this skill focuses on Google AI
68
+ - Frontend UI development for chat interfaces
69
+ - Custom embedding model training (uses pre-built text-embedding-gecko)
70
+ - Multi-tenant architecture with per-user flow isolation
@@ -0,0 +1,57 @@
1
+ # Error Handling Reference
2
+
3
+ ## Genkit Flow Errors
4
+
5
+ | Error | Cause | Solution |
6
+ |-------|-------|----------|
7
+ | `SAFETY_BLOCK` response | Model safety filters triggered on input or output | Review prompt content for policy violations; adjust safety settings in `GenerationConfig`; add input sanitization before `ai.generate()` |
8
+ | `QUOTA_EXCEEDED` | API rate limit or daily token quota reached | Implement exponential backoff with jitter; request quota increase via Cloud Console; cache repeated prompts with TTL |
9
+ | `ZodError: invalid input` | Runtime input does not match Zod schema | Add `.describe()` to schema fields for better error messages; validate inputs upstream before calling the flow |
10
+ | `ZodError: invalid output` | Model output does not match expected output schema | Tighten the prompt to match schema structure; use `response_mime_type: application/json`; add a retry with rephrased prompt |
11
+
12
+ ## Retriever & RAG Errors
13
+
14
+ | Error | Cause | Solution |
15
+ |-------|-------|----------|
16
+ | Empty retrieval results | Vector database query found no matches above similarity threshold | Lower the similarity threshold; verify documents are indexed with matching embedding model version; run `ai.index()` to re-index |
17
+ | `Embedding dimension mismatch` | Retriever uses different embedding model than indexer | Ensure both indexer and retriever use the same embedder (e.g., `textEmbedding004`); re-index if model changed |
18
+ | `Firestore findNearest: index not found` | Firestore vector index not created for the collection | Create a composite index with `gcloud firestore indexes composite create` including the embedding field |
19
+ | Retriever returns stale documents | Indexed content was updated but embeddings were not regenerated | Implement an update pipeline that re-embeds documents on change; add `updatedAt` timestamps for cache invalidation |
20
+
21
+ ## Deployment Errors
22
+
23
+ | Error | Cause | Solution |
24
+ |-------|-------|----------|
25
+ | `Function timeout` on Firebase Functions | Cold start or flow execution exceeds 60s default limit | Increase `timeoutSeconds` in function config (max 540s for 2nd gen); set `minInstances: 1` to avoid cold starts; use Cloud Run for long-running flows |
26
+ | `ENOMEM` or container OOM | Insufficient memory for model response processing | Increase memory allocation (`--memory 1Gi`); reduce `maxOutputTokens`; stream responses instead of buffering |
27
+ | `ERR_MODULE_NOT_FOUND` in deployed function | Dependencies not bundled correctly | Verify `tsconfig.json` `outDir` matches function entry point; run `npm run build` before deploy; check `package.json` exports field |
28
+ | `Cloud Run: service unavailable` after deploy | Health check fails during startup | Ensure the flow server binds to `0.0.0.0:$PORT`; add a health check endpoint at `/` or `/_ah/health` |
29
+
30
+ ## Model & Provider Errors
31
+
32
+ | Error | Cause | Solution |
33
+ |-------|-------|----------|
34
+ | `Model not found` | Model ID doesn't match provider format | Use `gemini25Flash` or `gemini25Pro` exports from `@genkit-ai/googleai`; don't use raw model strings unless explicitly supported |
35
+ | `API key not valid` | Missing or expired Google AI API key | Set `GOOGLE_GENAI_API_KEY` env var; rotate keys periodically; use `gcloud secrets` for production |
36
+ | `INVALID_ARGUMENT: max tokens exceeded` | Prompt plus expected output exceeds model context window | Reduce prompt size; summarize context; use retrieval to inject only relevant snippets |
37
+ | Provider timeout | Network or API latency spike | Set `timeout` in generation config; implement circuit breaker pattern; add fallback to alternative model |
38
+
39
+ ## Local Development Errors
40
+
41
+ | Error | Cause | Solution |
42
+ |-------|-------|----------|
43
+ | Genkit Developer UI won't start | Port 4000 already in use or missing `genkit` CLI | Kill process on port 4000 (`lsof -i :4000`); ensure `genkit` CLI is installed globally (`npm install -g genkit`) |
44
+ | `tsx` not found | TypeScript execution tool not installed | Install `tsx` as dev dependency: `npm install -D tsx`; or use `npx tsx` |
45
+ | Flow test hangs indefinitely | Async flow never resolves or rejects | Add timeout to test cases; verify all async branches have proper error handling; mock external API calls in tests |
46
+ | `ECONNREFUSED` when testing flows | Flow server not running or wrong port | Start server with `npx genkit start -- tsx src/index.ts`; verify URL matches the flow server port (default 3400) |
47
+
48
+ ## Tracing & Monitoring Errors
49
+
50
+ | Error | Cause | Solution |
51
+ |-------|-------|----------|
52
+ | No traces appearing in Firebase Console | `enableTracingAndMetrics` not set or wrong project | Pass `enableTracingAndMetrics: true` in Genkit config; verify `GOOGLE_CLOUD_PROJECT` env var matches Firebase project |
53
+ | Missing custom span attributes | Span not properly closed or attribute key rejected | Use OpenTelemetry-compliant attribute names; ensure spans are ended in `finally` blocks |
54
+ | High cardinality warning in monitoring | Too many unique flow names or label values | Use parameterized flow names; avoid dynamic values in metric labels |
55
+
56
+ ---
57
+ *[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*