@dxos/assistant 0.8.4-main.f9ba587 → 0.8.4-main.fd6878d

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 (145) hide show
  1. package/dist/lib/browser/chunk-6WRGDEMH.mjs +89 -0
  2. package/dist/lib/browser/chunk-6WRGDEMH.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-NZGGCEF3.mjs +341 -0
  4. package/dist/lib/browser/chunk-NZGGCEF3.mjs.map +7 -0
  5. package/dist/lib/browser/extraction/index.mjs +269 -0
  6. package/dist/lib/browser/extraction/index.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +240 -1905
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs +13 -0
  11. package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs.map +7 -0
  12. package/dist/lib/node-esm/chunk-3UU5V4FS.mjs +91 -0
  13. package/dist/lib/node-esm/chunk-3UU5V4FS.mjs.map +7 -0
  14. package/dist/lib/node-esm/chunk-XOOPGSGW.mjs +343 -0
  15. package/dist/lib/node-esm/chunk-XOOPGSGW.mjs.map +7 -0
  16. package/dist/lib/node-esm/extraction/index.mjs +270 -0
  17. package/dist/lib/node-esm/extraction/index.mjs.map +7 -0
  18. package/dist/lib/node-esm/index.mjs +240 -1906
  19. package/dist/lib/node-esm/index.mjs.map +4 -4
  20. package/dist/lib/node-esm/meta.json +1 -1
  21. package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs +14 -0
  22. package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs.map +7 -0
  23. package/dist/types/src/conversation/context.d.ts +90 -0
  24. package/dist/types/src/conversation/context.d.ts.map +1 -0
  25. package/dist/types/src/conversation/conversation.d.ts +31 -25
  26. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  27. package/dist/types/src/conversation/index.d.ts +1 -0
  28. package/dist/types/src/conversation/index.d.ts.map +1 -1
  29. package/dist/types/src/errors.d.ts +39 -0
  30. package/dist/types/src/errors.d.ts.map +1 -0
  31. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
  32. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +143 -45
  33. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
  34. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
  35. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  36. package/dist/types/src/extraction/extraction.d.ts +106 -44
  37. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  38. package/dist/types/src/functions/index.d.ts +2 -0
  39. package/dist/types/src/functions/index.d.ts.map +1 -0
  40. package/dist/types/src/functions/services.d.ts +7 -0
  41. package/dist/types/src/functions/services.d.ts.map +1 -0
  42. package/dist/types/src/index.d.ts +3 -5
  43. package/dist/types/src/index.d.ts.map +1 -1
  44. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  45. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  46. package/dist/types/src/session/format.d.ts +168 -0
  47. package/dist/types/src/session/format.d.ts.map +1 -0
  48. package/dist/types/src/session/format.test.d.ts +2 -0
  49. package/dist/types/src/session/format.test.d.ts.map +1 -0
  50. package/dist/types/src/session/index.d.ts +1 -0
  51. package/dist/types/src/session/index.d.ts.map +1 -1
  52. package/dist/types/src/session/session.d.ts +123 -239
  53. package/dist/types/src/session/session.d.ts.map +1 -1
  54. package/dist/types/src/session/version-pin.d.ts +4 -4
  55. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  56. package/dist/types/src/templates/index.d.ts +2 -0
  57. package/dist/types/src/templates/index.d.ts.map +1 -0
  58. package/dist/types/src/templates/system.d.ts +22 -0
  59. package/dist/types/src/templates/system.d.ts.map +1 -0
  60. package/dist/types/src/types.d.ts +13 -0
  61. package/dist/types/src/types.d.ts.map +1 -1
  62. package/dist/types/tsconfig.tsbuildinfo +1 -1
  63. package/package.json +46 -22
  64. package/src/{context/binder.ts → conversation/context.ts} +51 -19
  65. package/src/conversation/conversation.ts +90 -68
  66. package/src/conversation/index.ts +1 -0
  67. package/src/errors.ts +10 -0
  68. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +7 -18
  69. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +22 -17
  70. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +4 -3
  71. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +7 -4
  72. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +2 -2
  73. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +1 -1
  74. package/src/extraction/quotes.test.ts +1 -1
  75. package/src/extraction/quotes.ts +1 -1
  76. package/src/functions/index.ts +5 -0
  77. package/src/functions/services.ts +114 -0
  78. package/src/index.ts +3 -5
  79. package/src/session/__snapshots__/session.test.ts.snap +32 -0
  80. package/src/session/artifact-diff.ts +37 -0
  81. package/src/session/format.test.ts +60 -0
  82. package/src/session/format.ts +139 -0
  83. package/src/session/index.ts +1 -0
  84. package/src/session/session.test.ts +87 -57
  85. package/src/session/session.ts +220 -523
  86. package/src/session/version-pin.test.ts +2 -21
  87. package/src/session/version-pin.ts +9 -9
  88. package/src/summarization/summarization.test.ts +82 -106
  89. package/src/templates/format.tpl +55 -0
  90. package/src/templates/index.ts +5 -0
  91. package/src/templates/system.tpl +47 -0
  92. package/src/templates/system.ts +32 -0
  93. package/src/types.ts +45 -1
  94. package/src/typings.d.ts +5 -0
  95. package/dist/types/bin/chat.d.ts +0 -2
  96. package/dist/types/bin/chat.d.ts.map +0 -1
  97. package/dist/types/src/blueprint/blueprint.d.ts +0 -41
  98. package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
  99. package/dist/types/src/blueprint/index.d.ts +0 -3
  100. package/dist/types/src/blueprint/index.d.ts.map +0 -1
  101. package/dist/types/src/blueprint/registry.d.ts +0 -7
  102. package/dist/types/src/blueprint/registry.d.ts.map +0 -1
  103. package/dist/types/src/context/binder.d.ts +0 -34
  104. package/dist/types/src/context/binder.d.ts.map +0 -1
  105. package/dist/types/src/context/binding.d.ts +0 -38
  106. package/dist/types/src/context/binding.d.ts.map +0 -1
  107. package/dist/types/src/context/index.d.ts +0 -3
  108. package/dist/types/src/context/index.d.ts.map +0 -1
  109. package/dist/types/src/research/exa.d.ts +0 -7
  110. package/dist/types/src/research/exa.d.ts.map +0 -1
  111. package/dist/types/src/research/graph.d.ts +0 -41
  112. package/dist/types/src/research/graph.d.ts.map +0 -1
  113. package/dist/types/src/research/graph.test.d.ts +0 -2
  114. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  115. package/dist/types/src/research/index.d.ts +0 -4
  116. package/dist/types/src/research/index.d.ts.map +0 -1
  117. package/dist/types/src/research/research.d.ts +0 -10
  118. package/dist/types/src/research/research.d.ts.map +0 -1
  119. package/dist/types/src/research/research.test.d.ts +0 -2
  120. package/dist/types/src/research/research.test.d.ts.map +0 -1
  121. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  122. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  123. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  124. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  125. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  126. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  127. package/dist/types/src/testing/index.d.ts +0 -3
  128. package/dist/types/src/testing/index.d.ts.map +0 -1
  129. package/src/blueprint/blueprint.ts +0 -75
  130. package/src/blueprint/index.ts +0 -6
  131. package/src/blueprint/registry.ts +0 -15
  132. package/src/context/binding.ts +0 -31
  133. package/src/context/index.ts +0 -6
  134. package/src/research/exa.ts +0 -100
  135. package/src/research/graph.test.ts +0 -15
  136. package/src/research/graph.ts +0 -337
  137. package/src/research/index.ts +0 -7
  138. package/src/research/instructions-research.tpl +0 -97
  139. package/src/research/research.test.ts +0 -190
  140. package/src/research/research.ts +0 -90
  141. package/src/testing/exa-search-1748337321991.ts +0 -131
  142. package/src/testing/exa-search-1748337331526.ts +0 -144
  143. package/src/testing/exa-search-1748337344119.ts +0 -133
  144. package/src/testing/index.ts +0 -11
  145. package/src/typedefs.d.ts +0 -8
