MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / TrackedMemoryManager

Class TrackedMemoryManager

methods/lightmem_agent.py:21–331  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

19from .base import BaseAgent, MemoryBuildResult, AgentResponse
20from 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
26LOCOMO_ANSWER_PROMPT = """You are an intelligent memory assistant tasked with retrieving accurate information from conversation memories.
27
28# CONTEXT:
29You have access to memories from two speakers in a conversation. These memories contain
30timestamped information that may be relevant to answering the question.
31
32# INSTRUCTIONS:
331. Carefully analyze all provided memories from both speakers
342. Pay special attention to the timestamps to determine the answer
353. If the question asks about a specific event or fact, look for direct evidence in the memories
364. If the memories contain contradictory information, prioritize the most recent memory
375. 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.
406. 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.
437. 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.
458. The answer should be less than 5-6 words.
46
47# APPROACH (Think step by step):
481. First, examine all memories that contain information related to the question
492. Examine the timestamps and content of these memories carefully
503. Look for explicit mentions of dates, times, locations, or events that answer the question
514. If the answer requires calculation (e.g., converting relative time references), show your work
525. Formulate a precise, concise answer based solely on the evidence in the memories
536. Double-check that your answer directly addresses the question asked
547. Ensure your final answer is specific and avoids vague time references
55
56Memories for user {speaker_1_name}:
57
58{speaker_1_memories}
59
60Memories for user {speaker_2_name}:
61
62{speaker_2_memories}
63
64Question: {question}
65
66Answer:"""
67
68# LongMemEval: from experiments/longmemeval/run_lightmem_gpt.py
69LONGMEMEVAL_ANSWER_PROMPT = """You are a helpful assistant.
70
71Question time:{question_date} and question:{question}
72Please answer the question based on the following memories: {memories}"""
73
74# MedMemoryBench: adapted from LoCoMo prompt for medical dialogues
75MEDMEMORYBENCH_ANSWER_PROMPT = """你是一个智能医疗记忆助手,负责从对话记忆中准确检索信息来回答问题。
76
77# 背景:
78你可以访问患者和医生之间对话的记忆。这些记忆包含带有时间戳的信息,可能与回答问题相关。

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected