+ player_state = data.get('player_state', 'Relaxed and unarmed.')
+ world_state = data.get('world_state', 'Nothing of note is happening.')
+ npc_health = data.get('npc_health', 'Healthy and uninjured.')
+ relationship = data.get('relationship', 'Neutral or Friendly.')
+ location_context = data.get('location_context', 'You are in a generic area.')
+
+ # Core Strategy Flag (1: Agent, 2: Villain, 3: Maestro, 4: Shrine)
+ llm_strategy = int(data.get('llm_strategy', 1))
+
+
+ available_quests = data.get('available_quests', '')
+ available_props = data.get('available_props', '')
+
+ # --- Sub-Context Strings ---
+ group_context = f"Be aware that these other players are listening nearby: {nearby_players}." if nearby_players else ""
+ puppet_context = f"Nearby generic NPCs you can CONVERSE with: {nearby_npcs}" if nearby_npcs else ""
+ secret_context = f"YOUR SECRET (Reveal only if players are persuasive): {npc_secret}" if npc_secret else ""
+ routine_context = f"YOUR REQUIRED ROUTINE: {npc_routine}" if npc_routine else ""
+
+ session_id = f"{player_name}_{npc_tag}"
+
+ # =====================================================================
+ # DUAL RAG QUERY (Lore + Memories)
+ # =====================================================================
+ search_query = f"{location_context} {message}"
+ retrieved_lore = "No specific local lore currently relevant."
+ past_memories = ""
+
+ if lore_collection.count() > 0:
+ results = lore_collection.query(query_texts=[search_query], n_results=1)
+ if results['documents'] and results['documents'][0]:
+ retrieved_lore = f"- {results['documents'][0][0]}"
+
+ if memory_collection.count() > 0:
+ mem_results = memory_collection.query(
+ query_texts=[search_query], n_results=2, where={"session_id": session_id}
+ )
+ if mem_results['documents'] and mem_results['documents'][0]:
+ formatted_mems = "\n- ".join(mem_results['documents'][0])
+ past_memories = f"\nPAST MEMORIES OF {player_name}:\n- {formatted_mems}"
+
+ # =====================================================================
+ # STRATEGY-SPECIFIC PROMPT COMPILER
+ # =====================================================================
+ strategy_rules = ""
+ action_macros = ""
+ target_context = ""
+
+ if llm_strategy == 1:
+ # STRATEGY 1: The Autonomous Agent