- It marks the links to your own hosts in answers meant for agents (Markdown and
llms.txt), so the request an agent makes by following one joins the page it came from. The marker comes off before your site sees the request. - It sets the session cookie the browser script reads, so a visitor’s requests and page views share one session.
Create the source
An Admin creates the source once, whichever platform you use.1
Open Set up
Open Journeys, select Set up and choose Edge. If you are in Settings · Journeys, use Add the edge.
2
Name the source
Enter a Name, such as “Docs edge”, and select Create source.
3
Save the secret and hash key
Agentrail shows the Secret and the Hash key once, with the environment variables and a Cloudflare Worker example filled in for your site. Copy them before you select I have saved them. If you lose one, revoke the source and create another.
AGENTRAIL_SECRETlets the edge send this source’s events.AGENTRAIL_HASH_KEYis your workspace’s key. The edge hashes visitors’ addresses and verified identities with it before anything leaves your site.
<collector>. The example in Agentrail has yours in it.
Cloudflare Workers
Install the package and put the two values in the Worker’s secrets:Vercel
On Vercel, the edge runs in Routing Middleware. Install the package and Vercel’s functions helper, and addAGENTRAIL_SECRET and AGENTRAIL_HASH_KEY to the project’s environment variables:
origin fetches your site itself. Point it at an address of your site that this middleware does not run on: a fetch to the same address would come back through the middleware.
Create the edge once, outside the handler, as this does. In Next.js 16, the file is proxy.ts and the function it exports is proxy.
Options
collector, hashKey and hosts are required. The rest are optional.
hosts: your own hosts, and how a link to each is marked.'query'adds anhparameter.'path'adds an/h/prefix to the path, for a host whose calls an extra parameter would break.identify(request): the verified identity behind a request, from your own check of its method, URL and headers. See Identify a caller.queryAllowlist: the query parameters a recorded path keeps. Every other parameter is dropped from what is recorded. Your site still receives them.sessionIdleTimeout: seconds without a request after which a session ends. The default is 1800, which is 30 minutes.sessionCookieDomain: the domain a session is shared across, such asexample.comfordocs.example.comandapp.example.com. By default, a session stays on one host.sessionCookie: the session cookie’s name. The default isagentrail_session.service: the service name on each event. The default is the request’s host.onError(error): called when events could not be sent oridentifythrew. These are logged otherwise, and neither ever reaches the visitor.fetch: the fetch the collector’s calls go through.
Identify a caller
Return a verified identity fromidentify, or null when there is none. Use your own check, never something the caller merely says about itself:
kind is one of user, agent_registration, agent_instance, oauth_client or api_key. For an agent acting for a person, also return actingUserId. The ids are hashed before they leave the edge.
identify runs after the answer, so it does not slow your site down. If it throws, onError is told and the request is recorded with no identity.
If something goes wrong
Recording happens after the answer, so a visitor never waits for it and never sees it fail. A failed call to the collector is tried again, and is given up within 25 seconds, whenonError is told.