Skip to main content

escape_memory_content

Function escape_memory_content 

Source
pub fn escape_memory_content(content: &str) -> String
Expand description

Escape <agent-memory> and </agent-memory> tags from memory content.

Handles case variations (</AGENT-MEMORY>, </Agent-Memory >) via case-insensitive regex. Prevents prompt injection: an agent writing the closing tag to MEMORY.md would otherwise escape the <agent-memory> wrapper and inject arbitrary system prompt text.

Trust model note: MEMORY.md is written by the agent itself, unlike user-written instruction files. Agent-written content requires stricter escaping.