You are a senior Python/FastAPI engineer working inside my existing Replit project for LIA (Loyalty Intelligence Agent). Your task is to install **LIA System Prompt v2** into the backend and wire it into ALL OpenAI calls used by LIA. STACK / CONTEXT - Backend: FastAPI (Python) running in Replit - LIA uses OpenAI’s chat.completions (model like gpt-4.1) - There is an existing URE layer that builds the `ure_context` string (tier, stage, template_key, appointment_status, confusion_count, soft_no_count, etc.) - /api/lia/inbound is the HTTP endpoint that Make.com calls when a WhatsApp reply comes in I CANNOT CODE, so you must: - Locate the right files - Make all code changes - Create any missing files - Ensure everything runs without errors ──────────────────────────────── GOAL Install a new system prompt file `app/lia_prompt_v2.txt` and make sure ALL LIA-related OpenAI chat calls use this file via `LIA_SYSTEM_PROMPT` as the system message. Do NOT change any business logic, URE logic, or database logic. Only: - Prompt file creation - Prompt loading - OpenAI system prompt injection - Removal of old hardcoded prompts - Basic test to confirm it works ──────────────────────────────── STEP 1 — Create the prompt file 1. In the `app` directory, create a new file: app/lia_prompt_v2.txt 2. Put in a simple placeholder line like: LIA Prompt v2 placeholder – I (the human) will paste the full content later. (Do NOT try to generate the real long prompt yourself. Just ensure the file exists and is readable from Python.) 3. Ensure the file is committed/visible in the Replit file tree under `app/`. ──────────────────────────────── STEP 2 — Load the prompt at startup 1. Find the module where the OpenAI chat completion for LIA is performed. Likely candidates: - app/lia_ure.py - app/lia_inbound.py - or another helper module that wraps `client.chat.completions.create` 2. In that module (the one that actually calls OpenAI), at the top of the file add: from pathlib import Path import logging # Load System Prompt v2 at startup PROMPT_PATH = Path(__file__).parent / "lia_prompt_v2.txt" try: LIA_SYSTEM_PROMPT: str = PROMPT_PATH.read_text(encoding="utf-8") except FileNotFoundError as e: logging.critical(f"[LIA] System prompt file not found at {PROMPT_PATH}") raise RuntimeError(f"LIA system prompt missing: {PROMPT_PATH}") from e 3. Make sure this code runs exactly once when the module is imported and will crash loudly if the file is missing. This is desirable for now. ──────────────────────────────── STEP 3 — Centralise the OpenAI call for LIA 1. In the same module as above, create (or update) an async helper function that calls OpenAI using `LIA_SYSTEM_PROMPT` as the system message. For example: import anyio from openai import OpenAI client = OpenAI() # if not already defined; otherwise reuse the existing client async def generate_lia_reply(ure_context: str) -> str: """ ure_context: the final URE-structured string passed to the LLM (tier, stage, template_key, template_text, appointment_status, etc.) """ def _call_openai(): return client.chat.completions.create( model="gpt-4.1", messages=[ {"role": "system", "content": LIA_SYSTEM_PROMPT}, {"role": "user", "content": ure_context}, ], ) completion = await anyio.to_thread.run_sync(_call_openai) return completion.choices[0].message.content.strip() 2. If a similar helper already exists, update it instead of creating a duplicate. The key requirement: EVERY LIA OpenAI call must now use `LIA_SYSTEM_PROMPT` as the single system prompt. ──────────────────────────────── STEP 4 — Replace OLD system prompts 1. Search the entire repo for old LIA system prompt usages. Typical patterns: - LIA_PROMPT - "You are LIA" - "As a renewal assistant" - lia_prompt_v1 - any big multiline string that looks like an old LIA system prompt 2. For each of these: - Remove the old prompt definition, OR - Comment it out clearly with a note: "# deprecated LIA prompt (replaced by LIA_SYSTEM_PROMPT)" 3. Update any OpenAI calls that still reference old prompt variables so they now use `LIA_SYSTEM_PROMPT`. For example, change: response = client.chat.completions.create( model="gpt-4.1", messages=[ {"role": "system", "content": OLD_PROMPT}, {"role": "user", "content": ure_context}, ], ) to: response = client.chat.completions.create( model="gpt-4.1", messages=[ {"role": "system", "content": LIA_SYSTEM_PROMPT}, {"role": "user", "content": ure_context}, ], ) 4. Ensure that after your edits, there is exactly ONE active system prompt for LIA: `LIA_SYSTEM_PROMPT` loaded from `lia_prompt_v2.txt`. ──────────────────────────────── STEP 5 — Ensure /api/lia/inbound uses the new helper 1. Find the FastAPI route that handles inbound LIA messages, something like: @router.post("/api/lia/inbound", ...) async def lia_inbound(...): 2. Confirm that this endpoint: - Accepts the JSON payload from Make.com (from_number, body, channel, conversation_id, payments_remaining, etc.) - Calls the URE function to build a `ure_context` string - Then calls the LLM helper you created/updated, e.g.: ure_context = await build_ure_context(...) reply_text = await generate_lia_reply(ure_context) 3. If needed, wire it so that `lia_inbound` uses `generate_lia_reply` directly, instead of duplicating the OpenAI call logic. 4. Do not change any of the URE/business logic – only how the response is generated with the system prompt. ──────────────────────────────── STEP 6 — Light sanity test Add a tiny bit of logging to confirm that Prompt v2 is wired, for example: logging.info("[LIA] Using Prompt v2 system prompt from %s", PROMPT_PATH) You do NOT need to implement a full test harness, but ensure: - The app starts without errors - There are no crashes related to `lia_prompt_v2.txt` missing or encoding issues ──────────────────────────────── IMPORTANT - Do NOT invent or modify the contents of `lia_prompt_v2.txt` beyond a placeholder. - Do NOT change database schemas, URE logic, or state machine logic. - Only touch code related to: - Loading the prompt file - OpenAI call wrappers - Removing old prompt definitions - Ensuring /api/lia/inbound uses the new helper ──────────────────────────────── WHEN DONE Reply with a concise summary in this format: - Files created: - app/lia_prompt_v2.txt - Files modified: - : short note of changes - : short note of changes - How to use: - Where I should paste the real Prompt v2 content - How the inbound path flows now: Make.com -> /api/lia/inbound -> URE -> generate_lia_reply -> OpenAI with LIA_SYSTEM_PROMPT Make all edits now.