T02 · Agent Memory Poisoning
- Location
scripts/memory_manager.py:110- Finding
Persistent Knowledge Graph Content Can Poison Future AI Prompts
- Content
View full analysis
tuple[dict, bool]: """ Add an entity. If its ID already exists, merge its attributes. """ existing = {e["id"]: i for i, e in enumerate(graph["entities"])} if entity["id"] in existing: idx = existing[entity["id"]] old = graph["entities"][idx] old_attrs = old.get("attributes", {}) new_attrs = entity.get("attributes", {}) old_attrs.update(new_attrs) graph["entities"][idx]["attributes"] = old_attrs return graph, False graph["entities"].append(entity) graph["changelog"].append({ "ts": now_str(), "action": "add_entity", "id": entity["id"], "name": entity.get("name", "") }) return graph, True def add_relation(graph: dict, relation: dict) -> tuple[dict, bool]: """ Add a relationship. If the source, target, and type already exist, update the weight. """ key = (relation["source"], relation["target"], relation["type"]) for i, r in enumerate(graph["relations"]): if (r["source"], r["target"], r["type"]) == key: graph["relations"][i]["weight"] = relation.get( "weight", r.get("weight", 0.5) ) if "evidence" in relation: graph["relations"][i]["evidence"] = relation["evidence"] return graph, False relation.setdefault("timestamp", now_str()) graph["relations"].append(relation) graph["chan ...[truncated 5866 chars]- Remediation
View remediation
