{"slug": "how-i-fixed-hallucinations-by-switching-from-agents-md-to-agents-db", "title": "How I Fixed Hallucinations by Switching from AGENTS.md to AGENTS.db", "summary": "A developer at Exam Intelligence fixed agent hallucinations by replacing AGENTS.md with a SQLite3 database called AGENTS.db. The new system stores step-by-step instructions and synthetic memories in structured tables, enabling hierarchical querying and audit trails that eliminated broken JSON, syntax errors, and skipped migrations.", "body_md": "Before I dive in, a bit of background on how our agentic workflow at **Exam Intelligence** for deep analysis and notes generation works...\n\nInitially, I tried to create a complete end-to-end LangGraph workflow. Except, things always ran into unexpected bugs caused by external factors like missing PDFs, being unable to find papers, failing to parse them, or agents returning 503 errors or broken JSONs.\n\nAt that point, it looked like I needed to build an entire coding agent just to handle the edge cases.\n\nInstead of a master workflow, I switched to creating CLI tools that a coding agent can use.\n\nIf anything breaks, I decided on 3 levels of fixes:\n\nUnaware of the standard `AGENTS.md`\n\nnaming conventions, I initially chose this setup:\n\n`instructions.md`\n\n: Informed the agent about the entire workflow, architecture, and how it should execute it.`memory.md`\n\n: A persistent cross-session memory for the agent, mainly storing what bugs/problems it faced and how it fixed them.`workflow_checkpoints.db`\n\n: A SQLite3 database used as temporary storage for the workflow, which is later pushed to PostgreSQL (used by our Django app) after quality checks to ensure production isolation.The agent started right, but when the time came to migrate the notes data and stuff to the Django database, it completely broke.\n\nMy workflow had a `migrate.py`\n\nCLI tool which it could call to easily do the job (mentioned in `instructions.md`\n\n), but it started using inline Python, always made syntax errors, migrated the data with broken formatting, and sometimes entirely skipped migrating certain tables.\n\nSo after witnessing multiple failures, I made the following changes:\n\n`agents.db`\n\nHere is the schema layout:\n\n```\nsqlite> .schema\nCREATE TABLE instructions (\n    id INTEGER PRIMARY KEY,\n    step_order INTEGER NOT NULL,\n    title TEXT NOT NULL,\n    objective TEXT NOT NULL,\n    actions TEXT NOT NULL,\n    tools TEXT NOT NULL,\n    success_criteria TEXT NOT NULL,\n    created_at TEXT NOT NULL\n);\n\nCREATE TABLE memories (\n    id INTEGER PRIMARY KEY,\n    title TEXT NOT NULL,\n    step TEXT NOT NULL,\n    tldr TEXT NOT NULL,\n    problem TEXT NOT NULL,\n    fix TEXT NOT NULL,\n    created_at TEXT NOT NULL\n);\n```\n\n`instructions`\n\ntable`instructions.md`\n\n. It gave the agent isolated, step-by-step instructions focused on strict objectives, what specific actions it must take, what CLI tools it has access to, and a clearly defined definition of what success looks like.`memories`\n\ntableI pre-seeded the memories table with everything that went wrong in the previous runs and what the agent should have done in those instances using **synthetic memories**.\n\nThe agent was instructed to go step-by-step over the `instructions`\n\ntable. For each step, it queries the `memories`\n\ntable (just fetching the `tldr`\n\n) as a brief on what needs to be done, how to do it, and what can possibly go wrong. If it encounters a new issue, it just adds that to memories.\n\nThose changes allowed me to audit what the agent intends to do (the plan) and insert fixes if any. It allowed for hierarchical querying of instructions and bugs, and completely fixed the previous issues.\n\nWhile I prompted the agent as a quick fix to just read the database (telling it when to do it), a more reliable way would be to just edit the harness to insert the right instructions and memories—saving more tokens on SQL queries per step.\n\nUsing the PI coding agents harness as the orchestrator adds flexibility, but it makes things way too unpredictable. Despite the flow being mostly hierarchical, I'm now stuck asking it to do a full run, catching hallucinations, and updating memories...", "url": "https://wpnews.pro/news/how-i-fixed-hallucinations-by-switching-from-agents-md-to-agents-db", "canonical_source": "https://dev.to/0x1brahim/how-i-fixed-hallucinations-by-switching-from-agentsmd-to-agentsdb-2ch1", "published_at": "2026-07-21 14:01:18+00:00", "updated_at": "2026-07-21 14:21:21.618967+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-agents", "developer-tools", "large-language-models"], "entities": ["Exam Intelligence", "LangGraph", "SQLite3", "PostgreSQL", "Django"], "alternates": {"html": "https://wpnews.pro/news/how-i-fixed-hallucinations-by-switching-from-agents-md-to-agents-db", "markdown": "https://wpnews.pro/news/how-i-fixed-hallucinations-by-switching-from-agents-md-to-agents-db.md", "text": "https://wpnews.pro/news/how-i-fixed-hallucinations-by-switching-from-agents-md-to-agents-db.txt", "jsonld": "https://wpnews.pro/news/how-i-fixed-hallucinations-by-switching-from-agents-md-to-agents-db.jsonld"}}