Giving a LangChain or CrewAI Agent a Web Capture Tool with an Evidence Record
An agent that reads a web page and acts on it leaves a gap in your logs. You can see what it decided. You often can't see what the page said when it decided, and pages change.
A capture tool closes part of that gap. This guide adds one to both frameworks, using the current docs for each. We use PageVerified's API because it's ours, but the pattern applies to any capture service.
What the API gives you
From the Capture API reference:
POST /api/v1/keysissues a key with 25 free credits and no signup. Keys start withpv_cap_.POST /api/v1/capturereturnsid, a 24-hour signedartifact_url,sha256,captured_atandevidence_url. PNG and HTML cost 1 credit, and PDF costs 2.POST /api/v1/capture/recordtakes the same body and also returns arecordandsignature, for 4 more credits.POST /api/v1/capture/record/verifychecks a signed record.
Know what this is before you build on it. A capture records what our renderer saw at the recorded time, on our own server clock. It isn't a forensic chain of custody, proof of authorship or legal certification. Targets must be public HTTP or HTTPS pages.
Get a key once and keep it in a secret store. It is shown only one time.
curl -s -X POST https://pageverified.com/api/v1/keys \
-H "content-type: application/json" \
-d '{"label":"my agent"}'
The shared function
Both frameworks can call the same plain function. It returns the fields an agent needs, and it hands back the signed record separately so the model doesn't have to carry it.
import os
import requests
API_URL = "https://pageverified.com/api/v1/capture/record"
def capture_with_record(url: str, fmt: str = "png") -> dict:
response = requests.post(
API_URL,
headers={"Authorization": f"Bearer {os.environ['PAGEVERIFIED_API_KEY']}"},
json={"url": url, "format": fmt, "full_page": True},
timeout=120,
)
response.raise_for_status()
return response.json()
def summary(result: dict) -> str:
return (
f"Captured at {result['captured_at']}. "
f"SHA-256 {result['sha256']}. "
f"Capture id {result['id']}."
)
Store result["record"] and result["signature"] in your own database, next to the run ID. That pair is the evidence. The artifact_url expires after 24 hours, so download the file if you need to keep it. You can check that it matches with Python's hashlib:
import hashlib
import requests
def artifact_matches(artifact_url: str, expected_sha256: str) -> bool:
data = requests.get(artifact_url, timeout=120).content
return hashlib.sha256(data).hexdigest() == expected_sha256
LangChain
The LangChain tools guide imports tool from langchain.tools. It says type hints are required, because they define the input schema, and the docstring becomes the description the model reads.
from langchain.agents import create_agent
from langchain.tools import tool
@tool
def capture_page(url: str) -> str:
"""Capture a public web page and return its SHA-256 hash and timestamp.
Use this before relying on a page's price, terms or claims.
"""
result = capture_with_record(url)
save_evidence(result["record"], result["signature"]) # your own storage
return summary(result)
agent = create_agent("your-model-id", [capture_page])
Replace your-model-id with a model string your setup supports. save_evidence is yours to write.
Over MCP
LangChain also has a built-in MCP adapter in the beta langchain.mcp namespace, which needs langchain[mcp]>=1.4.0. Its auth page passes a bearer token through a FastMCP Client:
import os
from fastmcp.client import Client
from langchain.agents import create_agent
from langchain.mcp import MCPAdapter
async def build_agent():
token = os.environ["PAGEVERIFIED_API_KEY"]
async with MCPAdapter(Client("https://pageverified.com/mcp", auth=token)) as adapter:
tools = await adapter.list_tools()
return create_agent("your-model-id", tools)
The docs note the tools hold the client, so the agent stays usable after the context exits.
CrewAI
CrewAI's tools guide offers two forms. Here is the decorator:
from crewai import Agent
from crewai.tools import tool
@tool("Capture web page")
def capture_page(url: str) -> str:
"""Capture a public web page and return its SHA-256 hash and timestamp."""
result = capture_with_record(url)
save_evidence(result["record"], result["signature"]) # your own storage
return summary(result)
researcher = Agent(
role="Vendor researcher",
goal="Check vendor pages and keep a record of what they said",
backstory="You verify claims before anyone relies on them.",
tools=[capture_page],
)
If you need an explicit input schema, subclass BaseTool from crewai.tools with a Pydantic args_schema and a _run method.
Over MCP
CrewAI's MCP overview documents MCPServerHTTP with url, headers and streamable, passed in the agent's mcps list:
import os
from crewai import Agent
from crewai.mcp import MCPServerHTTP
researcher = Agent(
role="Vendor researcher",
goal="Check vendor pages and keep a record of what they said",
backstory="You verify claims before anyone relies on them.",
mcps=[
MCPServerHTTP(
url="https://pageverified.com/mcp",
headers={"Authorization": f"Bearer {os.environ['PAGEVERIFIED_API_KEY']}"},
streamable=True,
),
],
)
CrewAI's own advice applies here: only connect to MCP servers you trust.
REST or MCP?
The MCP Streamable HTTP transport gives you tool discovery for free, and our capture_url tool takes url, format, full_page, viewport and public_receipt. MCP is less work if you want the whole toolbox.
Use REST for the evidence record. capture_url performs an ordinary capture and returns a receipt. The signed record is only available from POST /api/v1/capture/record.
Before you ship
- Keep the key out of prompts and logs. Both frameworks can read it from the environment.
- Decide when the agent must capture. Put that rule in your code rather than leaving it to the model. Capturing before any purchase or external action is a sensible default.
- Handle
402(out of credits),429(rate limited) and400(blocked or invalid target). - Remember capture only works on public pages. Anything behind a login won't work, and private network targets are blocked.
A captured page tells you what a page displayed. It can't tell you whether what it said was true, so the agent's judgment still has to do that part.
