Skip to content

Commit cccc0a7

Browse files
authored
Feat: update prompt and format need raw (#528)
* feat: update memos headers * feat: headers add * feat: update search agent * feat: upadte mem story * feat: update mem scehduler * feat: update deepsearch mem code * feat: update deepsearch agent * feat: update test code * fix: remove dup config * feat: dock search pipeline * fix: code test * feat: add test scripts * feat: add test * feat: update need_raw process
1 parent 105d8a6 commit cccc0a7

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/memos/mem_agent/deepsearch_agent.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ def run(self, query: str, **kwargs) -> str | list[TextualMemoryItem]:
183183
if search_results:
184184
context_batch = [self._extract_context_from_memory(mem) for mem in search_results]
185185
accumulated_context.extend(context_batch)
186-
accumulated_memories.extend(search_results)
187-
188186
reflection_result = self.reflector.run(current_query, context_batch)
189187
status = reflection_result.get("status", "sufficient")
190188
reasoning = reflection_result.get("reasoning", "")
@@ -193,11 +191,14 @@ def run(self, query: str, **kwargs) -> str | list[TextualMemoryItem]:
193191

194192
if status == "sufficient":
195193
logger.info("Sufficient information collected")
194+
accumulated_memories.extend(search_results)
196195
break
197196
elif status == "needs_raw":
198197
logger.info("Need original sources, retrieving raw content")
198+
accumulated_memories.extend(self._set_source_from_memory(search_results))
199199
break
200200
elif status == "missing_info":
201+
accumulated_memories.extend(search_results)
201202
missing_entities = reflection_result.get("missing_entities", [])
202203
logger.info(f"Missing information: {missing_entities}")
203204
current_query = reflection_result.get("new_search_query")
@@ -331,6 +332,22 @@ def _refine_query_for_missing_info(self, query: str, missing_entities: list[str]
331332

332333
return refined_query
333334

335+
def _set_source_from_memory(
336+
self, memory_items: list[TextualMemoryItem]
337+
) -> list[TextualMemoryItem]:
338+
"""set source from memory item"""
339+
for memory_item in memory_items:
340+
if not hasattr(memory_item.metadata, "sources"):
341+
continue
342+
chat_sources = [
343+
f"{source.chat_time} {source.role}: {source.content}"
344+
for source in memory_item.metadata.sources
345+
if hasattr(source, "type") and source.type == "chat"
346+
]
347+
if chat_sources:
348+
memory_item.memory = "\n".join(chat_sources) + "\n"
349+
return memory_items
350+
334351
def _generate_final_answer(
335352
self,
336353
original_query: str,

src/memos/templates/mem_agent_prompts.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@
3535
- "sufficient": Context fully answers the query
3636
- "missing_info": Key information is missing (e.g., specific dates, locations, details)
3737
- "needs_raw": Content is relevant but too summarized/vague, need original sources
38-
- "new_search_query": New search query to retrieve more information
38+
39+
IMPORTANT for "new_search_query":
40+
- MUST preserve ALL specific entities from the original query (names, dates, times, locations, etc.)
41+
- DO NOT replace specific information with generic terms like "user", "person", "they", etc.
42+
- Keep the exact same subjects, time references, and key details as in the original query
43+
- Only modify the query to focus on the missing information while maintaining all original specifics
44+
- Example: If original query mentions "May 2024", keep "May 2024" in new query, don't change to "that month"
3945
4046
Response:"""
4147

0 commit comments

Comments
 (0)