Prompt Management System
This module provides a centralized way to manage prompts using PromptLayer with a local filesystem fallback. It allows you to version prompts, manage environments (dev/staging/prod), and easily switch between local development and cloud-managed prompts.
π Usage
Import the get_prompt function to load prompts anywhere in your application.
from src.backend.prompts import get_prompt
1. Load from PromptLayer (Default)
By default, if PROMPTLAYER_API_KEY is set in your environment, it will fetch the prompt from PromptLayer using the configured environment label (default: production).
# Fetches 'DB_Executor' tagged with current environment (e.g., 'production')
system_prompt = get_prompt("DB_Executor")
2. Load Latest Version (Ignore Environment)
Useful for testing or when you want to ensure you have the absolute latest saved version from PromptLayer, ignoring any 'prod' or 'dev' tags.
# Fetches the absolute latest version of the template
system_prompt = get_prompt("DB_Executor", latest_version=True)
3. Force Load from Local File
You can force loading from a local file, which is useful for local development without an internet connection or for testing new prompts before pushing to PromptLayer.
# Loads from src/prompts/templates/db_executor/v1.txt
# (Assuming 'v1.txt' is the file name in that directory, or provide full path)
system_prompt = get_prompt("db_executor/v1", local_prompt_path="src/prompts/templates")
If you don't provide a local_prompt_path but also don't have a PROMPTLAYER_API_KEY set, it defaults to looking in src/prompts/templates.
π Directory Structure
Store your local prompt backups in src/prompts/templates/.
src/prompts/
βββ __init__.py # Exposes get_prompt
βββ prompt_layer.py # Core logic
βββ templates/ # Local prompt storage
β βββ db_executor/
β β βββ v1.txt
β βββ supervisor/
β β βββ v1.txt
β βββ ...
βββ info.md # This file
βοΈ Configuration
PROMPTLAYER_API_KEY: Set this env var to enable PromptLayer.PROMPT_ENVIRONMENT: Set todev,staging, orproduction(default) to control which tagged version is loaded.
π Debugging
The system prints clear logs to stdout so you know where your prompt came from:
π Loaded prompt '...' from PromptLayer (env=production)π Loaded prompt '...' from PromptLayer (latest version)π Loaded prompt '...' from local file: ...