Index of every page on this site: llms.txt
All skills
genkit-ai avatar

/developing-genkit-python

@d12c988
by Genkitgenkit-ai/skills40 stars
13
Run it yourself

Provides guidance on developing AI-powered applications using Genkit Python (0.13) and migrating Genkit Python 0.12 projects to 0.13. Use when building AI agents, flows, tools, structured outputs, or FastAPI routes in Python, upgrading from Genkit 0.12, or debugging Genkit imports, config errors, or traces. Don't use for Genkit in JavaScript/TypeScript, Go, or Dart.

Use this Skill: https://skilld.dev/gh/genkit-ai/skills/developing-genkit-python

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesdev-workflow.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Dev Workflow — Genkit Python


Agent Responsibility

After generating or migrating code:

  1. Run the project's type checker (pyright, mypy, or ty) in .venv so typed configs (GeminiConfig), generic contexts (FlowContext[T], ToolContext[T]), keyword-only signatures, and OutputT | None checks pass before handing off.
  2. Give the developer:
    • Copy-paste setup commands with absolute paths
    • The genkit start command 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-here

Persist across shell sessions if desired:

echo 'export GEMINI_API_KEY=your-api-key-here' >> ~/.zshrc && source ~/.zshrc

Step 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.py

For 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 --reload

Wait for the CLI to print Genkit Developer UI: http://localhost:4000.


Step 5: Test in the Dev UI

  1. Open http://localhost:4000 in a browser.
  2. Pick the registered flow, prompt, or model from the left sidebar. Flows appear under their Python function name (e.g. order_flow).
  3. Paste JSON matching the flow's single input parameter, e.g. for order_flow(inp: OrderInput):
    {"text": "smoked salmon tartine"}
  4. Click Run and inspect the validated output on the right.
  5. 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 port

One-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: 395f73c3d0d662c28711239a4354bf53

Without -- <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, output

Always 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_flow

Built-in CLI documentation lookup:

genkit docs:search "streaming" python
genkit docs:list python
genkit docs:read python/flows.md

Troubleshooting

  • genkit: command not found — npm install -g genkit-cli
  • GEMINI_API_KEY missing — export GEMINI_API_KEY=your-key
  • Port 4000 busy — genkit start --port 4001 -- uv run src/main.py
  • uv: command not found — pipx install uv or pip 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).

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts14d3 checks · Risk SAFE
  • Gen Agent Trust Hub14d

    The skill provides comprehensive documentation and code examples for developing AI applications with Genkit Python. It includes instructions for setting up environment variables and installing packages from trusted registries (NPM, PyPI). While it describes building agents that process untrusted user data, which creates a potential surface for indirect prompt injection, this is inherent to the technology described and is documented alongside safety features like human-in-the-loop approval.

  • Socket14d

    No alerts

  • Snyk14d

    Risk: LOW · No issues

Signed by skilld at d12c988. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated 2 weeks ago
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}

README badge

README badge for genkit-ai/skills/developing-genkit-python