Skip to content

Conversation

@merongithub
Copy link

Summary

Introduce a standalone .prompt file handler for Python Genkit with:

  • Directory scanning (sync/async), partial registration, name/variant parsing
  • Optional folder preloading via Registry/Genkit without auto-registration
  • Lookup of loaded prompts by name/variant/ns
  • Tests validating loader behavior and metadata rendering

Scope of Changes

  • New utilities under genkit/dotprompt/:
    • file_loader.py: load .prompt files/dirs, register partials, compute definition keys, async metadata rendering; supports current engine API naming.
    • __init__.py: export loader/metadata functions.
    • types.py: prompt identity and loaded prompt types.
  • Registry integration (read-only, opt-in):
    • Registry.load_prompt_folder(dir, ns) caches loaded prompts in-memory.
    • Registry.list_loaded_prompts(), Registry.get_loaded_prompt(key), Registry.lookup_loaded_prompt(name, variant, ns).
  • Genkit API helpers:
    • GenkitRegistry.load_prompt_dir, aload_prompt_dir, load_prompt_file, aload_prompt_file (no auto-registration).
  • Tests:
    • file_loader_test.py: directory scan, partials, variant parsing, subdir prefixing, metadata rendering, definition-key and lookup.
  • Cleanups:
    • Removed unused genkit/dotprompt/exceptions.py.
    • Adjusted comments; ensured real engine API support.

Behavior and Compatibility

  • No breaking changes; existing prompts and execution paths are unchanged.
  • .prompt loading is opt-in (invoked by API or Registry.load_prompt_folder).
  • Tests pass locally: 6/6.

How to Test

  • Using uv (recommended):
    • From py/:
      • uv sync
      • uv run pytest packages/genkit/tests/genkit/dotprompt/file_loader_test.py -q
  • Or using venv:
    • Create/activate venv
    • Install pinned dotpromptz and dotprompt-handlebars per py/pyproject.toml (uv.lock has the commit)
    • pytest packages/genkit/tests/genkit/dotprompt/file_loader_test.py -q

Follow-ups (not included here)

  • Optional: wire ai.prompt('name', { variant }) to use loaded prompts behind a flag.
  • Caching optimizations (mtime/hash).
  • Additional integration tests using real engine for end-to-end prompt execution.

Checklist

  • Code compiles and lints cleanly
  • Unit tests added/updated and passing (6/6)
  • No breaking changes to public APIs
  • Real Dotprompt engine (dotpromptz) supported (camelCase/snake_case compatibility)
  • Read-only, opt-in integration only (no auto-registration)
  • Removed unused files (genkit/dotprompt/exceptions.py)
  • Comments updated to reflect current design
  • Documentation update (optional) on new loader APIs and Registry helpers
  • Release notes entry (optional)

@google-cla
Copy link

google-cla bot commented Oct 23, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added docs Improvements or additions to documentation feature New feature or request python Python dotprompt root labels Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation dotprompt feature New feature or request python Python root

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant