+ 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
+
+ # Anti-Hallucination Grounding for Quests
+ if available_quests:
+ quest_rules = f"SPECIAL CAPABILITIES: You can offer the following quests to the player: {available_quests}."
+ else:
+ quest_rules = "WARNING: You currently have NO quests to offer. Do NOT invent or offer any quests."
+
+ # --- NEW: Anti-Hallucination Grounding for Props ---
+ if available_props:
+ prop_rules = f"ENVIRONMENT: You own and have access to these specific nearby objects: [{available_props}]. To roleplay working or relaxing, use the USE_OBJECT action with one of these exact items as your action_target."
+ else:
+ prop_rules = ""
+
+ strategy_rules = f"ROLE: You are an interactive, living NPC. You actively respond to players.\nGOALS: React to their words, use the environment, and establish your personality.\n{quest_rules}\n{prop_rules}\nSPECIAL CAPABILITIES: You can open your merchant store if asked."