@@ -1,337 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema, identity, Option, SchemaAST } from 'effect';
6
-
7
- import { createTool, ToolResult } from '@dxos/ai';
8
- import type { Obj, Relation } from '@dxos/echo';
9
- import { Query, Filter } from '@dxos/echo';
10
- import { type EchoDatabase, type Queue } from '@dxos/echo-db';
11
- import { isEncodedReference } from '@dxos/echo-protocol';
12
- import {
13
- EntityKind,
14
- getSchemaTypename,
15
- getTypeAnnotation,
16
- getTypeIdentifierAnnotation,
17
- create,
18
- getEntityKind,
19
- getSchemaDXN,
20
- ObjectId,
21
- ReferenceAnnotationId,
22
- type BaseObject,
23
- RelationSourceDXNId,
24
- RelationTargetDXNId,
25
- RelationSourceId,
26
- RelationTargetId,
27
- } from '@dxos/echo-schema';
28
- import { mapAst } from '@dxos/effect';
29
- import { DXN } from '@dxos/keys';
30
- import { log } from '@dxos/log';
31
- import { deepMapValues, isNonNullable } from '@dxos/util';
32
-
33
- // TODO(burdon): Unify with the graph schema.
34
- export const Subgraph = Schema.Struct({
35
- /** Objects and relations. */
36
- objects: Schema.Array(Schema.Any),
37
- });
38
- export interface Subgraph extends Schema.Schema.Type<typeof Subgraph> {}
39
-
40
- export type RelatedSchema = {
41
- schema: Schema.Schema.AnyNoContext;
42
- kind: 'reference' | 'relation';
43
- };
44
-
45
- /**
46
- * Find all schemas that are related to the given schema.
47
- *
48
- * @param db
49
- * @param schema
50
- * @returns
51
- */
52
- export const findRelatedSchema = async (
53
- db: EchoDatabase,
54
- anchor: Schema.Schema.AnyNoContext,
55
- ): Promise<RelatedSchema[]> => {
56
- // TODO(dmaretskyi): Query stored schemas.
57
- const allSchemas = [...db.graph.schemaRegistry.schemas];
58
-
59
- // TODO(dmaretskyi): Also do references.
60
- return allSchemas
61
- .filter((schema) => {
62
- if (getTypeAnnotation(schema)?.kind !== EntityKind.Relation) {
63
- return false;
64
- }
65
-
66
- return (
67
- isSchemaAddressableByDxn(anchor, DXN.parse(getTypeAnnotation(schema)!.sourceSchema!)) ||
68
- isSchemaAddressableByDxn(anchor, DXN.parse(getTypeAnnotation(schema)!.targetSchema!))
69
- );
70
- })
71
- .map(
72
- (schema): RelatedSchema => ({
73
- schema,
74
- kind: 'relation',
75
- }),
76
- );
77
- };
78
-
79
- /**
80
- * Non-strict DXN comparison.
81
- * Returns true if the DXN could be resolved to the schema.
82
- */
83
- const isSchemaAddressableByDxn = (schema: Schema.Schema.AnyNoContext, dxn: DXN): boolean => {
84
- if (getTypeIdentifierAnnotation(schema) === dxn.toString()) {
85
- return true;
86
- }
87
-
88
- const t = dxn.asTypeDXN();
89
- if (t) {
90
- return t.type === getSchemaTypename(schema);
91
- }
92
-
93
- return false;
94
- };
95
-
96
- /**
97
- * Perform vector search in the local database.
98
- */
99
- export const createLocalSearchTool = (db: EchoDatabase, queue?: Queue) => {
100
- return createTool('search', {
101
- name: 'local_search',
102
- description: 'Search the local database for information using a vector index',
103
- schema: Schema.Struct({
104
- query: Schema.String.annotations({
105
- description: 'The query to search for. Could be a question or a topic or a set of keywords.',
106
- }),
107
- }),
108
- execute: async ({ query }) => {
109
- const { objects } = await db.query(Query.select(Filter.text(query, { type: 'vector' }))).run();
110
- const results = [...objects];
111
- if (queue) {
112
- const queueObjects = await queue.queryObjects();
113
- // TODO(dmaretskyi): Text search on the queue.
114
- results.push(...queueObjects);
115
- }
116
-
117
- return ToolResult.Success(`
118
- <local_context>
119
- ${JSON.stringify(results, null, 2)}
120
- </local_context>
121
- `);
122
- },
123
- });
124
- };
125
-
126
- /**
127
- * Create a schema for structured data extraction.
128
- */
129
- export const createExtractionSchema = (types: Schema.Schema.AnyNoContext[]) => {
130
- return Schema.Struct({
131
- ...Object.fromEntries(
132
- types.map(preprocessSchema).map((schema, index) => [
133
- `objects_${getSanitizedSchemaName(types[index])}`,
134
- Schema.optional(Schema.Array(schema)).annotations({
135
- description: `The objects of type: ${getSchemaDXN(types[index])?.asTypeDXN()!.type}. ${SchemaAST.getDescriptionAnnotation(types[index].ast).pipe(Option.getOrElse(() => ''))}`,
136
- }),
137
- ]),
138
- ),
139
- });
140
- };
141
-
142
- export const getSanitizedSchemaName = (schema: Schema.Schema.AnyNoContext) => {
143
- return getSchemaDXN(schema)!
144
- .asTypeDXN()!
145
- .type.replaceAll(/[^a-zA-Z0-9]+/g, '_');
146
- };
147
-
148
- export const sanitizeObjects = async (
149
- types: Schema.Schema.AnyNoContext[],
150
- data: Record<string, readonly unknown[]>,
151
- db: EchoDatabase,
152
- queue?: Queue,
153
- ): Promise<BaseObject[]> => {
154
- const entries = types
155
- .map(
156
- (type) =>
157
- data[`objects_${getSanitizedSchemaName(type)}`]?.map((object: any) => ({
158
- data: object,
159
- schema: type,
160
- })) ?? [],
161
- )
162
- .flat();
163
-
164
- const idMap = new Map<string, string>();
165
- const existingIds = new Set<ObjectId>();
166
- const enitties = new Map<ObjectId, Obj.Any | Relation.Any>();
167
-
168
- const resolveId = (id: string): DXN | undefined => {
169
- if (ObjectId.isValid(id)) {
170
- existingIds.add(id);
171
- return DXN.fromLocalObjectId(id);
172
- }
173
-
174
- const mappedId = idMap.get(id);
175
- if (mappedId) {
176
- return DXN.fromLocalObjectId(mappedId);
177
- }
178
-
179
- return undefined;
180
- };
181
-
182
- const res = entries
183
- .map((entry) => {
184
- // This entry mutates existing object.
185
- if (ObjectId.isValid(entry.data.id)) {
186
- return entry;
187
- }
188
-
189
- idMap.set(entry.data.id, ObjectId.random());
190
- entry.data.id = idMap.get(entry.data.id);
191
- return entry;
192
- })
193
- .map((entry) => {
194
- const data = deepMapValues(entry.data, (value, recurse) => {
195
- if (isEncodedReference(value)) {
196
- const ref = value['/'];
197
- const id = resolveId(ref);
198
-
199
- if (id) {
200
- // Link to an existing object.
201
- return { '/': id.toString() };
202
- } else {
203
- // Search URIs?
204
- return { '/': `search:?q=${encodeURIComponent(ref)}` };
205
- }
206
- }
207
-
208
- return recurse(value);
209
- });
210
-
211
- if (getEntityKind(entry.schema) === 'relation') {
212
- const sourceDxn = resolveId(data.source);
213
- if (!sourceDxn) {
214
- log.warn('source not found', { source: data.source });
215
- }
216
- const targetDxn = resolveId(data.target);
217
- if (!targetDxn) {
218
- log.warn('target not found', { target: data.target });
219
- }
220
- delete data.source;
221
- delete data.target;
222
- data[RelationSourceDXNId] = sourceDxn;
223
- data[RelationTargetDXNId] = targetDxn;
224
- }
225
-
226
- return {
227
- data,
228
- schema: entry.schema,
229
- };
230
- })
231
- .filter((object) => !existingIds.has(object.data.id)); // TODO(dmaretskyi): This dissallows updating existing objects.
232
-
233
- // TODO(dmaretskyi): Use ref resolver.
234
- const { objects: dbObjects } = await db.query(Query.select(Filter.ids(...existingIds))).run();
235
- const queueObjects = (await queue?.getObjectsById([...existingIds])) ?? [];
236
- const objects = [...dbObjects, ...queueObjects].filter(isNonNullable);
237
-
238
- // TODO(dmaretskyi): Returns everything if IDs are empty!
239
- log.info('objects', { dbObjects, queueObjects, existingIds });
240
- const missing = Array.from(existingIds).filter((id) => !objects.some((object) => object.id === id));
241
- if (missing.length > 0) {
242
- throw new Error(`Object IDs do not point to existing objects: ${missing.join(', ')}`);
243
- }
244
-
245
- return res.flatMap(({ data, schema }) => {
246
- let skip = false;
247
- if (RelationSourceDXNId in data) {
248
- const id = (data[RelationSourceDXNId] as DXN).asEchoDXN()?.echoId;
249
- const obj = objects.find((object) => object.id === id) ?? enitties.get(id!);
250
- if (obj) {
251
- delete data[RelationSourceDXNId];
252
- data[RelationSourceId] = obj;
253
- } else {
254
- skip = true;
255
- }
256
- }
257
- if (RelationTargetDXNId in data) {
258
- const id = (data[RelationTargetDXNId] as DXN).asEchoDXN()?.echoId;
259
- const obj = objects.find((object) => object.id === id) ?? enitties.get(id!);
260
- if (obj) {
261
- delete data[RelationTargetDXNId];
262
- data[RelationTargetId] = obj;
263
- } else {
264
- skip = true;
265
- }
266
- }
267
- if (!skip) {
268
- const obj = create(schema, data);
269
- enitties.set(obj.id, obj);
270
- return [obj];
271
- }
272
- return [];
273
- });
274
- };
275
-
276
- const SoftRef = Schema.Struct({
277
- '/': Schema.String,
278
- }).annotations({
279
- description: 'Reference to another object.',
280
- });
281
-
282
- const preprocessSchema = (schema: Schema.Schema.AnyNoContext) => {
283
- const isRelationSchema = getEntityKind(schema) === 'relation';
284
-
285
- const go = (ast: SchemaAST.AST): SchemaAST.AST => {
286
- if (SchemaAST.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome)) {
287
- return SoftRef.ast;
288
- }
289
-
290
- return mapAst(ast, go);
291
- };
292
-
293
- return Schema.make<any, any, never>(mapAst(schema.ast, go)).pipe(
294
- Schema.omit('id'),
295
- Schema.extend(
296
- Schema.Struct({
297
- id: Schema.String.annotations({
298
- description: 'The id of this object. Come up with a unique id based on your judgement.',
299
- }),
300
- }),
301
- ),
302
- isRelationSchema
303
- ? Schema.extend(
304
- Schema.Struct({
305
- source: Schema.String.annotations({
306
- description: 'The id of the source object for this relation.',
307
- }),
308
- target: Schema.String.annotations({
309
- description: 'The id of the target object for this relation.',
310
- }),
311
- }),
312
- )
313
- : identity<Schema.Schema.AnyNoContext>,
314
- );
315
- };
316
-
317
- export const createGraphWriterTool = ({
318
- db,
319
- queue,
320
- schema,
321
- onDone = async (x) => x,
322
- }: {
323
- db: EchoDatabase;
324
- queue?: Queue;
325
- schema: Schema.Schema.AnyNoContext[];
326
- onDone?: (data: Obj.Any[]) => Promise<any>;
327
- }) => {
328
- return createTool('graph', {
329
- name: 'writer',
330
- description: 'Write to the local graph database',
331
- schema: createExtractionSchema(schema),
332
- execute: async (input) => {
333
- const data = await sanitizeObjects(schema, input as any, db, queue);
334
- return ToolResult.Success(await onDone(data as Obj.Any[]));
335
- },
336
- });
337
- };
@@ -1,7 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export * from './exa';
6
- export * from './research';
7
- export * from './graph';
@@ -1,97 +0,0 @@
1
- You are the Research Agent.
2
-
3
- The Research Agent is an expert assistant that conducts in-depth research using real-time web search.
4
- The Research Agent outputs results in a structured format matching the schema provided.
5
-
6
- The Research Agent is equipped with the ability to:
7
-
8
- - Generate precise and effective search queries
9
- - Request web pages by query (through a `web_search` tool)
10
- - Read the full content of retrieved pages
11
- - Synthesize accurate, clear, and structured answers using reliable information from the retrieved content
12
- - Search the local database for information using a vector index (through a `local_search` tool)
13
-
14
- The Research Agent always follows these principles:
15
-
16
- - Relevance First: The Research Agent only returns facts supported by content in retrieved web pages. The Research Agent never fabricates or guesses information.
17
- - Summarize, Don't Copy: The Research Agent synthesizes and rephrases content in its own words. The Research Agent quotes only when necessary.
18
- - Multiple Sources: The Research Agent cross-references at least 2 sources before drawing conclusions, unless the information is directly stated and non-controversial.
19
- - Transparency: The Research Agent mentions which sources were used and explains how it arrived at conclusions.
20
- - Accuracy Over Brevity: The Research Agent prefers detailed, technically accurate explanations over shallow summaries.
21
- - The Research Agent admits uncertainty rather than misleading.
22
- - The Research Agent picks the most concrete schema types for extracted information.
23
- - The Research Agent fills schema fields completely with information it is confident about, and omits fields it is not confident about.
24
- - When outputting results, the Research Agent adds extra data that fits the schema even if not directly related to the user's question.
25
- - The Research Agent creates relations and references between new objects found and what's already in the database.
26
- - The Research Agent does not create objects that are already in the database.
27
- - The Research Agent re-uses existing object IDs as references when enriching existing objects.
28
-
29
- The Research Agent may be asked for:
30
-
31
- - Technical explanations
32
- - Literature reviews
33
- - Comparisons
34
- - Emerging trends
35
- - Implementation strategies
36
-
37
- The Research Agent begins by interpreting the user's request, then:
38
-
39
- The Research Agent breaks it into sub-questions (if applicable).
40
-
41
- For each sub-question, the Research Agent generates a clear, concise web search query.
42
-
43
- The Research Agent uses `web_search`(query) to retrieve information.
44
-
45
- The Research Agent extracts and synthesizes relevant answers.
46
-
47
- The Research Agent's output includes:
48
-
49
- - A clear, structured answer to the user's question
50
- - A citation list or link list of sources used
51
-
52
- Optionally, the Research Agent provides follow-up suggestions or questions for deeper inquiry.
53
-
54
- Here's how the Research Agent operates:
55
-
56
- 1. The Research Agent analyzes the user's request and identifies key topics to search for (3 or more), printing them out.
57
- 2. The Research Agent performs a web search for each topic.
58
- 3. The Research Agent reads and analyzes results, cross references information from multiple sources, and represents conflicting information as ranges of possible values.
59
-
60
- 4. The Research Agent searches the local database for information using a vector index that might link to the user's question.
61
- 6. The Research Agent creates relations and references between new objects and existing database objects when related, using existing object IDs as references.
62
- 7. The Research Agent selects the most concrete schema types for extracted information, using multiple types as needed, and prints its decision and reasoning.
63
- 5. The Research Agent creates a clear, structured answer to the user's question.
64
- 8. The Research Agent submits results using the specific schema.
65
-
66
- IMPORTANT:
67
-
68
- - The Research Agent always runs the `local_search` tool to search the local database at least once before submitting results.
69
- - The Research Agent does not create objects that already exist in the database.
70
- - Ids that are not in the database are human-readable strings like `ivan_zhao_1`.
71
-
72
- Status reporting:
73
-
74
- The Research Agent reports its status frequently using the `<status>` tags: <status>Searching for Google Founders</status>
75
- The Research Agent reports its status in-between each tool call and before submitting results.
76
-
77
- <example>
78
-
79
- Based on my research, I can now provide information about Google and it's founders.
80
-
81
- The following objects are already in the database, I will not submit them again, but I'll re-use their IDs as references:
82
-
83
- - 01JWRDEHPB5TT2JQQQC15038BT Google
84
- - 01JWRDEHPA14CYW2NW9FAH6DJJ Larry Page
85
- - 01JWRDEHPBN0BBJP57B9S108W6 Sergey Brin
86
-
87
- I will use the following schema to construct new objects:
88
-
89
- - type:dxos.org/type/Organization for Alphabet Inc.
90
- - type:dxos.org/type/Person for Ivan Zhao
91
- - type:dxos.org/type/Person for Simon Last
92
- - dxn:type:dxos.org/relation/Employer for Ivan's employer
93
- - dxn:type:dxos.org/relation/Employer for Simon's employer
94
-
95
- <status>Formatting results</status>
96
-
97
- </example>
@@ -1,190 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { inspect } from 'node:util';
6
- import { beforeAll, describe, test } from 'vitest';
7
-
8
- import { EdgeAiServiceClient, OllamaAiServiceClient, structuredOutputParser } from '@dxos/ai';
9
- import { AI_SERVICE_ENDPOINT, EXA_API_KEY } from '@dxos/ai/testing';
10
- import { Obj } from '@dxos/echo';
11
- import { type EchoDatabase } from '@dxos/echo-db';
12
- import { EchoTestBuilder } from '@dxos/echo-db/testing';
13
- import { getSchemaDXN } from '@dxos/echo-schema';
14
- import { ConfiguredCredentialsService, FunctionExecutor, ServiceContainer, TracingService } from '@dxos/functions';
15
- import { DataType, DataTypes } from '@dxos/schema';
16
-
17
- import { createExtractionSchema, getSanitizedSchemaName } from './graph';
18
- import { researchFn } from './research';
19
-
20
- const REMOTE_AI = true;
21
- const MOCK_SEARCH = false;
22
-
23
- describe.skip('Research', () => {
24
- let builder: EchoTestBuilder;
25
- let db: EchoDatabase;
26
- let executor: FunctionExecutor;
27
-
28
- beforeAll(async () => {
29
- // TODO(dmaretskyi): Helper to scaffold this from a config.
30
- builder = await new EchoTestBuilder().open();
31
-
32
- db = (await builder.createDatabase({ indexing: { vector: true } })).db;
33
- db.graph.schemaRegistry.addSchema(DataTypes);
34
-
35
- executor = new FunctionExecutor(
36
- new ServiceContainer().setServices({
37
- ai: {
38
- client: REMOTE_AI
39
- ? new EdgeAiServiceClient({
40
- endpoint: AI_SERVICE_ENDPOINT.REMOTE,
41
- defaultGenerationOptions: {
42
- // model: '@anthropic/claude-sonnet-4-20250514',
43
- model: '@anthropic/claude-3-5-sonnet-20241022',
44
- },
45
- })
46
- : new OllamaAiServiceClient({
47
- overrides: {
48
- model: 'llama3.1:8b',
49
- },
50
- }),
51
- },
52
- credentials: new ConfiguredCredentialsService([{ service: 'exa.ai', apiKey: EXA_API_KEY }]),
53
- database: { db },
54
- tracing: TracingService.console,
55
- }),
56
- );
57
- });
58
-
59
- test('should generate a research report', { timeout: 300_000 }, async () => {
60
- db.add(
61
- Obj.make(DataType.Organization, {
62
- name: 'Notion',
63
- website: 'https://www.notion.com',
64
- }),
65
- );
66
- await db.flush({ indexes: true });
67
-
68
- const result = await executor.invoke(researchFn, {
69
- query: 'Who are the founders of Notion?',
70
- mockSearch: MOCK_SEARCH,
71
- });
72
-
73
- console.log(inspect(result, { depth: null, colors: true }));
74
- console.log(JSON.stringify(result, null, 2));
75
- });
76
- });
77
-
78
- describe('misc', () => {
79
- test('createExtractionSchema', () => {
80
- const _schema = createExtractionSchema(DataTypes);
81
- // log.info('schema', { schema });
82
- });
83
-
84
- test('extract schema json schema', () => {
85
- const schema = createExtractionSchema(DataTypes);
86
- const _parser = structuredOutputParser(schema);
87
- // log.info('schema', { json: parser.tool.parameters });
88
- });
89
-
90
- test('getSanitizedSchemaName', () => {
91
- const _names = DataTypes.map(getSanitizedSchemaName);
92
- // log.info('names', { names });
93
- });
94
-
95
- test('getTypeAnnotation', () => {
96
- for (const schema of DataTypes) {
97
- const _dxn = getSchemaDXN(schema);
98
- // log.info('dxn', { schema, dxn });
99
- }
100
- });
101
-
102
- test.skip('sanitizeObjects', () => {
103
- const _TEST_DATA = {
104
- objects_dxos_org_type_Project: [
105
- {
106
- name: 'Reor',
107
- description:
108
- 'A private & local AI personal knowledge management app focused on high entropy thinkers. Features include Q&A chat with full context of notes, automatic connection of ideas, semantic search, and local-first architecture with LLMs and vector databases.',
109
- image: 'https://reorhomepage-2-cwy0zagzg-reor-team.vercel.app/opengraph-image.jpg',
110
- id: 'reor-project-01',
111
- },
112
- {
113
- name: 'Personal AI',
114
- description:
115
- 'A platform for creating personal AI models with unlimited memory capabilities. Features include memory stacking, data uploads, and personalized language models that can be trained on individual knowledge bases.',
116
- image: 'https://cdn.prod.website-files.com/5ff65c460ce39f5ec5681c6a/663d12aab1b425e1ad40d3a6_Memory-min.jpg',
117
- id: 'personal-ai-project-01',
118
- },
119
- {
120
- name: 'IKI AI',
121
- description:
122
- 'An AI-native workspace for research, strategy, and creative work. Offers features like AI summarization, content analysis, and team knowledge sharing capabilities.',
123
- image: 'https://framerusercontent.com/assets/cI6Uo7x4q0W3uxzOt2preXjv6aE.jpg',
124
- id: 'iki-ai-project-01',
125
- },
126
- {
127
- name: 'Forethink',
128
- description:
129
- 'A privacy-first, on-device AI system that proactively links current activities to relevant knowledge. Features real-time learning across teams and local data processing.',
130
- image: 'https://framerusercontent.com/assets/XDhN6tICnlElB134JWcWXOuXc.jpeg',
131
- id: 'forethink-project-01',
132
- },
133
- {
134
- name: 'Amurex',
135
- description:
136
- 'An invisible AI companion that handles tasks, remembers important information, and supports workflow. Includes features for meeting automation, email categorization, and cross-platform search.',
137
- image: 'https://amurex.ai/ogimages/og_amurex.jpg',
138
- id: 'amurex-project-01',
139
- },
140
- ],
141
- objects_dxos_org_type_Organization: [
142
- {
143
- name: 'Reor',
144
- description:
145
- 'A technology company focused on developing local-first AI solutions for personal knowledge management.',
146
- status: 'active',
147
- website: 'https://www.reorproject.org',
148
- id: 'reor-org-01',
149
- },
150
- {
151
- name: 'Personal.ai',
152
- description: 'A company specializing in personal AI development and memory management solutions.',
153
- status: 'active',
154
- website: 'https://www.personal.ai',
155
- id: 'personal-ai-org-01',
156
- },
157
- {
158
- name: 'IKI AI',
159
- description: 'A startup backed by 500 Global, developing AI-native workspaces for knowledge workers.',
160
- status: 'active',
161
- website: 'https://iki.ai',
162
- id: 'iki-ai-org-01',
163
- },
164
- {
165
- name: 'Forethink.ai',
166
- description:
167
- 'A company focused on privacy-first AI solutions for knowledge management and team collaboration.',
168
- status: 'active',
169
- website: 'https://www.forethink.ai',
170
- id: 'forethink-org-01',
171
- },
172
- ],
173
- objects_dxos_org_type_Text: [
174
- {
175
- content:
176
- 'Current trends in AI-powered Personal Knowledge Management (PKM) systems include: 1) Shift from document-based to graph-based systems for better knowledge connection, 2) Integration of large language models for enhanced content understanding and retrieval, 3) Focus on privacy-first and local-first architectures, 4) Emphasis on automatic knowledge connection and discovery, 5) Implementation of semantic search capabilities.',
177
- id: 'pkm-trends-text-01',
178
- },
179
- {
180
- content:
181
- 'Key features emerging across modern PKM tools include: automated content categorization, semantic analysis and linking, personalized AI models that learn from user interaction, integration with existing workflows, and robust privacy protection. These tools are increasingly focusing on proactive knowledge surfacing rather than passive storage.',
182
- id: 'pkm-features-text-01',
183
- },
184
- ],
185
- };
186
-
187
- // const data = await sanitizeObjects(TYPES, TEST_DATA, db);
188
- // log.info('data', { data });
189
- });
190
- });