detectAgent(request)
Detect whether an incoming request is from an AI agent.Parameters
request
Type: Request (required)A standard Web API Request object. Inspects the Accept and User-Agent headers.Return type
isAgent (boolean, required): true when the request is identified as coming from an AI agent.
agent (AgentInfo): Present when isAgent is true.
name (string, required): Matched agent name (e.g., "ClaudeBot", "GPTBot"), or "unknown" when detected via Accept: text/markdown with no matching User-Agent.
confidence (number, required): Detection confidence score from 0 to 1. 1.0 for accept-header detection; 0.9 for user-agent pattern match.
method (string, required): The signal that triggered detection. One of 'accept-header' | 'user-agent' | 'http-signature' | 'behavioral'.
Full HTML-to-markdown transformation pipeline. Processes a raw HTML string through four stages: expand hidden content, extract main content, convert to markdown, clean and finalize.Parameters
html
Type: string (required)Raw HTML string to transform.options
Type: TransformOptionsOptional transform configuration.
contentSelector (string): CSS selector for the main content area. Auto-detected when omitted.
excludeSelectors (string[]): CSS selectors for elements to remove before conversion.
baseUrl (string): Base URL for resolving relative links to absolute URLs in the output.
maxTokens (number): Maximum token target. Content is truncated by section when exceeded.
headingStyle (‘atx’ | ‘setext’): Markdown heading style. 'atx' uses # prefixes (default); 'setext' uses underlines.
title (string): Page title override. Auto-extracted from the HTML when omitted.
description (string): Page description written into the output metadata.
includeNav (boolean | SiteHeaderConfig): Prepend a site navigation preamble to the output. Pass true to auto-extract from the page’s <header>/<nav>; pass a SiteHeaderConfig object to use a manual override. Omit or pass false for no preamble.
Return type
markdown (string, required): The agent-optimized markdown output.
tokenEstimate (number, required): Estimated token count of the markdown output, calculated as Math.ceil(markdown.length / 4).
metadata (object, required): Extracted page metadata.
title (string, required): Page title extracted from the HTML or provided via options.title.
sourceUrl (string): Source URL, set from options.baseUrl when provided.
description (string): Page description extracted from the HTML or provided via options.description.
processingTimeMs (number, required): Wall-clock time in milliseconds for the full pipeline.
generateLlmsTxt(options)
Generate a standards-compliant llms.txt file following the llmstxt.org specification.Parameters
options
Type: LlmsTxtOptions (required)
siteName (string, required): Site name written as the top-level # Heading of the file.
description (string): Site description written as a > blockquote below the heading.
baseUrl (string, required): Base URL prepended to each page path to form absolute links.
pages (LlmsTxtPage[], required): List of pages to include. Each entry:
maxPages (number): Maximum number of pages to include. Defaults to 15. Pages beyond this limit are silently omitted.
Return type
Returns a string containing the complete llms.txt content.
defineConfig(config)
Type-safe configuration factory for agentxp.config.ts. Returns the config object unchanged — its only purpose is to provide TypeScript type inference and editor autocompletion.Parameters
config
Type: AgentXPConfig (required)Your AgentXP configuration object. All fields are optional.Return type
Returns the config typed as AgentXPConfig. Use with a default export in agentxp.config.ts.defineConfig is a zero-overhead identity function — it exists purely for TypeScript autocompletion. When using Edge Runtime middleware, pass your config directly to withAgentXP() rather than loading it from a separate file, since dynamic import() and process.cwd() are not available in the Edge Runtime.
For full configuration documentation, see Configuration overview.