@deepagents/text2sql 0.8.1 → 0.9.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.
- package/dist/index.js +2 -11
- package/dist/index.js.map +3 -3
- package/dist/lib/adapters/groundings/index.js +42 -44
- package/dist/lib/adapters/groundings/index.js.map +2 -2
- package/dist/lib/adapters/groundings/report.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/mysql/index.js +46 -45
- package/dist/lib/adapters/mysql/index.js.map +2 -2
- package/dist/lib/adapters/mysql/info.mysql.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/postgres/index.js +46 -45
- package/dist/lib/adapters/postgres/index.js.map +2 -2
- package/dist/lib/adapters/postgres/info.postgres.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlite/index.js +46 -45
- package/dist/lib/adapters/sqlite/index.js.map +2 -2
- package/dist/lib/adapters/sqlite/info.sqlite.grounding.d.ts.map +1 -1
- package/dist/lib/adapters/sqlserver/index.js +46 -45
- package/dist/lib/adapters/sqlserver/index.js.map +2 -2
- package/dist/lib/adapters/sqlserver/info.sqlserver.grounding.d.ts.map +1 -1
- package/dist/lib/sql.d.ts.map +1 -1
- package/dist/lib/synthesis/extractors/last-query-extractor.d.ts +1 -1
- package/dist/lib/synthesis/index.js.map +1 -1
- package/package.json +5 -4
|
@@ -344,6 +344,47 @@ import {
|
|
|
344
344
|
toState,
|
|
345
345
|
user
|
|
346
346
|
} from "@deepagents/agent";
|
|
347
|
+
var reportAgent = agent({
|
|
348
|
+
name: "db-report-agent",
|
|
349
|
+
model: groq("openai/gpt-oss-20b"),
|
|
350
|
+
prompt: () => dedent`
|
|
351
|
+
<identity>
|
|
352
|
+
You are a database analyst expert. Your job is to understand what
|
|
353
|
+
a database represents and provide business context about it.
|
|
354
|
+
You have READ-ONLY access to the database.
|
|
355
|
+
</identity>
|
|
356
|
+
|
|
357
|
+
<instructions>
|
|
358
|
+
Write a business context that helps another agent answer questions accurately.
|
|
359
|
+
|
|
360
|
+
For EACH table, do queries ONE AT A TIME:
|
|
361
|
+
1. SELECT COUNT(*) to get row count
|
|
362
|
+
2. SELECT * LIMIT 3 to see sample data
|
|
363
|
+
|
|
364
|
+
Then write a report with:
|
|
365
|
+
- What business this database is for
|
|
366
|
+
- For each table: purpose, row count, and example of what the data looks like
|
|
367
|
+
|
|
368
|
+
Include concrete examples like "Track prices are $0.99",
|
|
369
|
+
"Customer names like 'Luís Gonçalves'", etc.
|
|
370
|
+
|
|
371
|
+
Keep it 400-600 words, conversational style.
|
|
372
|
+
</instructions>
|
|
373
|
+
`,
|
|
374
|
+
tools: {
|
|
375
|
+
query_database: tool({
|
|
376
|
+
description: "Execute a SELECT query to explore the database and gather insights.",
|
|
377
|
+
inputSchema: z.object({
|
|
378
|
+
sql: z.string().describe("The SELECT query to execute"),
|
|
379
|
+
purpose: z.string().describe("What insight you are trying to gather with this query")
|
|
380
|
+
}),
|
|
381
|
+
execute: ({ sql }, options) => {
|
|
382
|
+
const state = toState(options);
|
|
383
|
+
return state.adapter.execute(sql);
|
|
384
|
+
}
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
});
|
|
347
388
|
var ReportGrounding = class extends AbstractGrounding {
|
|
348
389
|
#adapter;
|
|
349
390
|
#model;
|
|
@@ -372,51 +413,8 @@ var ReportGrounding = class extends AbstractGrounding {
|
|
|
372
413
|
return () => report2;
|
|
373
414
|
}
|
|
374
415
|
async #generateReport() {
|
|
375
|
-
const reportAgent = agent({
|
|
376
|
-
name: "db-report-agent",
|
|
377
|
-
model: this.#model,
|
|
378
|
-
prompt: () => dedent`
|
|
379
|
-
<identity>
|
|
380
|
-
You are a database analyst expert. Your job is to understand what
|
|
381
|
-
a database represents and provide business context about it.
|
|
382
|
-
You have READ-ONLY access to the database.
|
|
383
|
-
</identity>
|
|
384
|
-
|
|
385
|
-
<instructions>
|
|
386
|
-
Write a business context that helps another agent answer questions accurately.
|
|
387
|
-
|
|
388
|
-
For EACH table, do queries ONE AT A TIME:
|
|
389
|
-
1. SELECT COUNT(*) to get row count
|
|
390
|
-
2. SELECT * LIMIT 3 to see sample data
|
|
391
|
-
|
|
392
|
-
Then write a report with:
|
|
393
|
-
- What business this database is for
|
|
394
|
-
- For each table: purpose, row count, and example of what the data looks like
|
|
395
|
-
|
|
396
|
-
Include concrete examples like "Track prices are $0.99",
|
|
397
|
-
"Customer names like 'Luís Gonçalves'", etc.
|
|
398
|
-
|
|
399
|
-
Keep it 400-600 words, conversational style.
|
|
400
|
-
</instructions>
|
|
401
|
-
`,
|
|
402
|
-
tools: {
|
|
403
|
-
query_database: tool({
|
|
404
|
-
description: "Execute a SELECT query to explore the database and gather insights.",
|
|
405
|
-
inputSchema: z.object({
|
|
406
|
-
sql: z.string().describe("The SELECT query to execute"),
|
|
407
|
-
purpose: z.string().describe(
|
|
408
|
-
"What insight you are trying to gather with this query"
|
|
409
|
-
)
|
|
410
|
-
}),
|
|
411
|
-
execute: ({ sql }, options) => {
|
|
412
|
-
const state = toState(options);
|
|
413
|
-
return state.adapter.execute(sql);
|
|
414
|
-
}
|
|
415
|
-
})
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
416
|
const { text } = await generate(
|
|
419
|
-
reportAgent,
|
|
417
|
+
reportAgent.clone({ model: this.#model }),
|
|
420
418
|
[
|
|
421
419
|
user(
|
|
422
420
|
"Please analyze the database and write a contextual report about what this database represents."
|
|
@@ -993,7 +991,10 @@ var SqlServerInfoGrounding = class extends InfoGrounding {
|
|
|
993
991
|
return {
|
|
994
992
|
dialect: "sqlserver",
|
|
995
993
|
version: versionRows[0]?.version,
|
|
996
|
-
database: dbRows[0]?.db
|
|
994
|
+
database: dbRows[0]?.db,
|
|
995
|
+
details: {
|
|
996
|
+
parameterPlaceholder: "@p1, @p2, @p3, ..."
|
|
997
|
+
}
|
|
997
998
|
};
|
|
998
999
|
}
|
|
999
1000
|
};
|