@weaviate/agents 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +130 -2
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/query/agent.d.ts +539 -0
  6. package/dist/query/agent.js +373 -0
  7. package/dist/query/agent.test.d.ts +1 -0
  8. package/dist/query/agent.test.js +1118 -0
  9. package/dist/query/collection.d.ts +22 -0
  10. package/dist/query/collection.js +12 -0
  11. package/dist/query/connection.d.ts +10 -0
  12. package/dist/query/connection.js +19 -0
  13. package/dist/query/filter.d.ts +2 -0
  14. package/dist/query/filter.js +20 -0
  15. package/dist/query/index.d.ts +4 -0
  16. package/dist/query/index.js +3 -0
  17. package/dist/query/media.d.ts +25 -0
  18. package/dist/query/media.js +24 -0
  19. package/dist/query/response/api-response-mapping.d.ts +3 -0
  20. package/dist/query/response/api-response-mapping.js +172 -0
  21. package/dist/query/response/api-response.d.ts +219 -0
  22. package/dist/query/response/api-response.js +1 -0
  23. package/dist/query/response/error.d.ts +6 -0
  24. package/dist/query/response/error.js +34 -0
  25. package/dist/query/response/index.d.ts +2 -0
  26. package/dist/query/response/index.js +2 -0
  27. package/dist/query/response/response-mapping.d.ts +23 -0
  28. package/dist/query/response/response-mapping.js +308 -0
  29. package/dist/query/response/response.d.ts +332 -0
  30. package/dist/query/response/response.js +44 -0
  31. package/dist/query/response/server-sent-events.d.ts +14 -0
  32. package/dist/query/response/server-sent-events.js +85 -0
  33. package/dist/query/search.d.ts +37 -0
  34. package/dist/query/search.js +87 -0
  35. package/package.json +46 -3
