ArchiveBox + AI Agents: Archive Every Page Your Agent Cites
Research agents are great at citing sources. They're less great at noticing that the source changed the next day. A pricing page gets updated, a blog post gets edited, a docs page moves, a news article quietly disappears. A week later, someone clicks the link in your agent's report and finds something that doesn't support the claim at all.
The fix is old and boring, which is why it works: keep a copy of every page the agent cites, at the moment it cited it. Here's how to do that with ArchiveBox and a few lines of Python, on a server you control.
What ArchiveBox Does
ArchiveBox is an open-source, self-hosted web archive. Give it a URL and it saves the page in several formats at once: a single-file HTML copy, a screenshot, extracted text and more, depending on which plugins you enable. Everything lands on your own disk, in open formats you can read without ArchiveBox.
The current stable release is v0.9.77, from October 27. The 0.9 line brought a new archiving engine, a plugin system for the extractors and a REST API that agents can call. One honest caveat before you build on it: the project still labels the REST API as alpha. Pin your version and check the API docs on your own instance after upgrades.
Step 1: Get an API Key
Once ArchiveBox is running, open the admin UI and create an API token for a dedicated user, for example research-agent. Every request sends it in a header:
X-ArchiveBox-API-Key: YOUR_TOKEN
Avoid the ?api_key= query parameter, which ArchiveBox also accepts. URLs end up in logs, and anyone holding that URL can act with your key.
Your instance also serves interactive API docs at /api/v1/docs. Keep that tab open while you build: it shows the exact request and response fields for your version.
Step 2: Archive the Sources After Each Run
The agent already knows which URLs it cited. After each run, send them to ArchiveBox in one request, tagged with the run ID so you can find them later:
import os
import requests
ARCHIVEBOX = os.environ["ARCHIVEBOX_URL"] # e.g. https://archive.example.com
HEADERS = {"X-ArchiveBox-API-Key": os.environ["ARCHIVEBOX_API_KEY"]}
def archive_sources(urls: list[str], run_id: str) -> list[str]:
"""Queue every cited URL and return the snapshot IDs."""
resp = requests.post(
f"{ARCHIVEBOX}/api/v1/cli/add",
headers=HEADERS,
json={"urls": urls, "tag": f"agent-run-{run_id}", "depth": 0},
timeout=30,
)
resp.raise_for_status()
data = resp.json()
if not data["success"]:
raise RuntimeError(data["errors"])
return data["result"]["snapshot_ids"]
Two settings matter. depth: 0 archives only the page itself, not everything it links to. And the tag groups all sources from one run, so "show me what the agent saw for report 1042" becomes a single filter.
The API queues the work and returns right away, so your agent doesn't wait for slow pages to finish rendering.
Step 3: Link the Archived Copy, Not Just the Live URL
Archiving runs in the background. Each snapshot moves from queued to started to sealed. When you build the final report, look up each source and add the archived link next to the original. Filtering on the run's tag matters: a popular URL can have many snapshots, and you want the one taken for this report:
def archived_link(url: str, run_id: str) -> str | None:
"""Return the archive URL captured for this run, if it is ready."""
resp = requests.get(
f"{ARCHIVEBOX}/api/v1/core/snapshots",
headers=HEADERS,
params={"url": url, "tag": f"agent-run-{run_id}", "limit": 1},
timeout=30,
)
resp.raise_for_status()
items = resp.json()["items"]
if not items or items[0]["status"] != "sealed":
return None
return f"{ARCHIVEBOX}/archive/{items[0]['timestamp']}/"
In the report, every claim gets two links: the live page and "archived on November 26". If the live page changes, the archived copy shows exactly what the agent read.
What to Archive, and What Not To
A few practical rules:
| Source type | Archive it? |
|---|---|
| Public articles, docs, pricing pages | Yes, these change the most and matter the most |
| Pages behind a login | Only with care: the archive stores what the logged-in user saw |
| Search result pages | No, archive the pages the agent actually used |
| Huge files and videos | Rarely, they fill disks fast |
Archiving also has a legal side. Keeping private copies for internal verification is very different from republishing someone's content. Keep the archive private unless you're sure you're allowed to share it.
Running It on Elestio
ArchiveBox on Elestio starts at $11/month for the VM, with SSL, backups, monitoring and updates handled. You get a public HTTPS address for your agents to call, and backups matter more than usual here: an archive is only useful if it survives. Watch disk usage, since screenshots and full-page captures add up. Before upgrading to a new 0.9 release, take a backup, because the project notes that 0.9 moves some files in the data directory.
Troubleshooting
401 or 403 from the API. The token is missing, expired or sent under the wrong header name. It must be exactly X-ArchiveBox-API-Key.
Snapshots stay queued. The background workers aren't running or are overloaded. Check the instance logs, and avoid sending hundreds of URLs in a single request.
Archived pages look empty or broken. The site needs JavaScript or blocks headless browsers. Check which extractors succeeded on the snapshot page: the screenshot and single-file copies usually handle modern sites better than raw HTML.
The same URL is archived over and over. Each run adds a new snapshot. That's useful when a page changes, but wasteful otherwise. Check for an existing recent snapshot with the lookup function before queuing again.
The API returns an unexpected field or error after an upgrade. The REST API is still alpha. Compare your requests with /api/v1/docs on the upgraded instance.
Thanks for reading ❤️ See you in the next one 👋