T02 · Agent Memory Poisoning
- Location
memory_compress.py:124- Finding
Untrusted Session Logs Can Poison Persistent Agent Memory
- Content
View full analysis
tuple: """Returns (combined_text, list_of_paths_read).""" cutoff = datetime.utcnow() - timedelta(days=n_days) logs = [] paths = [] for day_offset in range(n_days): date = (datetime.utcnow() - timedelta(days=day_offset)).strftime("%Y-%m-%d") log_file = MEMORY_DIR / f"{date}.md" if log_file.exists(): logs.append(f"=== {date} ===\n{log_file.read_text()[:2000]}") paths.append(log_file) return "\n\n".join(logs), paths ``` ```python def update_memory_md(sections: dict, substrate: Substrate): """ Rewrite MEMORY.md with current distilled insights. Appends new content to existing sections rather than overwriting. """ existing = MEMORY_MD.read_text() if MEMORY_MD.exists() else "" insights = substrate.get_insights() total_insights = len(insights) high_conf = substrate.get_insights_above_confidence(0.75) challenged_zone = substrate.get_claims_in_confidence_range(0.45, 0.55) now = datetime.utcnow().isoformat() new_content = f"""# MEMORY.md — Epistemic Council Agent Long-Term Memory _Last updated: {now}_ ## Substrate Reality (auto-computed) - Total insights in substrate: {total_insights} - High-confidence insights (>0.75): {len(high_conf)} - Challenged-zone claims (0.45–0.55): {len(challenged_zone)} ## Calibration Heuristics _Updated from last 7-day log compression_ """ for lesson in sections.get("calibration_lessons", []): new_content += f"- {lesson}\n" new_content += "\n## Domain Boundaries Discovered\n" for boundary in sections.get("domain_boundaries", []): new_content += f"- {boundary}\n" new_content += "\n## E ...[truncated 2985 chars]- Remediation
View remediation
