Skip to main content

Quick Start

Install AgentXP and serve your first markdown response in minutes.
1

Install the package

Add @reaganhsu/agentxp-next to your project.
2

Add middleware

Create middleware.ts in your project root (next to package.json). If your project uses a src/ directory, create src/middleware.ts instead.
middleware.ts
That’s all you need for a working installation. AgentXP detects AI agents and serves markdown automatically from this point forward.Already have middleware? If you use Clerk, next-intl, or any other middleware, pass it as the second argument:
middleware.ts
AgentXP runs first. If the request is from an AI agent, it handles the response. Otherwise, it passes the request to your existing middleware unchanged.
3

Add the AgentExperience component (optional)

Add the AgentExperience component to your root layout to inject structured metadata for agents — a JSON-LD WebSite schema, a link to /llms.txt, and AI-specific robots directives.
The component renders no visible UI. It injects:
  • JSON-LD structured data (WebSite schema)
  • A <link> to /llms.txt
  • AI-specific meta robots directives (noai, noimageai) based on your permissions settings
4

Verify it works

Start your dev server and send a request with Accept: text/markdown to any page:
You should see clean markdown instead of HTML:
Check the response headers to confirm AgentXP is active:
You can also verify the auto-generated endpoints:

Configuration

withAgentXP() accepts an optional configuration object. Here is a full example showing the available options:
See Configuration overview for the full reference.
AgentXP requires Next.js 14 or later.