Quick Start
Install the SDK and wire up your stores, then create an agent instance and callagent.query().
Querying with Attachments
Pass one or moreattachments alongside your question. The pipeline interprets each file during Phase 1 before retrieval begins, so evidence from the attachments is available to every downstream reasoner.
Pipeline Phases
The query agent runs six sequential phases for every question. Retrieval and reasoning phases run in parallel across sub-questions to keep latency low.1
Interpret Attachments
If attachments are present, the agent processes each one with a vision-capable or PDF-aware model. Each interpreted file becomes an
EvidenceItem that flows into the retrieval and reasoning phases alongside document store results.2
Classify
The question is classified into a
QueryIntent, broken into sub-questions, and evaluated for storage requirements. Classification drives which retrieval strategies run in Phase 4.Supported intents: policy_question · coverage_comparison · document_search · claims_inquiry · general_knowledge3
Plan Retrieval and Retrieve
The planner checks whether a lookup is actually needed — for example, if the conversation history already contains a complete answer, retrieval can be skipped entirely. This keeps token usage low for follow-up questions.When retrieval is needed, four strategies run in parallel up to the configured
concurrency limit:- Chunk search — semantic similarity search across indexed document chunks
- Document lookup — structured look up by carrier, policy number, or document type
- Source retrieval — fetches raw source spans via the optional
SourceRetriever - Conversation history — recent turns for continuity and reference
4
Reason (Parallel)
Each sub-question gets its own reasoner, and they all run in parallel. Critically, each reasoner only sees its assigned evidence items — never full documents. This constraint enforces grounding and makes citation tracking possible: every factual claim maps back to a specific chunk.
5
Verify
The verifier checks three properties across all sub-answers:
- Grounding — every claim has a citation that actually supports it
- Consistency — sub-answers don’t contradict each other
- Completeness — the original question is fully addressed
6
Respond
Sub-answers are merged into a single coherent response. Citations are deduplicated and assigned sequential display numbers (
[1], [2], etc.). The final QueryOutput is returned with the answer, citations, confidence score, and review report.Reasoners only see evidence items, never full documents. This design forces grounding and enables precise citation tracking — every
[n] reference in the answer maps to a specific chunk ID and quoted passage.Configuration
Pass options tocreateQueryAgent() to tune retrieval depth, parallelism, and observability hooks.
GenerateTextFn
required
Text generation function from your AI provider (e.g. Vercel AI SDK’s
generateText).GenerateObjectFn
required
Structured object generation function for classification and reasoning schemas.
DocumentStore
required
Store used for chunk search and document lookup during retrieval.
MemoryStore
required
Conversation memory store used to retrieve and persist turn history.
SourceRetriever
Optional retriever for raw source spans. When omitted, source retrieval is skipped.
number
default:"3"
Maximum number of retrievers or reasoners to run in parallel.
number
default:"1"
How many times the verifier may trigger a targeted retry before accepting the current answers.
number
default:"10"
Maximum number of evidence items fetched per sub-question during retrieval.
"hybrid" | "semantic" | "keyword"
default:"\"hybrid\""
Strategy used when searching document chunks.
hybrid combines semantic and keyword matching.(usage: TokenUsage) => void
Callback fired after each phase with a cumulative token usage snapshot.
(message: string) => void
Callback fired with a human-readable progress message at each phase transition.
Output Shape
Every call toagent.query() resolves to a QueryOutput object.
string
The final merged answer with inline citation markers like
[1], [2].Citation[]
Ordered list of citations referenced in the answer. See the Citations guide for the full
Citation shape.QueryIntent
Classified intent:
policy_question · coverage_comparison · document_search · claims_inquiry · general_knowledge.number
Aggregate confidence score from
0 to 1 reflecting grounding quality and evidence coverage.string
Optional suggested follow-up question surfaced by the reasoner when the answer is partial or ambiguous.
TokenUsage
Total prompt and completion tokens consumed across all phases.
QueryReviewReport
Detailed grounding, consistency, and completeness report from the verifier phase.