-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_langsmith_traces.mjs
More file actions
53 lines (45 loc) · 1.26 KB
/
Copy pathquery_langsmith_traces.mjs
File metadata and controls
53 lines (45 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import "dotenv/config";
import { Client } from "langsmith";
const client = new Client({
apiKey: process.env.LANGSMITH_API_KEY,
apiUrl: process.env.LANGSMITH_ENDPOINT || "https://api.smith.langchain.com",
});
const projectName =
process.env.LANGSMITH_PROJECT ||
"langsmith-hyper-granular-agent-trace-querying";
const roots = [];
for await (const run of client.listRuns({
projectName,
executionOrder: 1,
limit: 10,
})) {
roots.push(run);
}
function walk(run, depth = 0, rows = []) {
rows.push({
id: run.id,
name: run.name,
run_type: run.run_type,
depth,
parent_run_id: run.parent_run_id,
child_count: run.child_runs?.length ?? 0,
});
for (const child of run.child_runs ?? []) {
walk(child, depth + 1, rows);
}
return rows;
}
const summaries = [];
for (const root of roots.slice(0, 5)) {
const hydrated = await client.readRun(root.id, { loadChildRuns: true });
const rows = walk(hydrated);
summaries.push({
trace_id: hydrated.trace_id ?? hydrated.id,
root_id: hydrated.id,
root_name: hydrated.name,
run_count: rows.length,
max_depth: Math.max(...rows.map((row) => row.depth)),
run_types: [...new Set(rows.map((row) => row.run_type))].sort(),
});
}
console.log(JSON.stringify(summaries, null, 2));