I Stopped Dumping JSON Into Prompts
— Hindsight Fixed It How restructuring agent memory around recall — not storage — fixed latency, hallucinations, and prompt bloat in the Smart Campus AI backend The first version of this agent had ...

Source: DEV Community
— Hindsight Fixed It How restructuring agent memory around recall — not storage — fixed latency, hallucinations, and prompt bloat in the Smart Campus AI backend The first version of this agent had a dirty secret: every request sent the entire student_history.json to the LLM. Token counts ballooned. Responses hallucinated connections between unrelated events. Latency doubled. I had treated memory as a context-window problem. It was a retrieval design problem. This is the story of how restructuring the backend — specifically the memory schema, the prompt construction, and the recall layer — using Hindsight fixed all three problems without adding meaningful complexity to the codebase. 1. The Problem: Raw JSON in Every Prompt The Smart Campus AI Assistant is a FastAPI + Groq backend that serves four students with distinct profiles: Arjun (tech, entrepreneurship), Priya (arts, cultural), Rahul (fresher, tech), and Sneha (arts, sports). Each has enrolled clubs, upcoming deadlines, registered