T02 · Agent Memory Poisoning
- Location
scripts/experience_manager.py:71- Finding
Persistent Agent Memory Poisoning Through Untrusted Experience Content
- Content
View full analysis
Dict: """Add a new experience to the database.""" ensure_dirs() exp = { "id": generate_id(question + datetime.now().isoformat()), "question": question, "failure_reason": failure_reason, "improvement": improvement, "missed_information": missed_information, "category": category, "weight": INITIAL_WEIGHT, "created_at": datetime.now().isoformat(), "use_count": 0, "success_count": 0, } with open(DB_PATH, 'a') as f: f.write(json.dumps(exp, default=str) + "\n") return exp ``` ```python def generate_guideline(task_title: str, experiences: List[Dict]) -> str: """ Generate a task-specific guideline from experiences. """ if not experiences: return "" lines = ["## Task-Specific Guidelines (from past experiences)\n"] for i, exp in enumerate(experiences, 1): lines.append(f"### Lesson {i} (weight: {exp.get('weight', 1.0):.2f})") lines.append(f"**From similar task:** {exp.get('question', '')[:100]}") if exp.get('failure_reason'): lines.append(f"**What went wrong:** {exp.get('failure_reason', '')}") if exp.get('improvement'): lines.append(f"**Key lesson:** {exp.get('improvement', '')}") if exp.get('missed_information'): lines.append(f"**Don't forget:** {exp.get('missed_information', '')}") lines.append("") lines.append("---") lines.append("**Apply these lessons to your current task. Be cautious about over-generalizing.**") return ...[truncated 3391 chars]- Remediation
View remediation