@@ -0,0 +1,539 @@
1
+ import { WeaviateClient } from "@weaviate/core";
2
+ import { z } from "zod";
3
+ import { QueryAgentResponse, ProgressMessage, StreamedTokens, AskModeResponse, SuggestQueryResponse, ParsedAskModeResponse } from "./response/response.js";
4
+ import { QueryAgentCollection, QueryAgentCollectionConfig } from "./collection.js";
5
+ import { SearchModeResponse } from "./response/response.js";
6
+ /**
7
+ * An agent for executing agentic queries against Weaviate.
8
+ *
9
+ * For more information, see the [Weaviate Agents - Query Agent Docs](https://weaviate.io/developers/agents).
10
+ */
11
+ export declare class QueryAgent {
12
+ private client;
13
+ private collections?;
14
+ private systemPrompt?;
15
+ private agentsHost;
16
+ /**
17
+ * Initialize the Query Agent.
18
+ *
19
+ * @param client - The Weaviate client connected to a Weaviate Cloud cluster.
20
+ * @param options - Configuration for the agent.
21
+ * @param options.collections - The collections to query. Either a list of strings, or a list of
22
+ * {@link QueryAgentCollectionConfig} objects. Will be overridden if passed in any of the agent's
23
+ * methods that support it.
24
+ * @param options.systemPrompt - Optional prompt to control the tone, format, and style of the
25
+ * agent's final response. This prompt is both passed to the query writer agent, and applied
26
+ * when generating the answer after all research and data retrieval is complete.
27
+ * @param options.agentsHost - Optional host of the agents service.
28
+ */
29
+ constructor(client: WeaviateClient, { collections, systemPrompt, agentsHost, }?: QueryAgentOptions);
30
+ /**
31
+ * Run the query agent.
32
+ *
33
+ * @deprecated The `run` method is deprecated; use {@link ask} instead.
34
+ * @param query - The natural language query string for the agent.
35
+ * @param options - Options for this run.
36
+ * @param options.collections - The collections to query. Will override any collections passed in the constructor.
37
+ * @param options.context - Optional previous response from the agent.
38
+ * @returns The response from the query agent.
39
+ */
40
+ run(query: string, { collections, context }?: QueryAgentRunOptions): Promise<QueryAgentResponse>;
41
+ /** @hidden */
42
+ ask<S extends z.ZodType>(query: QueryAgentQuery, options: QueryAgentAskOptions & {
43
+ outputFormat: S;
44
+ }): Promise<ParsedAskModeResponse<z.infer<S>>>;
45
+ /** @hidden */
46
+ ask(query: QueryAgentQuery, options: QueryAgentAskOptions & {
47
+ outputFormat: Record<string, unknown>;
48
+ }): Promise<ParsedAskModeResponse<Record<string, unknown>>>;
49
+ /**
50
+ * Run the Query Agent ask mode.
51
+ *
52
+ * Performs an agentic search on the collections and returns a natural language answer to the query.
53
+ *
54
+ * @param query - The natural language query string, or a list of chat messages, for the agent.
55
+ * @param options - Options for this ask invocation.
56
+ * @param options.collections - The collections to query. Either a list of strings, or a list of
57
+ * {@link QueryAgentCollectionConfig} objects. Will override any collections passed in the constructor.
58
+ * @param options.resultEvaluation - One of `"llm"` or `"none"`.
59
+ * If `"llm"`, the final answer will be cross-compared to the sources, and those sources will be
60
+ * filtered to only those in the answer. Also populates the `missingInformation` and
61
+ * `isPartialAnswer` fields of the response.
62
+ * If `"none"`, the result will not be evaluated, and the sources will not be filtered.
63
+ * Defaults to `"none"`.
64
+ * @param options.outputFormat - The structured output format to return. Either a Zod schema, a JSON Schema object, or undefined.
65
+ * If a Zod schema is provided, the final answer will be parsed and validated into the schema, and the response will be returned as a {@link ParsedAskModeResponse} whose `finalAnswerParsed` is typed as `z.infer<typeof schema>`.
66
+ * If a JSON Schema object (Draft 2020-12) is provided, the final answer will be parsed as JSON, and the response will be returned as a {@link ParsedAskModeResponse} whose `finalAnswerParsed` is typed as `Record<string, unknown>`.
67
+ * If undefined (the default, no structured output), the answer is plain text on `finalAnswer` and an {@link AskModeResponse} is returned.
68
+ * To generate an image, include a {@link GeneratedImage} field in a Zod schema. The generated image is returned as a base64 PNG on that field's `base64` in `finalAnswerParsed`.
69
+ * @returns An {@link AskModeResponse} (or {@link ParsedAskModeResponse} when `outputFormat` is set)
70
+ * which contains the final answer, sources, and other metadata such as the searches performed,
71
+ * usage and total time.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const agent = new QueryAgent(client, { collections: ["FinancialContracts"] });
76
+ * const response = await agent.ask(
77
+ * "What are the terms of the contract signed by John Smith in May 2025?",
78
+ * );
79
+ * ```
80
+ *
81
+ * @example Structured output with a Zod schema. The final answer is parsed and
82
+ * validated into the schema, and exposed (typed) on `finalAnswerParsed`.
83
+ * ```ts
84
+ * import { z } from "zod";
85
+ *
86
+ * const CitedText = z.object({
87
+ * text: z.string(),
88
+ * sources: z
89
+ * .array(z.string())
90
+ * .describe("The sources that support this section of text. Can be empty."),
91
+ * });
92
+ * const AnswerWithSources = z.object({ texts: z.array(CitedText) });
93
+ *
94
+ * const agent = new QueryAgent(client, { collections: ["FinancialContracts"] });
95
+ * const result = await agent.ask(
96
+ * "What contracts were signed by Jane Doe in 2024? What were they about?",
97
+ * { outputFormat: AnswerWithSources },
98
+ * );
99
+ * // result.finalAnswerParsed is typed as { texts: { text: string; sources: string[] }[] }
100
+ * console.log(result.finalAnswerParsed.texts);
101
+ * ```
102
+ *
103
+ * @example Image generation. Each image field is returned with the generated image
104
+ * as base64. Use {@link generatedImageWithOptions} to set options such as the shape.
105
+ * ```ts
106
+ * import { z } from "zod";
107
+ * import { GeneratedImage } from "@weaviate/agents";
108
+ *
109
+ * const AnswerWithImage = z.object({
110
+ * answer: z.string(),
111
+ * image: GeneratedImage.describe("An advertisement for the product."),
112
+ * });
113
+ *
114
+ * const agent = new QueryAgent(client, { collections: ["ECommerce"] });
115
+ * const result = await agent.ask("What is the best selling product?", {
116
+ * outputFormat: AnswerWithImage,
117
+ * });
118
+ * const imageBytes = Buffer.from(result.finalAnswerParsed.image.base64, "base64");
119
+ * ```
120
+ */
121
+ ask(query: QueryAgentQuery, options?: QueryAgentAskOptions): Promise<AskModeResponse>;
122
+ /** @hidden */
123
+ stream(query: string, options: QueryAgentStreamOptions & {
124
+ includeProgress: false;
125
+ includeFinalState: false;
126
+ }): AsyncGenerator<StreamedTokens>;
127
+ /** @hidden */
128
+ stream(query: string, options: QueryAgentStreamOptions & {
129
+ includeProgress: false;
130
+ includeFinalState?: true;
131
+ }): AsyncGenerator<StreamedTokens | QueryAgentResponse>;
132
+ /** @hidden */
133
+ stream(query: string, options: QueryAgentStreamOptions & {
134
+ includeProgress?: true;
135
+ includeFinalState: false;
136
+ }): AsyncGenerator<ProgressMessage | StreamedTokens>;
137
+ /**
138
+ * Stream responses from the query agent.
139
+ *
140
+ * @deprecated The `stream` method is deprecated; use {@link askStream} instead.
141
+ * @param query - The natural language query string for the agent.
142
+ * @param options - Options for the stream.
143
+ * @param options.collections - The collections to query. Will override any collections passed in the constructor.
144
+ * @param options.context - Optional previous response from the agent.
145
+ * @param options.includeProgress - Whether to include progress messages in the stream. These are
146
+ * informational messages about the progress of the agent's search.
147
+ * @param options.includeFinalState - Whether to include the final state in the stream. This is
148
+ * the final {@link QueryAgentResponse}, yielded as the last item in the stream.
149
+ * @returns An async generator yielding {@link ProgressMessage}, {@link StreamedTokens}, and a
150
+ * final {@link QueryAgentResponse}, depending on the include flags.
151
+ */
152
+ stream(query: string, options?: QueryAgentStreamOptions & {
153
+ includeProgress?: true;
154
+ includeFinalState?: true;
155
+ }): AsyncGenerator<ProgressMessage | StreamedTokens | QueryAgentResponse>;
156
+ /** @hidden */
157
+ askStream<S extends z.ZodType>(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
158
+ outputFormat: S;
159
+ includeProgress: false;
160
+ includeFinalState: false;
161
+ }): AsyncGenerator<StreamedTokens>;
162
+ /** @hidden */
163
+ askStream<S extends z.ZodType>(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
164
+ outputFormat: S;
165
+ includeProgress: false;
166
+ includeFinalState?: true;
167
+ }): AsyncGenerator<StreamedTokens | ParsedAskModeResponse<z.infer<S>>>;
168
+ /** @hidden */
169
+ askStream<S extends z.ZodType>(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
170
+ outputFormat: S;
171
+ includeProgress?: true;
172
+ includeFinalState: false;
173
+ }): AsyncGenerator<ProgressMessage | StreamedTokens>;
174
+ /** @hidden */
175
+ askStream<S extends z.ZodType>(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
176
+ outputFormat: S;
177
+ includeProgress?: true;
178
+ includeFinalState?: true;
179
+ }): AsyncGenerator<ProgressMessage | StreamedTokens | ParsedAskModeResponse<z.infer<S>>>;
180
+ /** @hidden */
181
+ askStream(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
182
+ outputFormat: Record<string, unknown>;
183
+ includeProgress: false;
184
+ includeFinalState: false;
185
+ }): AsyncGenerator<StreamedTokens>;
186
+ /** @hidden */
187
+ askStream(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
188
+ outputFormat: Record<string, unknown>;
189
+ includeProgress: false;
190
+ includeFinalState?: true;
191
+ }): AsyncGenerator<StreamedTokens | ParsedAskModeResponse<Record<string, unknown>>>;
192
+ /** @hidden */
193
+ askStream(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
194
+ outputFormat: Record<string, unknown>;
195
+ includeProgress?: true;
196
+ includeFinalState: false;
197
+ }): AsyncGenerator<ProgressMessage | StreamedTokens>;
198
+ /** @hidden */
199
+ askStream(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
200
+ outputFormat: Record<string, unknown>;
201
+ includeProgress?: true;
202
+ includeFinalState?: true;
203
+ }): AsyncGenerator<ProgressMessage | StreamedTokens | ParsedAskModeResponse<Record<string, unknown>>>;
204
+ /** @hidden */
205
+ askStream(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
206
+ outputFormat?: undefined;
207
+ includeProgress: false;
208
+ includeFinalState: false;
209
+ }): AsyncGenerator<StreamedTokens>;
210
+ /** @hidden */
211
+ askStream(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
212
+ outputFormat?: undefined;
213
+ includeProgress: false;
214
+ includeFinalState?: true;
215
+ }): AsyncGenerator<StreamedTokens | AskModeResponse>;
216
+ /** @hidden */
217
+ askStream(query: QueryAgentQuery, options: QueryAgentAskStreamOptions & {
218
+ outputFormat?: undefined;
219
+ includeProgress?: true;
220
+ includeFinalState: false;
221
+ }): AsyncGenerator<ProgressMessage | StreamedTokens>;
222
+ /**
223
+ * Run the Query Agent ask mode and stream the response.
224
+ *
225
+ * @param query - The natural language query string, or a list of chat messages, for the agent.
226
+ * @param options - Options for the ask stream.
227
+ * @param options.collections - The collections to query. Either a list of strings, or a list of
228
+ * {@link QueryAgentCollectionConfig} objects. Will override any collections passed in the constructor.
229
+ * @param options.includeProgress - Whether to include progress messages in the stream. These are
230
+ * informational messages about the progress of the agent's search.
231
+ * @param options.includeFinalState - Whether to include the final state in the stream. This is
232
+ * the final {@link AskModeResponse}, yielded as the last item in the stream.
233
+ * @param options.resultEvaluation - One of `"llm"` or `"none"`.
234
+ * If `"llm"`, the final answer will be cross-compared to the sources, and those sources will be
235
+ * filtered to only those in the answer. Also populates the `missingInformation` and
236
+ * `isPartialAnswer` fields of the response.
237
+ * If `"none"`, the result will not be evaluated, and the sources will not be filtered.
238
+ * Defaults to `"none"`.
239
+ * @param options.outputFormat - The structured output format to return. Either a Zod schema, a JSON Schema object, or undefined.
240
+ * If a Zod schema is provided, the final answer will be parsed and validated into the schema, and the response will be returned as a `ParsedAskModeResponse` with the inferred type.
241
+ * If a JSON Schema object is provided, the final answer will be parsed as JSON, and the response will be returned as a `ParsedAskModeResponse` with the type `Record<string, unknown>`.
242
+ * If undefined, the final answer will be returned as a `AskModeResponse` with the type `string`.
243
+ * To generate an image, include a {@link GeneratedImage} field in a Zod schema. The generated image is returned as a base64 PNG on that field's `base64` in `finalAnswerParsed`.
244
+ * The streamed tokens of the final answer never include `base64`. It is added after generation, so it only appears in the final state.
245
+ * @returns An async generator yielding any of the following:
246
+ *
247
+ * - {@link ProgressMessage}: informational messages about the progress of the agent's search
248
+ * (if `includeProgress` is `true`).
249
+ * - {@link StreamedTokens}: token deltas from the agent's response.
250
+ * - {@link AskModeResponse}: the final response, yielded as the last item in the stream
251
+ * (if `includeFinalState` is `true`).
252
+ *
253
+ * @example
254
+ * ```ts
255
+ * const agent = new QueryAgent(client, { collections: ["FinancialContracts"] });
256
+ * for await (const event of agent.askStream(
257
+ * "What are the terms of the contract signed by John Smith in May 2025?",
258
+ * )) {
259
+ * if ("finalAnswer" in event) {
260
+ * // AskModeResponse
261
+ * console.log(event.finalAnswer);
262
+ * } else if ("delta" in event) {
263
+ * // StreamedTokens
264
+ * process.stdout.write(event.delta);
265
+ * } else {
266
+ * // ProgressMessage
267
+ * console.log(event.message);
268
+ * }
269
+ * }
270
+ * ```
271
+ *
272
+ * @example Structured output with a Zod schema. When `includeFinalState` is on
273
+ * (the default), the final-state event is a {@link ParsedAskModeResponse} whose
274
+ * `finalAnswerParsed` is typed from the schema.
275
+ * ```ts
276
+ * import { z } from "zod";
277
+ *
278
+ * const CitedText = z.object({
279
+ * text: z.string(),
280
+ * sources: z
281
+ * .array(z.string())
282
+ * .describe("The sources that support this section of text. Can be empty."),
283
+ * });
284
+ * const AnswerWithSources = z.object({ texts: z.array(CitedText) });
285
+ *
286
+ * const agent = new QueryAgent(client, { collections: ["FinancialContracts"] });
287
+ * for await (const event of agent.askStream(
288
+ * "What contracts were signed by Jane Doe in 2024? What were they about?",
289
+ * { outputFormat: AnswerWithSources },
290
+ * )) {
291
+ * if ("finalAnswerParsed" in event) {
292
+ * // ParsedAskModeResponse — finalAnswerParsed is typed from the schema
293
+ * console.log(event.finalAnswerParsed.texts);
294
+ * } else if ("delta" in event) {
295
+ * process.stdout.write(event.delta);
296
+ * } else {
297
+ * console.log(event.message);
298
+ * }
299
+ * }
300
+ * ```
301
+ *
302
+ * @example Image generation. The image's base64 is only populated on the final state.
303
+ * ```ts
304
+ * import { z } from "zod";
305
+ * import { GeneratedImage } from "@weaviate/agents";
306
+ *
307
+ * const AnswerWithImage = z.object({
308
+ * answer: z.string(),
309
+ * image: GeneratedImage.describe("An advertisement for the product."),
310
+ * });
311
+ *
312
+ * const agent = new QueryAgent(client, { collections: ["ECommerce"] });
313
+ * for await (const event of agent.askStream("What is the best selling product?", {
314
+ * outputFormat: AnswerWithImage,
315
+ * })) {
316
+ * if ("finalAnswerParsed" in event) {
317
+ * const imageBytes = Buffer.from(event.finalAnswerParsed.image.base64, "base64");
318
+ * } else if ("delta" in event) {
319
+ * process.stdout.write(event.delta);
320
+ * } else {
321
+ * console.log(event.message);
322
+ * }
323
+ * }
324
+ * ```
325
+ */
326
+ askStream(query: QueryAgentQuery, options?: QueryAgentAskStreamOptions & {
327
+ outputFormat?: undefined;
328
+ includeProgress?: true;
329
+ includeFinalState?: true;
330
+ }): AsyncGenerator<ProgressMessage | StreamedTokens | AskModeResponse>;
331
+ /**
332
+ * Run the Query Agent search-only mode.
333
+ *
334
+ * Sends the initial search request and returns a {@link SearchModeResponse} containing the
335
+ * first page of results. To paginate, call `response.next({ limit, offset })` on the returned
336
+ * response. This reuses the same underlying searches to ensure a consistent result set across
337
+ * pages.
338
+ *
339
+ * @param query - The natural language query string, or a list of chat messages, for the agent.
340
+ * @param options - Options for this search invocation.
341
+ * @param options.limit - The maximum number of results to return for the first page. Defaults to 20.
342
+ * @param options.collections - The collections to query. Either a list of strings, or a list of
343
+ * {@link QueryAgentCollectionConfig} objects. Will override any collections passed in the constructor.
344
+ * @param options.diversityWeight - Optional number between `0.0` and `1.0` to diversify results
345
+ * with MMR reranking. Higher values push for more topical variety at the cost of relevance.
346
+ * Defaults to no diversity.
347
+ * @param options.filtering - The filtering strategy: `"recall"` for broader retrieval or
348
+ * `"precision"` for more targeted results. Defaults to `"recall"`.
349
+ * @param options.effort - The amount of effort the agent should put into the search. One of
350
+ * `"medium"`, `"high"`, or `"ultrahigh"`. Higher effort may improve result quality at the
351
+ * expense of increased latency and cost.
352
+ * @returns A {@link SearchModeResponse} for the first page of results. Use
353
+ * `response.next({ limit, offset })` to paginate.
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * const agent = new QueryAgent(client, { collections: ["FinancialContracts"] });
358
+ * const page1 = await agent.search("Find all NDAs signed by Jane Doe in 2024.", { limit: 5 });
359
+ * const page2 = await page1.next({ limit: 5, offset: 5 });
360
+ * const page3 = await page2.next({ limit: 5, offset: 10 });
361
+ * ```
362
+ */
363
+ search(query: QueryAgentQuery, { limit, collections, diversityWeight, filtering, effort, }?: QueryAgentSearchOnlyOptions): Promise<SearchModeResponse>;
364
+ /**
365
+ * Suggest queries for the data in your collections.
366
+ *
367
+ * Uses the agent to generate example queries that can be run against the given collections.
368
+ * This can help users discover what kinds of questions they can ask, or generate example prompts
369
+ * for a dataset.
370
+ *
371
+ * @param options - Options for the suggest-queries request.
372
+ * @param options.collections - Optional override for the collections configured at instantiation.
373
+ * Either a list of strings, or a list of {@link QueryAgentCollectionConfig} objects.
374
+ * @param options.numQueries - The number of queries to suggest. Defaults to 3.
375
+ * @param options.instructions - Optional natural language guidance for the style, topic, or
376
+ * language of the suggested queries. Supplied in addition to the agent's system instructions.
377
+ * @param options.conversation - Optional conversation history to contextualise suggested queries
378
+ * as follow-up questions. Each element is a {@link ChatMessage} with `role` and `content`.
379
+ * @returns A {@link SuggestQueryResponse} containing the list of suggested queries, along with
380
+ * additional metadata if present.
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * const agent = new QueryAgent(client, { collections: ["FinancialContracts"] });
385
+ * const suggestions = await agent.suggestQueries({
386
+ * collections: ["Products"],
387
+ * numQueries: 5,
388
+ * instructions: "Focus on questions about eco-friendly features.",
389
+ * conversation: [
390
+ * { role: "user", content: "What topics are covered?" },
391
+ * { role: "assistant", content: "The collection covers ML and economics." },
392
+ * ],
393
+ * });
394
+ * ```
395
+ */
396
+ suggestQueries({ collections, numQueries, instructions, conversation, }?: QueryAgentSuggestQueriesOptions): Promise<SuggestQueryResponse>;
397
+ private validateCollections;
398
+ }
399
+ /** Options for constructing a {@link QueryAgent}. */
400
+ export type QueryAgentOptions = {
401
+ /**
402
+ * The collections to query. Either a list of strings, or a list of
403
+ * {@link QueryAgentCollectionConfig} objects. Will be overridden if passed in any of the
404
+ * agent's methods that support it.
405
+ */
406
+ collections?: QueryAgentCollection[];
407
+ /**
408
+ * Optional prompt to control the tone, format, and style of the agent's final response. This
409
+ * prompt is both passed to the query writer agent, and applied when generating the answer
410
+ * after all research and data retrieval is complete.
411
+ */
412
+ systemPrompt?: string;
413
+ /** Optional host of the agents service. */
414
+ agentsHost?: string;
415
+ };
416
+ /** The query for a Query Agent invocation. Either a natural language string or a list of chat messages. */
417
+ export type QueryAgentQuery = string | ChatMessage[];
418
+ /** A single chat message in a conversation context passed to the Query Agent. */
419
+ export type ChatMessage = {
420
+ role: "user" | "assistant";
421
+ content: string;
422
+ };
423
+ /**
424
+ * Options for {@link QueryAgent.run}.
425
+ *
426
+ * @deprecated `run` is deprecated; use {@link QueryAgent.ask} with {@link QueryAgentAskOptions} instead.
427
+ */
428
+ export type QueryAgentRunOptions = {
429
+ /** The collections to query. Will override any collections passed in the constructor. */
430
+ collections?: (string | QueryAgentCollectionConfig)[];
431
+ /** Optional previous response from the agent. */
432
+ context?: QueryAgentResponse;
433
+ };
434
+ /**
435
+ * Controls how the agent evaluates the final result.
436
+ *
437
+ * - `"llm"`: cross-compares the final answer to the sources, filters those sources to only the
438
+ * ones used in the answer, and populates `missingInformation` and `isPartialAnswer`.
439
+ * - `"none"`: the result is not evaluated and sources are not filtered.
440
+ */
441
+ export type ResultEvaluation = "llm" | "none";
442
+ /** Options for {@link QueryAgent.ask}. */
443
+ export type QueryAgentAskOptions = {
444
+ /**
445
+ * The collections to query. Either a list of strings, or a list of
446
+ * {@link QueryAgentCollectionConfig} objects. Will override any collections passed in the constructor.
447
+ */
448
+ collections?: (string | QueryAgentCollectionConfig)[];
449
+ /** How the agent should evaluate the final result. See {@link ResultEvaluation}. Defaults to `"none"`. */
450
+ resultEvaluation?: ResultEvaluation;
451
+ };
452
+ /**
453
+ * Options for {@link QueryAgent.stream}.
454
+ *
455
+ * @deprecated `stream` is deprecated; use {@link QueryAgent.askStream} with {@link QueryAgentAskStreamOptions} instead.
456
+ */
457
+ export type QueryAgentStreamOptions = {
458
+ /** The collections to query. Will override any collections passed in the constructor. */
459
+ collections?: (string | QueryAgentCollectionConfig)[];
460
+ /** Optional previous response from the agent. */
461
+ context?: QueryAgentResponse;
462
+ /**
463
+ * Whether to include progress messages in the stream. These are informational messages about the
464
+ * progress of the agent's search.
465
+ */
466
+ includeProgress?: boolean;
467
+ /**
468
+ * Whether to include the final state in the stream. This is the final {@link QueryAgentResponse},
469
+ * yielded as the last item in the stream.
470
+ */
471
+ includeFinalState?: boolean;
472
+ };
473
+ /** Options for {@link QueryAgent.askStream}. */
474
+ export type QueryAgentAskStreamOptions = {
475
+ /**
476
+ * The collections to query. Either a list of strings, or a list of
477
+ * {@link QueryAgentCollectionConfig} objects. Will override any collections passed in the constructor.
478
+ */
479
+ collections?: (string | QueryAgentCollectionConfig)[];
480
+ /**
481
+ * Whether to include progress messages in the stream. These are informational messages about the
482
+ * progress of the agent's search.
483
+ */
484
+ includeProgress?: boolean;
485
+ /**
486
+ * Whether to include the final state in the stream. This is the final {@link AskModeResponse},
487
+ * yielded as the last item in the stream.
488
+ */
489
+ includeFinalState?: boolean;
490
+ /** How the agent should evaluate the final result. See {@link ResultEvaluation}. Defaults to `"none"`. */
491
+ resultEvaluation?: ResultEvaluation;
492
+ };
493
+ /** Options for {@link QueryAgent.search}. */
494
+ export type QueryAgentSearchOnlyOptions = {
495
+ /** The maximum number of results to return for the first page. Defaults to 20. */
496
+ limit?: number;
497
+ /**
498
+ * The collections to query. Either a list of strings, or a list of
499
+ * {@link QueryAgentCollectionConfig} objects. Will override any collections passed in the constructor.
500
+ */
501
+ collections?: (string | QueryAgentCollectionConfig)[];
502
+ /**
503
+ * Optional number between `0.0` and `1.0` to diversify results with MMR reranking. Higher values
504
+ * push for more topical variety at the cost of relevance. Defaults to no diversity.
505
+ */
506
+ diversityWeight?: number;
507
+ /**
508
+ * The filtering strategy to use for the search. `"recall"` optimizes for finding all relevant
509
+ * results (broader retrieval), while `"precision"` optimizes for accuracy of returned results
510
+ * (narrower, more targeted retrieval).
511
+ */
512
+ filtering?: "recall" | "precision";
513
+ /**
514
+ * The amount of effort the agent should put into the search. One of `"medium"`, `"high"`, or
515
+ * `"ultrahigh"`. Higher effort may improve result quality at the expense of increased latency
516
+ * and cost.
517
+ */
518
+ effort?: "medium" | "high" | "ultrahigh";
519
+ };
520
+ /** Options for {@link QueryAgent.suggestQueries}. */
521
+ export type QueryAgentSuggestQueriesOptions = {
522
+ /**
523
+ * Optional override for the collections configured at instantiation. Either a list of strings,
524
+ * or a list of {@link QueryAgentCollectionConfig} objects.
525
+ */
526
+ collections?: (string | QueryAgentCollectionConfig)[];
527
+ /** The number of queries to suggest. Defaults to 3. */
528
+ numQueries?: number;
529
+ /**
530
+ * Optional natural language guidance for the style, topic, or language of the suggested queries.
531
+ * Supplied in addition to the agent's system instructions.
532
+ */
533
+ instructions?: string;
534
+ /**
535
+ * Optional conversation history to contextualise suggested queries as follow-up questions.
536
+ * Each element is a {@link ChatMessage} with `role` and `content`.
537
+ */
538
+ conversation?: ChatMessage[];
539
+ };