A Memory Manager that wraps LightMem's LLM calls through our llm_client for token tracking. This replaces LightMem's OpenaiManager while maintaining the same interface.
| 19 | from .base import BaseAgent, MemoryBuildResult, AgentResponse |
| 20 | from utils.llm_client import create_llm_client, format_messages, BaseLLMClient, get_usage_tracker |
| 21 | |
| 22 | |
| 23 | # ============ Official Answer Prompts (from LightMem experiments) ============ |
| 24 | |
| 25 | # LoCoMo: from experiments/locomo/prompts.py ANSWER_PROMPT |
| 26 | LOCOMO_ANSWER_PROMPT = """You are an intelligent memory assistant tasked with retrieving accurate information from conversation memories. |
| 27 | |
| 28 | # CONTEXT: |
| 29 | You have access to memories from two speakers in a conversation. These memories contain |
| 30 | timestamped information that may be relevant to answering the question. |
| 31 | |
| 32 | # INSTRUCTIONS: |
| 33 | 1. Carefully analyze all provided memories from both speakers |
| 34 | 2. Pay special attention to the timestamps to determine the answer |
| 35 | 3. If the question asks about a specific event or fact, look for direct evidence in the memories |
| 36 | 4. If the memories contain contradictory information, prioritize the most recent memory |
| 37 | 5. If there is a question about time references (like "last year", "two months ago", etc.), |
| 38 | calculate the actual date based on the memory timestamp. For example, if a memory from |
| 39 | 4 May 2022 mentions "went to India last year," then the trip occurred in 2021. |
| 40 | 6. Always convert relative time references to specific dates, months, or years. For example, |
| 41 | convert "last year" to "2022" or "two months ago" to "March 2023" based on the memory |
| 42 | timestamp. Ignore the reference while answering the question. |
| 43 | 7. Focus only on the content of the memories from both speakers. Do not confuse character |
| 44 | names mentioned in memories with the actual users who created those memories. |
| 45 | 8. The answer should be less than 5-6 words. |
| 46 | |
| 47 | # APPROACH (Think step by step): |
| 48 | 1. First, examine all memories that contain information related to the question |
| 49 | 2. Examine the timestamps and content of these memories carefully |
| 50 | 3. Look for explicit mentions of dates, times, locations, or events that answer the question |
| 51 | 4. If the answer requires calculation (e.g., converting relative time references), show your work |
| 52 | 5. Formulate a precise, concise answer based solely on the evidence in the memories |
| 53 | 6. Double-check that your answer directly addresses the question asked |
| 54 | 7. Ensure your final answer is specific and avoids vague time references |
| 55 | |
| 56 | Memories for user {speaker_1_name}: |
| 57 | |
| 58 | {speaker_1_memories} |
| 59 | |
| 60 | Memories for user {speaker_2_name}: |
| 61 | |
| 62 | {speaker_2_memories} |
| 63 | |
| 64 | Question: {question} |
| 65 | |
| 66 | Answer:""" |
| 67 | |
| 68 | # LongMemEval: from experiments/longmemeval/run_lightmem_gpt.py |
| 69 | LONGMEMEVAL_ANSWER_PROMPT = """You are a helpful assistant. |
| 70 | |
| 71 | Question time:{question_date} and question:{question} |
| 72 | Please answer the question based on the following memories: {memories}""" |
| 73 | |
| 74 | # MedMemoryBench: adapted from LoCoMo prompt for medical dialogues |
| 75 | MEDMEMORYBENCH_ANSWER_PROMPT = """你是一个智能医疗记忆助手,负责从对话记忆中准确检索信息来回答问题。 |
| 76 | |
| 77 | # 背景: |
| 78 | 你可以访问患者和医生之间对话的记忆。这些记忆包含带有时间戳的信息,可能与回答问题相关。 |
no outgoing calls
no test coverage detected