页面简介
Tune query quality, structured output, effort, and cost for production Exa Agent integrations.
正文摘录
Use this guide after the Exa Agent quickstart to improve query quality, structure outputs, and control runtime and cost. For complete requests, start with Agent examples. Core principles Treat query as a task specification. Name what Agent should find, the scope of the work, the evidence required, and what a complete result looks like. PythonJavaScriptcURLrun = exa.agent.runs.create( query="Find up to 10 current engineering leaders at AI infrastructure companies that raised a Series A or B in the last 6 months. Include only people whose current role and company funding can be verified from public sources.", ) Without an outputSchema, Agent returns prose in output.text and citations in output.grounding. Add another field only when it has a clear job: FieldUse it whenoutputSchemaDownstream code needs structured fieldsinput.dataYou already have rows to enrichinput.exclusionKnown records should not be returneddataSourcesA field should come from an Exa Connect partnerpreviousRunIdThe request continues a completed runeffortCost or research depth needs an explicit settingbudget.maxCostDollarsAn auto or ultra run needs a cost ceiling, or a fixed-effort run needs a contact-enrichment capuserIdentifierThe run is made on behalf of one of your users; see end-user attribution. A follow-up run that omits it keeps the previous run’s value Keep rows, exclusions, and response shape in their dedicated fields rather than embedding them in query. Writing list-building and enrichment queries For list building, define the entity, target count, qualification criteria, exclusions, and evidence bar. For enrichment, put the existing records in input.data and describe only the research Agent should add. Ask for a rationale when qualification requires judgment. Give examples only when a criterion has multiple plausible interpretations. QueryFind up to 20 current engineering leaders at US-based AI infrastructure companies that announced a Series A or B between March 1 and August 31, 2026. Include CTOs, VPs of Engineering, and Heads of Engineering. Exclude founders without an operating engineering role and anyone whose current employment cannot be verified. For each person, return their name, current title, company, company website, funding announcement date, and a short explanation of why they qualify. Verify employment on the company website or another current source, and verify funding from the company announcement or a reputable business publication. See Find all GTM members for a discovery request and Enrich input rows for the corresponding row-enrichment pattern. Handle asynchronous runs Agent runs can take seconds to minutes while they search, read, and reason. Build around the lifecycle instead of holding an application request open. 1Create and persistCreate the run and save its returned id with your request metadata. The create response is not the final result.2Wait for a terminal stateUse an SDK polling helper, poll GET /agent/runs/{id}, or consume the SSE stream. Continue while the run is queued or running.3Store the resultStop waiting at completed, failed, or cancelled, then persist the terminal response and grounding. Persisting the run ID lets your application recover after a restart, reconnect to a stream, and inspect failures. Keep latency down by narrowing the scope, limiting result count, keeping the schema focused, and choosing minimal or low when speed matters more than completeness. For batches, benchmark representative tasks before estimating concurrency or putting Agent on a synchronous UI path. Runtime varies with item count, schema complexity, source availability, and effort. For Zero Data Retention teams, consume the live stream or poll within the retention window. previousRunId is not available, and dataSources can include only ZDR-eligible Connect providers; any other provider returns a 400 error that names it. See Zero Data Retention. Write custom JSON schemas for structured output Use outputSchema when downstream code needs machine-readable fields, normalized values, table rows, or enrichment records. If a prose answer is enough, omit it and read output.text; structured output adds formatting work and can increase latency. Keep research instructions in query and response shape in outputSchema. Use clear property names and descriptions, choose the narrowest useful types, and bound arrays with maxItems. Output schema{ "type": "object", "properties": { "people": { "type": "array", "maxItems": 10, "description": "Current engineering leaders who satisfy every criterion in the query.", "items": { "type": "object", "properties": { "name": { "type": "string", "description": "The person's full name." }, "job_title": { "type": "string", "description": "Their current title at the qualifying company." }, "company": { "type": "string", "description": "The qualifying company's canonical name." }, "qualification_rationale": { "type": "string", "description": "A concise explanation of how the person satisfies the query criteria." } }, "required": ["name", "job_title", "company", "qualification_rationale"] } } }, "required": ["people"] } See all 33 lines Schema adherence validates shape, not facts. Agent may return null when evidence does not support a field, even if the submitted schema marks it as required or non-nullable. stopReason: schema_satisfied means Agent considers the expected shape complete with those nulls allowed; it does not guarantee strict validation against the submitted schema. Do not duplicate Exa’s built-in citations or confidence in your schema. Add a rationale field only when each item should explain why it qualifies, and persist output.grounding with the structured result. Verify important claims against their sources and test schema changes on representative inputs before shipping. Browse the structured Agent examples to compare schemas for list building, KYB, job postings, exclusions, and continued runs. Agent vs Search NeedStart withWeb results for your LLMSearchFast research and synthesisDeep SearchAsync list building, multi-hop research, or enrichmentAgent Use Agent when the work requires several retrieval steps, per-entity verification, or enrichment over known records. Use Search when you need pages quickly and your application will perform the remaining reasoning. Tips for common use cases If you needUseAvoidA researched list of unknown sizeauto and a bounded outputSchemaA fixed cheap effort and an unbounded arrayEnrichment of records you already haveinput.data plus fields to addPasting the table into queryA follow-up over the last result setpreviousRunIdRe-sending the full previous outputRecords that should not appear againinput.exclusion plus downstream deduplicationTreating exclusions as a strict identity guaranteePremium provider dataExa Connect with dataSourcesAsking Agent to infer provider-only fields from the open webPredictable per-request costA fixed effortauto or ultra without a budgetCompleteness over latency & costxhigh or ultraRaising effort before tightening the query Next steps Agent quickstartCreate a run, stream events, set effort, and read structured output.Open guideAgent examplesCopy complete list-building, enrichment, KYB, exclusion, and follow-up requests.Browse examplesExa ConnectAdd premium company, people, traffic, compliance, finance, and other provider data.Browse data partnersSearch best practicesRetrieval quality, latency, and synthesis when Search is enough.Read guide