T02 · Agent Memory Poisoning
- Location
scripts/mem_learn.py:42- Finding
Persistent Agent Memory Poisoning Through Untrusted Learning Content
- Content
View full analysis
str: today = datetime.now().strftime("%Y-%m-%d") learning_file = LEARNINGS_DIR / f"{today}.md" # Append to today's file (or create it) entry = f""" ## Learning: {today} ### Incident {incident} ### Lesson {lesson} ### Context {context or "General situation"} ### Tags {' '.join(f'#{t.strip()}' for t in tags if t.strip())} ### Confidence {confidence} --- """ with open(learning_file, "a", encoding="utf-8") as f: f.write(entry) return learning_file.name ``` `scripts/mem_recall.py:30-62` reads stored content and returns surrounding lines without trust labeling or instruction neutralization: ```python def search_file(path: Path, query: str, limit: int = 5) -> list[dict]: """Search a single file for query matches.""" if not path.exists(): return [] try: content = path.read_text(encoding="utf-8", errors="ignore") except Exception: return [] query_words = query.lower().split() lines = content.split("\n") scored_lines = [] for i, line in enumerate(lines): line_lower = line.lower() # Skip headers and empty lines if not line.strip() or line.startswith("#"): continue score = 0 matched_words = 0 for word in query_words: if word in line_lower: score += 1 matched_words += 1 # Exact phrase match b ...[truncated 4760 chars]- Remediation
View remediation
