页面简介
Run deep research, list-building, and enrichment workflows that return structured outputs.
正文摘录
Exa Agent is an async, usage-based web research agent API for high-compute tasks like list building, enrichment, and deep research. It handles complex reasoning and can return many structured output fields. Think of it as a context agent: you describe the data you want and the shape it should come back in, and Exa Agent orchestrates the tool calls needed to get there. A single run can fan out many searches across different angles, read and condense the pages behind them, split list building into subtasks that run in parallel, verify each candidate against your criteria, enrich contacts, and query any Exa Connect data partners you attach. You get the assembled context back as one grounded, structured result instead of orchestrating each /search and /contents call yourself. Each run can return a natural-language answer, schema-validated JSON, field-level grounding, metadata, and a cost breakdown. You can retrieve completed runs later, list past runs, replay events, or continue from a previous run. Prefer MCP? Exa Agent and Exa Connect are available in Exa MCP. Connect with OAuth or your API key and the agent_run tool is enabled by default, so you can run multi-step research, list-building, enrichment, and structured output from Claude, Cursor, and other MCP clients. When to use Exa Agent Use Exa Agent when a workflow needs more than a single search or extraction call, or when you would otherwise write your own loop of searches, page reads, and verification steps to assemble the data: Build lists from open-ended criteria, then enrich each result Research entities across many fields with citations Run multi-hop tasks like “find companies, then find their decision makers” Produce structured JSON from a long-running web research task Combine web research with premium data partners in one grounded answer Continue from a previous run with a follow-up request like “find 10 more results” Exa Agent is higher-latency and async by design. For a single low-latency search where you orchestrate the calls yourself, start with the Search API. Quickstart This example starts a run that builds a structured list of people matching your criteria. It returns JSON in output.structured. 1. Install the Exa SDK PythonJavaScriptpip install exa-py # Or, if using uv: uv add exa-py 2. Set your API key macOS/Linux Windowsexport EXA_API_KEY="your-api-key" setx EXA_API_KEY "your-api-key" 3. Create a run PythonJavaScriptcURLimport json from exa_py import Exa exa = Exa() run = exa.agent.runs.create( query="Find engineering leaders at AI infrastructure companies that raised a Series A or B in the last 6 months.", output_schema={ "type": "object", "properties": { "people": { "type": "array", "maxItems": 10, "items": { "type": "object", "properties": { "name": {"type": "string"}, "job_title": {"type": "string"}, "linkedin_url": {"type": "string", "format": "uri"}, }, "required": ["name", "job_title", "linkedin_url"], }, } }, "required": ["people"], }, effort="auto", ) print(json.dumps(run.model_dump(), indent=2)) Add Accept: text/event-stream when creating a run to receive server-sent events as the run is queued, started, and completed. See Stream events for more details. 4. Poll for completion If you do not stream events, save the returned id and poll the run until it reaches a terminal status. PythonJavaScriptcURLimport json from exa_py import Exa exa = Exa() run_id = "agent_run_01j..." run = exa.agent.runs.poll_until_finished( run_id, poll_interval=4000, ) print(json.dumps(run.model_dump(), indent=2)) Completed runs include: output.text: a natural-language answer output.structured: validated JSON when you provide outputSchema output.grounding: citations for text or structured fields, when emitted costDollars: the run’s cost breakdown Exa Agent is also available through the OpenAI-compatible Responses API. Point the OpenAI SDK at https://api.exa.ai, use model: "exa-agent", and choose synchronous, streaming, or background execution. See OpenAI SDK compatibility. Verify and enrich a specific entity Beyond list building, use Exa Agent to inspect a single known entity, verify a claim against authoritative sources, and return structured enrichment. This example checks whether a company’s official website has a publicly accessible pricing page, and enriches the result with pricing details when they are available. The schema requires only domain and verdict; everything else is optional enrichment. PythonTypeScriptcURLimport json from exa_py import Exa exa = Exa() run = exa.agent.runs.create( query="Inspect the official website redbarnrobotics.com and determine whether it has a publicly accessible pricing or plans page. A dedicated pricing page counts as present even if it only says 'Contact sales'.", system_prompt="Judge only the company specified in the query. Use present only when a public pricing or plans page is found. Use absent only after successfully inspecting the website and finding no such page. If the website is unreachable, blocked, fails to render, or cannot be inspected reliably, use cannot_verify. Never use absent when inspection failed. Use only the company's official website as evidence.", effort="low", output_schema={ "type": "object", "additionalProperties": False, "required": ["domain", "verdict"], "properties": { "domain": {"type": "string", "const": "redbarnrobotics.com"}, "verdict": { "type": "string", "enum": ["present", "absent", "cannot_verify"], }, "pricing_page_url": {"type": ["string", "null"], "format": "uri"}, "displays_numeric_prices": {"type": ["boolean", "null"]}, "pricing_model": { "type": ["string", "null"], "enum": [ "free", "subscription", "usage_based", "one_time", "custom_quote", "mixed", "other", None, ], }, "starting_price": {"type": ["number", "null"], "minimum": 0}, "currency": { "type": ["string", "null"], "description": "ISO 4217 code such as USD or EUR.", }, "billing_period": { "type": ["string", "null"], "enum": [ "monthly", "annual", "one_time", "usage_based", "variable", "other", None, ], }, "has_free_plan": {"type": ["boolean", "null"]}, "has_free_trial": {"type": ["boolean", "null"]}, "reasoning": {"type": ["string", "null"], "maxLength": 300}, }, }, ) run = exa.agent.runs.poll_until_finished(run.id) print(json.dumps(run.output.structured if run.output else None, indent=2)) Schemas for verification workflows should account for uncertainty. Make fields that may not be verifiable nullable and leave them out of required, so the agent can return null instead of fabricating a value. The verdict enum distinguishes a failed inspection (cannot_verify) from actual negative evidence (absent): a site that could not be reached is not evidence that the page does not exist. Stream events Streaming keeps the create request open and sends Server-Sent Events (SSE) until the run completes. See Event format for the event types and payloads. Set stream=True in Python, stream: true in JavaScript, or send Accept: text/event-stream over HTTP: PythonJavaScriptcURLfrom exa_py import Exa exa = Exa() events = exa.agent.runs.create( query="Find five recently launched developer tools for evaluating AI agents.", stream=True, ) for event in events: print(event.event, event.data) Event format Each SSE frame contains an event ID, event name, and JSON payload: id: 1 event: agent_run.created data: {"id":"agent_run_01j...","status":"queued","createdAt":"2026-05-07T21:21:52.051Z"} The stream may also contain comment lines such as : keep-alive. SSE clients ignore comments automatically; custom parsers should do the same. Event types Eventdata payloadHow to use itagent_run.created{ id, status: "queued", createdAt }Save the run ID as soon as the request is accepted.agent_run.started{ id, status: "running" }Mark the run as actively processing.agent_run.completedThe completed Agent run objectRead the final answer from data.output.text or data.output.structured, and citations from data.output.grounding.agent_run.failed{ id, status: "failed", error }Surface error.code and error.message; no completed output is available.agent_run.cancelled{ id, status: "cancelled", ... }Stop consuming the stream and handle the run as cancelled. Events associated with the same research step include a callId. It corresponds to item.call_id in tool progress events. Use it to group search traces, sources, and tool progress. Some search-trace descriptions are generated asynchronously and can arrive after the source or tool event they describe, so do not correlate them by arrival order alone. Treat agent_run.source.added as a live preview rather than a complete citation list. The terminal run’s output.grounding is the authoritative grounding output. Replay stored events For non-ZDR runs, GET /agent/runs/{id}/events returns stored events as paginated JSON. Send Accept: text/event-stream to replay the stored events as SSE, and Last-Event-ID to skip events your client has already processed: cURLcurl -N "https://api.exa.ai/agent/runs/agent_run_01j.../events" \ -H "Accept: text/event-stream" \ -H "Last-Event-ID: 12" \ -H "Authorization: Bearer $EXA_API_KEY" The replay endpoint sends the events stored at request time and then closes; it does not continue following a running run. ZDR runs do not retain events and cannot be replayed. For forward compatibility, ignore event names your application does not recognize and continue until a terminal event arrives. Return structured JSON Use outputSchema to return schema-validated JSON in output.structured. outputSchema supports the JSON Schema specification. Runs with a schema that no output can satisfy fail fast with a 400 INVALID_OUTPUT_SCHEMA error. For example, a root object with additionalProperties: false whose required list names a property missing from its properties. To request contact information, describe the desired contact fields in outputSchema. Use standard JSON Schema shapes such as { "type": "string", "format": "email" } for email addresses, { "type": "string", "format": "phone" } for phone numbers, and { "type": "s