- 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, select Add source, then 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 an example for Cloudflare Workers or Vercel 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.
Join your servers
When your servers run the Node, Go or Python SDK, the edge signs each request it forwards, so your server’s steps continue the visit the edge recorded. Give the edge and your servers the same hash key, and keep their clocks synchronized: a signature is accepted for 60 seconds. The signature covers the exact path and query your site receives. If the edge rewrites them, do it in the adapter’sprepareOriginRequest(request), as in vercel({ waitUntil, prepareOriginRequest, origin }), which runs before signing. A change of host in origin keeps the signature, but a change of path or query there means your server cannot check it, and the request starts a trace of its own. If signing fails, onError is told and the request goes to your site unsigned.
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.ignoreRequest(request): requests to pass to your site untouched and record nowhere, such as your own servers’ calls. See Leave out your own servers.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.signers: hosts, beside the signers the edge already knows, whose Web Bot Auth signatures the edge may check. A signature from any other host is recorded as not checked, and that host is never contacted.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.