Dev Workflow — Genkit Python
- Agent Responsibility: Lines 14-30
- Step 1: Get a Gemini API Key: Lines 34-37
- Step 2: Export the API Key: Lines 41-51
- Step 3: Install Dependencies: Lines 55-65
- Step 4: Start the Dev UI: Lines 69-114
- Step 5: Test in the Dev UI: Lines 118-130
- CLI Commands: Lines 134-183
- Troubleshooting: Lines 187-195
Agent Responsibility
After generating or migrating code:
- Run the project's type checker (
pyright,mypy, orty) in.venvso typed configs (GeminiConfig), generic contexts (FlowContext[T],ToolContext[T]), keyword-only signatures, andOutputT | Nonechecks pass before handing off. - Give the developer:
- Copy-paste setup commands with absolute paths
- The
genkit startcommand to run in their foreground terminal (expected to block) - Exact Dev UI steps to exercise the flow or agent and inspect traces
Do not run genkit start as an interactive blocking command on the developer's
behalf unless explicitly asked; use genkit flow:run for automated one-shot
verification.
Step 1: Get a Gemini API Key
If the developer needs a key, create one at
https://aistudio.google.com/apikey.
Step 2: Export the API Key
export GEMINI_API_KEY=your-api-key-herePersist across shell sessions if desired:
echo 'export GEMINI_API_KEY=your-api-key-here' >> ~/.zshrc && source ~/.zshrcStep 3: Install Dependencies
Replace /path/to/your-project with the project's absolute path:
cd /path/to/your-project
uv add 'genkit==0.13.*' 'genkit-google-genai==0.13.*'(Run uv init first if pyproject.toml does not exist yet — see
Setup.)
Step 4: Start the Dev UI
The examples below use this src/main.py:
from pydantic import BaseModel
from genkit import Genkit
ai = Genkit()
class OrderInput(BaseModel):
text: str
@ai.flow()
async def order_flow(inp: OrderInput) -> str:
return f'order: {inp.text}'
async def main() -> None:
print(await order_flow(OrderInput(text='smoked salmon tartine')))
if __name__ == '__main__':
ai.run_main(main())
# => order: smoked salmon tartine
# Under `genkit start`, the process stays up for the Dev UI until Ctrl+C.Run in a foreground terminal (blocks until stopped with Ctrl+C):
cd /path/to/your-project
GEMINI_API_KEY=your-api-key-here genkit start -- uv run src/main.pyFor FastAPI apps, run uvicorn under genkit start instead; the reflection
server starts on a background thread (see FastAPI):
GEMINI_API_KEY=your-api-key-here genkit start -- uv run uvicorn main:app --reloadWait for the CLI to print Genkit Developer UI: http://localhost:4000.
Step 5: Test in the Dev UI
- Open
http://localhost:4000in a browser. - Pick the registered flow, prompt, or model from the left sidebar. Flows
appear under their Python function name (e.g.
order_flow). - Paste JSON matching the flow's single input parameter, e.g. for
order_flow(inp: OrderInput):{"text": "smoked salmon tartine"} - Click Run and inspect the validated output on the right.
- Open Traces in the left sidebar to inspect every span, rendered prompt, tool call, token count, latency, and unwrapped error stack trace.
CLI Commands
genkit start sets GENKIT_ENV=dev, runs your command, and stores local traces
from every Genkit action under .genkit/ in the project root. The app's stdout
and stderr pass through. Running uv run directly skips the reflection server
and local trace capture.
Persistent dev runtime:
genkit start -- uv run src/main.py
genkit start --noui -- uv run src/main.py # no Dev UI; runtime still blocks until Ctrl+C
genkit start --non-interactive -- uv run src/main.py # CLI prompts take the default choice (CI/agents)
genkit start --port 4001 -- uv run src/main.py # Dev UI on another portOne-shot flow execution (flow:run): with -- <cmd>, it starts the app,
runs one @ai.flow() by its Python function name, prints Result: and
Trace ID:, and exits:
genkit flow:run order_flow '{"text": "smoked salmon tartine"}' -- uv run src/main.py
# => Result:
# order: smoked salmon tartine
# Trace ID: 395f73c3d0d662c28711239a4354bf53Without -- <cmd>, flow:run targets a runtime already started by
genkit start in the same directory, and fails with No runtimes found if none
is running. A str input is a JSON string: '"risotto"'.
flow:run runs @ai.flow() actions, not agents. Wrap one agent turn in a small
flow to test it (see Agents).
Inspecting traces from the terminal:
genkit trace:list --limit 5 # recent trace IDs with status, input, output
genkit trace:get <traceId> # human-readable execution tree
genkit trace:get <traceId> --format json # machine-readable JSON: spans, attributes, input, outputAlways pass --format json when piping into jq or other parsers (without it,
trace:get prints a human-readable execution tree):
genkit trace:get <traceId> --format json | jq -r '.spans[].displayName'
# => order_flowBuilt-in CLI documentation lookup:
genkit docs:search "streaming" python
genkit docs:list python
genkit docs:read python/flows.mdTroubleshooting
genkit: command not found—npm install -g genkit-cliGEMINI_API_KEYmissing —export GEMINI_API_KEY=your-key- Port 4000 busy —
genkit start --port 4001 -- uv run src/main.py uv: command not found—pipx install uvorpip install uv- Action missing in Dev UI — ensure standalone scripts enter via
ai.run_main(main())and check terminal output for startup import or validation errors (see Common Errors).