
Developing Genkit Python
Ship Python AI features with Genkit flows, tools, and Google AI models when your agent hits import or API errors.
Overview
Developing Genkit Python is an agent skill most often used in Build (also Ship, Operate) that guides correct Genkit Python setup, flows, and troubleshooting when building AI-powered apps.
Install
npx skills add https://github.com/firebase/agent-skills --skill developing-genkit-pythonWhat is this skill?
- Bootstraps Genkit with Google AI (`GoogleAI()`, `GEMINI_API_KEY`) and prefixed model IDs like `googleai/gemini-flash-lat
- Documents Python 3.14+, `uv`, and global `genkit-cli` as hard prerequisites
- 4-step dev workflow: provider defaults, model ID prefixing, entrypoint via `ai.run_main`, and error-first lookup in Comm
- Explicit guardrail: do not trust stale internal knowledge—verify imports against references on every API change
- Pointers to setup, examples, and common-errors reference docs for bootstrap and troubleshooting
- Python 3.14+ runtime requirement
- 4-step development workflow section
- Default model alias pattern googleai/gemini-flash-latest
Adoption & trust: 33.5k installs on skills.sh; 345 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You want Genkit in Python but the SDK shifts often and your agent keeps guessing wrong imports, model IDs, or env setup.
Who is it for?
Indie builders adding Gemini-backed flows or tools in Python with `uv` and who will run `genkit-cli` locally.
Skip if: Teams skipping Genkit entirely, pure Node/TS Genkit-only stacks with no Python, or one-off prompts with no project structure.
When should I use this skill?
User asks about Genkit, AI agents, flows, or tools in Python, or encounters Genkit errors, import issues, or API problems.
What do I get? / Deliverables
You get verified bootstrap code, provider defaults, and an error-first path so Genkit runs and generates reliably in your repo.
- Runnable Genkit Python hello-world with async generate
- Correct plugin and prefixed model configuration
- Troubleshooting path aligned to common-errors reference
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Genkit is where solo builders wire models, plugins, and runnable flows into a product—canonical shelf is agent tooling during the build phase. The skill centers on Genkit SDK patterns, `generate`, plugins, and CLI—not generic Python backend CRUD.
Where it fits
Scaffold a Genkit entrypoint with `GoogleAI()` and a first `ai.generate` flow before adding custom tools.
Wire a backend route that delegates generation to a Genkit flow with the correct prefixed model ID.
Unblock CI failures caused by wrong Genkit imports by following the common-errors reference.
Diagnose production Genkit API or plugin errors without relying on outdated agent training data.
How it compares
Use for the official Genkit Python workflow—not generic “call OpenAI from Python” snippets or unmanaged copy-paste from old docs.
Common Questions / FAQ
Who is developing-genkit-python for?
Solo and indie builders shipping Python apps with Genkit, plugins, and Google AI models inside agent-assisted IDEs.
When should I use developing-genkit-python?
During build when scaffolding flows and tools; at ship when fixing integration tests or env keys; at operate when debugging production Genkit import or API errors.
Is developing-genkit-python safe to install?
Review the Security Audits panel on this Prism page and treat `GEMINI_API_KEY` and any cloud credentials as secrets you scope per environment.
SKILL.md
READMESKILL.md - Developing Genkit Python
# Genkit Python ## Prerequisites - **Runtime**: Python **3.14+**, **`uv`** for deps ([install](https://docs.astral.sh/uv/getting-started/installation/)). - **CLI**: `genkit --version` — install via `npm install -g genkit-cli` if missing. **New projects:** [Setup](references/setup.md) (bootstrap + env). **Patterns and code samples:** [Examples](references/examples.md). ## Hello World ```python from genkit import Genkit from genkit.plugins.google_genai import GoogleAI ai = Genkit( plugins=[GoogleAI()], model='googleai/gemini-flash-latest', ) async def main(): response = await ai.generate(prompt='Tell me a joke about Python.') print(response.text) if __name__ == '__main__': ai.run_main(main()) ``` ## Critical: Do Not Trust Internal Knowledge The Python SDK changes often — verify imports and APIs against the references here or upstream docs. On **any** error, read [Common Errors](references/common-errors.md) first. ## Development Workflow 1. Default provider: **Google AI** (`GoogleAI()`), **`GEMINI_API_KEY`** in the environment. 2. Model IDs: always prefixed, e.g. **`googleai/gemini-flash-latest`** (always-on-latest Flash alias; same pattern as other skills). 3. Entrypoint: **`ai.run_main(main())`** for Genkit-driven apps (not `asyncio.run()` for long-lived servers started with `genkit start` — see [Common Errors](references/common-errors.md)). 4. After generating code, follow [Dev Workflow](references/dev-workflow.md) for `genkit start` and the Dev UI. 5. On errors: step 1 is always [Common Errors](references/common-errors.md). ## References - [Examples](references/examples.md): Structured output, streaming, flows, tools, embeddings. - [Setup](references/setup.md): New project bootstrap and plugins. - [Common Errors](references/common-errors.md): Read first when something breaks. - [FastAPI](references/fastapi.md): HTTP, `genkit_fastapi_handler`, parallel flows. - [Dotprompt](references/dotprompt.md): `.prompt` files and helpers. - [Evals](references/evals.md): Evaluators and datasets. - [Dev Workflow](references/dev-workflow.md): `genkit start`, Dev UI, checklist. # Common Errors — Genkit Python ## Before anything else: read this file when you hit any error. --- ## ModuleNotFoundError: No module named 'genkit.plugins.google_genai' **Cause:** Plugin package not installed. **Fix:** Add dependencies from PyPI: ```bash uv add genkit genkit-plugin-google-genai ``` --- ## 400 INVALID_ARGUMENT: functionDeclaration parameters schema should be of type OBJECT **Cause:** Tool function has bare scalar parameters (e.g. `city: str`). Gemini requires object schema. **Fix:** Wrap parameters in a Pydantic BaseModel: ```python from pydantic import BaseModel # Wrong @ai.tool() async def get_weather(city: str) -> str: ... # Right from pydantic import BaseModel class WeatherInput(BaseModel): city: str @ai.tool() async def get_weather(input: WeatherInput) -> str: ... ``` --- ## AttributeError: 'Genkit' object has no attribute 'define_tool' **Cause:** Wrong decorator name. **Fix:** Use `@ai.tool()`, not `@ai.define_tool()`. --- ## RuntimeError / event loop errors when using asyncio.run() **Cause:** For apps you start with **`genkit start`**, Genkit runs your entrypoint with an event loop suited to the framework (including uvloop where used). There is no “default” loop for you to manage in that mode. **Fix:** For long-running Genkit apps (servers, flows served under `genkit start`), use **`ai.run_main(main())`** as your entrypoint instead of `asyncio.run(main())`. For one-off scripts that exit when done, using `asyncio.run()` can still be appropriate when you are not using `genkit start`. --- ## Wrong model ID