Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(seeder): add support-agent scenario — handcrafted demo-grade agent trace (#14985)

Nikita Kabardind11f37b5cff0
diff --git a/.agents/skills/seed-test-data/SKILL.md b/.agents/skills/seed-test-data/SKILL.md
index 503091c649..cbb59b2c72 100644
--- a/.agents/skills/seed-test-data/SKILL.md
+++ b/.agents/skills/seed-test-data/SKILL.md
@@ -29,23 +29,24 @@ this.
## Need → command
-| I need... | Command |
-| --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| A very complex observation tree (v3) | `pnpm run seed -- trace-tree --observations 5000 --depth 12 --breadth 500` |
-| The same tree readable in the v4 events UI | add `--v4` (writes `events_full`; `events_core` fills via MV) |
-| Async parents whose subtree outlives their own span (subtree wall-clock duration badge) | add `--async-parents` to `trace-tree` (root + hub end immediately while children keep running) |
-| A realistic agent flow over a timeline (graph view + scrubbable timeline) | `pnpm run seed -- agent-timeline --turns 6 --v4` (LangGraph refine loop planner→retriever→generator→critic→loop, staggered in time; add `--timing-only` for the pure timing fallback) |
-| A plain trace with no agentic types (collapsed-by-default graph panel) | add `--plain` to `trace-tree` (SPAN/GENERATION/EVENT only) |
-| A super tough session (v3 legacy session view) | `pnpm run seed -- long-session --traces 300 --observations-per-trace 8` |
-| Diverse v4 session shapes (chat / coding-agent / mixed) for the session-detail view | `pnpm run seed -- session-shapes --shape all` (the `agent` shape has I/O on AGENT/TOOL with no GENERATION — pre-LFE-10520 the "first generation" default rendered empty cards for it; the current "All observations with I/O" default renders it correctly; v4 on by default) |
-| Many traces for list/filter performance | `pnpm run seed -- many-traces --count 100000 --days 14` |
-| Scores with spaces in the name (filter/grammar testing) | `pnpm run seed -- scored-traces --traces 24 --v4` |
-| Lots of scores on every node (dense score badges, tree-row overflow testing) | add `--scores-per-node 12` to `trace-tree` (N distinct scores per observation; try `--depth 2 --breadth 44` for many tall sibling rows) |
-| Varied human-annotation queues (annotate UI / keyboard testing) | `pnpm run seed -- annotation-queue --core-items 12` (creates a "core types" queue covering every score-field render path + an "edge cases" queue with archived/stale/partial scores and observation/session/deleted/completed items) |
-| Huge/malformed/unicode payloads | `pnpm run seed -- trace-tree --payload-bytes 1000000 --payload-style malformed` (styles: json, text, malformed, unicode, bignum) |
-| Big integers beyond 2^53-1 (number-precision testing) | `pnpm run seed -- trace-tree --observations 1 --payload-style bignum` |
-| See all scenarios and flags | `pnpm run seed -- list --json` |
-| Predict without writing | add `--dry-run` |
+| I need... | Command |
+| --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| A very complex observation tree (v3) | `pnpm run seed -- trace-tree --observations 5000 --depth 12 --breadth 500` |
+| The same tree readable in the v4 events UI | add `--v4` (writes `events_full`; `events_core` fills via MV) |
+| Async parents whose subtree outlives their own span (subtree wall-clock duration badge) | add `--async-parents` to `trace-tree` (root + hub end immediately while children keep running) |
+| A realistic agent flow over a timeline (graph view + scrubbable timeline) | `pnpm run seed -- agent-timeline --turns 6 --v4` (LangGraph refine loop planner→retriever→generator→critic→loop, staggered in time; add `--timing-only` for the pure timing fallback) |
+| A demo-grade, real-looking agent trace (videos, screenshots, docs) | `pnpm run seed -- support-agent --v4 --id-prefix <hex>` (one fixed, fully handcrafted support-copilot refund run: guardrails, parallel context fan-out, 3-turn ReAct loop with real payloads/costs; deterministic — reseed with a FRESH prefix for a clean take; the prefix is the trace id, so a hex prefix reads like production) |
+| A plain trace with no agentic types (collapsed-by-default graph panel) | add `--plain` to `trace-tree` (SPAN/GENERATION/EVENT only) |
+| A super tough session (v3 legacy session view) | `pnpm run seed -- long-session --traces 300 --observations-per-trace 8` |
+| Diverse v4 session shapes (chat / coding-agent / mixed) for the session-detail view | `pnpm run seed -- session-shapes --shape all` (the `agent` shape has I/O on AGENT/TOOL with no GENERATION — pre-LFE-10520 the "first generation" default rendered empty cards for it; the current "All observations with I/O" default renders it correctly; v4 on by default) |
+| Many traces for list/filter performance | `pnpm run seed -- many-traces --count 100000 --days 14` |
+| Scores with spaces in the name (filter/grammar testing) | `pnpm run seed -- scored-traces --traces 24 --v4` |
+| Lots of scores on every node (dense score badges, tree-row overflow testing) | add `--scores-per-node 12` to `trace-tree` (N distinct scores per observation; try `--depth 2 --breadth 44` for many tall sibling rows) |
+| Varied human-annotation queues (annotate UI / keyboard testing) | `pnpm run seed -- annotation-queue --core-items 12` (creates a "core types" queue covering every score-field render path + an "edge cases" queue with archived/stale/partial scores and observation/session/deleted/completed items) |
+| Huge/malformed/unicode payloads | `pnpm run seed -- trace-tree --payload-bytes 1000000 --payload-style malformed` (styles: json, text, malformed, unicode, bignum) |
+| Big integers beyond 2^53-1 (number-precision testing) | `pnpm run seed -- trace-tree --observations 1 --payload-style bignum` |
+| See all scenarios and flags | `pnpm run seed -- list --json` |
+| Predict without writing | add `--dry-run` |
## Contract
diff --git a/packages/shared/scripts/seeder/AGENTS.md b/packages/shared/scripts/seeder/AGENTS.md
index 9aff2ee874..dc84ded468 100644
--- a/packages/shared/scripts/seeder/AGENTS.md
+++ b/packages/shared/scripts/seeder/AGENTS.md
@@ -11,6 +11,7 @@ pnpm run seed -- list # scenarios and flags (--json for machines)
pnpm run seed -- trace-tree --observations 5000 --breadth 500 --v4
pnpm run seed -- trace-tree --observations 12 --plain --v4 # SPAN/GENERATION/EVENT only (collapsed-by-default graph panel)
pnpm run seed -- agent-timeline --turns 6 --v4 # realistic agent flow-with-loop over a timeline (graph view)
+pnpm run seed -- support-agent --v4 --id-prefix <hex> # demo-grade handcrafted support-copilot run (videos/screenshots)
pnpm run seed -- long-session --traces 300 --observations-per-trace 8
pnpm run seed -- session-shapes --shape all # chat / coding-agent / mixed v4 sessions
pnpm run seed -- many-traces --count 100000 --days 14
diff --git a/packages/shared/scripts/seeder/scenarios/index.ts b/packages/shared/scripts/seeder/scenarios/index.ts
index 1e5096b8cf..b7bf16c9b0 100644
--- a/packages/shared/scripts/seeder/scenarios/index.ts
+++ b/packages/shared/scripts/seeder/scenarios/index.ts
@@ -4,6 +4,7 @@ import { longSessionScenario } from "./long-session";
import { manyTracesScenario } from "./many-traces";
import { scoredTracesScenario } from "./scored-traces";
import { sessionShapesScenario } from "./session-shapes";
+import { supportAgentScenario } from "./support-agent";
import { traceTreeScenario } from "./trace-tree";
import { ScenarioDefinition } from "./types";
@@ -18,6 +19,7 @@ export const scenarios: Record<string, ScenarioDefinition> = {
"scored-traces": scoredTracesScenario,
"session-shapes": sessionShapesScenario,
"annotation-queue": annotationQueueScenario,
+ "support-agent": supportAgentScenario,
};
export * from "./types";
diff --git a/packages/shared/scripts/seeder/scenarios/support-agent.ts b/packages/shared/scripts/seeder/scenarios/support-agent.ts
new file mode 100644
index 0000000000..73744438d6
--- /dev/null
+++ b/packages/shared/scripts/seeder/scenarios/support-agent.ts
@@ -0,0 +1,677 @@
+import {
+ createTrace,
+ createObservation,
+ createTracesCh,
+ createObservationsCh,
+ createEventsCh,
+ ObservationRecordInsertType,
+} from "../../../src/server";
+import { ObservationType } from "../../../src/domain";
+import { observationToEvent, traceToEvent } from "./event-mirror";
+import { utcDayStartMs } from "./rng";
+import {
+ chunk,
+ ScenarioContext,
+ ScenarioDefinition,
+ SeedError,
+ SeedSummary,
+} from "./types";
+import { countRows, sessionLink, traceLink } from "./verify";
+
+/**
+ * A demo-grade, production-looking agent run: one fixed, fully handcrafted
+ * trace of a customer-support copilot resolving a duplicate-charge refund.
+ *
+ * Unlike the other scenarios (which generate lorem-style payloads at scale),
+ * every observation here carries real-looking content — actual message
+ * arrays, tool arguments and JSON results, believable token counts, per-model
+ * costs, staggered timings with a parallel context fan-out and a 3-turn
+ * ReAct loop (`llm.chat` repeats, tools differ). Deterministic: re-seeding
+ * reproduces the identical trace, which makes it ideal for videos,
+ * screenshots, and docs.
+ *
+ * Graph view: the repeated `llm.chat` collapses to one `(3/3)` node with
+ * loop-back edges in Aggregated mode; Expanded mode unrolls the run into the
+ * as-it-ran DAG with the load-context fork/join.
+ */
+
+const MODEL_PRICES: Record<string, { input: number; output: number }> = {
+ "gpt-4o": { input: 2.5e-6, output: 1e-5 },
+ "gpt-4o-mini": { input: 1.5e-7, output: 6e-7 },
+};
+
+type DemoObs = {
+ key: string;
+ parentKey: string | null;
+ type: ObservationType;
+ name: string;
+ /** ms offsets from the trace timestamp */
+ start: number;
+ end: number;
+ input?: unknown;
+ output?: unknown;
+ metadata?: Record<string, string>;
+ model?: keyof typeof MODEL_PRICES;
+ /** [input tokens, output tokens] — generations only */
+ usage?: [number, number];
+ /** time-to-first-token in ms — generations only */
+ ttft?: number;
+ modelParameters?: Record<string, unknown>;
+};
+
+const CUSTOMER_MESSAGE =
+ "Hi — I was charged twice for my Pro subscription this month " +
+ "(invoices inv_20260701 and inv_20260701-2, $49 each). " +
+ "Can you refund the duplicate?";
+
+const AGENT_SYSTEM_PROMPT =
+ "You are Acme's support copilot. Resolve the customer's billing issue " +
+ "end-to-end using the available tools (stripe_find_charges, " +
+ "stripe_create_refund, escalate_to_human). Verify before acting: never " +
+ "refund without confirming the duplicate against Stripe. When done, " +
+ "summarize the resolution for the reply drafter.";
+
+const FINAL_REPLY =
+ "Hi Maya, thanks for flagging this! I've confirmed the duplicate $49.00 " +
+ "charge from July 1st (both hit within 5 seconds — a payment retry bug on " +
+ "our side) and issued a refund for the second charge (re_8Fj2kQ). You " +
+ "should see it back on your card within 5–10 business days. I've also " +
+ "passed the retry issue to our payments team so it doesn't happen again. " +
+ "Sorry for the hassle!";
+
+/** The whole run, handcrafted. Offsets are ms from the trace timestamp. */
+const PLAN: DemoObs[] = [
+ {
+ key: "root",
+ parentKey: null,
+ type: "AGENT",
+ name: "support-copilot",
+ start: 0,
+ end: 11052,
+ input: { message: CUSTOMER_MESSAGE, customer_id: "cus_LqT4v8" },
+ output: {
+ reply: FINAL_REPLY,
+ resolution: "refund_issued",
+ refund_id: "re_8Fj2kQ",
+ confidence: 0.94,
+ },
+ metadata: { channel: "in-app-chat", plan: "pro", region: "eu-central-1" },
+ },
+ {
+ key: "guard-in",
+ parentKey: "root",
+ type: "GUARDRAIL",
+ name: "guardrail.input",
+ start: 45,
+ end: 168,
+ input: {
+ text: CUSTOMER_MESSAGE,
+ checks: ["prompt_injection", "pii", "toxicity"],
+ },
+ output: { verdict: "pass", flags: [], pii_redactions: 0 },
+ metadata: { provider: "internal", policy: "support-v2" },
+ },
+ {
+ key: "classify",
+ parentKey: "root",
+ type: "GENERATION",
+ name: "classify-intent",
+ start: 205,
+ end: 818,
+ model: "gpt-4o-mini",
+ usage: [412, 31],
+ ttft: 158,
+ modelParameters: { temperature: 0, max_tokens: 128 },
+ input: {
+ messages: [
+ {
+ role: "system",
+ content:
+ "Classify the support request. Return JSON: " +
+ "{intent, urgency, sentiment}.",
+ },
+ { role: "user", content: CUSTOMER_MESSAGE },
+ ],
+ },
+ output: {
+ intent: "billing.duplicate_charge",
+ urgency: "medium",
+ sentiment: "frustrated",
+ },
+ },
+ {
+ key: "load-context",
+ parentKey: "root",
+ type: "SPAN",
+ name: "load-context",
+ start: 858,
+ end: 1512,
+ input: { customer_id: "cus_LqT4v8" },
+ output: { sources: ["crm", "billing", "tickets"], cache_hit: false },
+ },
+ {
+ key: "crm",
+ parentKey: "load-context",
+ type: "TOOL",
+ name: "crm.get-customer",
+ start: 881,
+ end: 1129,
+ input: { customer_id: "cus_LqT4v8" },
+ output: {
+ name: "Maya Chen",
+ company: "Acme Robotics",
+ plan: "pro",
+ seats: 14,
+ mrr_usd: 49,
+ customer_since: "2024-03-12",
+ churn_risk: "low",
+ },
+ metadata: { provider: "salesforce" },
+ },
+ {
+ key: "billing",
+ parentKey: "load-context",
+ type: "TOOL",
+ name: "billing.list-invoices",
+ start: 886,
+ end: 1494,
+ input: { customer_id: "cus_LqT4v8", period: "2026-06..2026-07" },
+ output: {
+ invoices: [
+ {
+ id: "inv_20260701",
+ amount_usd: 49.0,
+ status: "paid",
+ charged_at: "2026-07-01T06:12:04Z",
+ },
+ {
+ id: "inv_20260701-2",
+ amount_usd: 49.0,
+ status: "paid",
+ charged_at: "2026-07-01T06:12:09Z",
+ },
+ ],
+ },
+ metadata: { provider: "stripe", api_version: "2026-06-01" },
+ },
+ {
+ key: "tickets",
+ parentKey: "load-context",
+ type: "TOOL",
+ name: "tickets.search",
+ start: 893,
+ end: 1263,
+ input: { query: "duplicate charge cus_LqT4v8", limit: 5 },
+ output: {
+ hits: 1,
+ tickets: [
+ {
+ id: "TCK-4821",
+ subject: "Card charged twice on renewal",
+ status: "closed",
+ resolution: "refund",
+ opened_at: "2026-02-17",
+ },
+ ],
+ },
+ metadata: { provider: "zendesk" },
+ },
+ {
+ key: "llm-1",
+ parentKey: "root",
+ type: "GENERATION",
+ name: "llm.chat",
+ start: 1561,
+ end: 3389,
+ model: "gpt-4o",
+ usage: [1846, 94],
+ ttft: 243,
+ modelParameters: {
+ temperature: 0.3,
+ max_tokens: 1024,
+ tool_choice: "auto",
+ },
+ input: {
+ messages: [
+ { role: "system", content: AGENT_SYSTEM_PROMPT },
+ { role: "user", content: CUSTOMER_MESSAGE },
+ {
+ role: "assistant",
+ content:
+ "Context: pro plan customer (Maya Chen, Acme Robotics), two $49 " +
+ "invoices paid 5s apart on 2026-07-01, one prior ticket with the " +
+ "same pattern resolved by refund.",
+ },
+ ],
+ },
+ output: {
+ content: null,
+ tool_calls: [
+ {
+ id: "call_qL83mN",
+ type: "function",
+ function: {
+ name: "stripe_find_charges",
+ arguments:
+ '{"customer_id":"cus_LqT4v8","period":"2026-07","amount_usd":49}',
+ },
+ },
+ ],
+ },
+ },
+ {
+ key: "find-charges",
+ parentKey: "root",
+ type: "TOOL",
+ name: "stripe.find-charges",
+ start: 3441,
+ end: 4118,
+ input: { customer_id: "cus_LqT4v8", period: "2026-07", amount_usd: 49 },
+ output: {
+ charges: [
+ {
+ id: "ch_3PqK8r",
+ amount_usd: 49.0,
+ created: "2026-07-01T06:12:04Z",
+ invoice: "inv_20260701",
+ payment_intent: "pi_3PqK8q",
+ },
+ {
+ id: "ch_3PqK9b",
+ amount_usd: 49.0,
+ created: "2026-07-01T06:12:09Z",
+ invoice: "inv_20260701-2",
+ payment_intent: "pi_3PqK8q",
+ },
+ ],
+ duplicate_confidence: 0.98,
+ note: "same payment_intent — retry produced a second capture",
+ },
+ metadata: { provider: "stripe", api_version: "2026-06-01" },
+ },
+ {
+ key: "llm-2",
+ parentKey: "root",
+ type: "GENERATION",
+ name: "llm.chat",
+ start: 4172,
+ end: 5924,
+ model: "gpt-4o",
+ usage: [2413, 72],
+ ttft: 212,
+ modelParameters: {
+ temperature: 0.3,
+ max_tokens: 1024,
+ tool_choice: "auto",
+ },
+ input: {
+ messages: [
+ { role: "system", content: AGENT_SYSTEM_PROMPT },
+ {
+ role: "tool",
+ tool_call_id: "call_qL83mN",
+ content:
+ '{"charges":[{"id":"ch_3PqK8r"},{"id":"ch_3PqK9b"}],' +
+ '"duplicate_confidence":0.98}',
+ },
+ ],
+ },
+ output: {
+ content: null,
+ tool_calls: [
+ {
+ id: "call_xT19vB",
+ type: "function",
+ function: {
+ name: "stripe_create_refund",
+ arguments:
+ '{"charge_id":"ch_3PqK9b","reason":"duplicate",' +
+ '"idempotency_key":"refund-cus_LqT4v8-20260709"}',
+ },
+ },
+ ],
+ },
+ },
+ {
+ key: "refund",
+ parentKey: "root",
+ type: "TOOL",
+ name: "stripe.create-refund",
+ start: 5978,
+ end: 6893,
+ input: {
+ charge_id: "ch_3PqK9b",
+ reason: "duplicate",
+ idempotency_key: "refund-cus_LqT4v8-20260709",
+ },
+ output: {
+ refund_id: "re_8Fj2kQ",
+ status: "succeeded",
+ amount_usd: 49.0,
+ charge_id: "ch_3PqK9b",
+ expected_arrival: "5-10 business days",
+ },
+ metadata: { provider: "stripe", api_version: "2026-06-01" },
+ },
+ {
+ key: "llm-3",
+ parentKey: "root",
+ type: "GENERATION",
+ name: "llm.chat",
+ start: 6947,
+ end: 8731,
+ model: "gpt-4o",
+ usage: [2987, 141],
+ ttft: 264,
+ modelParameters: {
+ temperature: 0.3,
+ max_tokens: 1024,
+ tool_choice: "auto",
+ },
+ input: {
+ messages: [
+ { role: "system", content: AGENT_SYSTEM_PROMPT },
+ {
+ role: "tool",
+ tool_call_id: "call_xT19vB",
+ content: '{"refund_id":"re_8Fj2kQ","status":"succeeded"}',
+ },
+ ],
+ },
+ output: {
+ content:
+ "Resolution complete. Verified duplicate capture (same " +
+ "payment_intent, 5s apart), refunded ch_3PqK9b (re_8Fj2kQ, $49.00). " +
+ "Root cause: payment retry double-capture — flag to payments team. " +
+ "Ready to draft the customer reply.",
+ tool_calls: [],
+ },
+ },
+ {
+ key: "draft",
+ parentKey: "root",
+ type: "GENERATION",
+ name: "draft-response",
+ start: 8790,
+ end: 10377,
+ model: "gpt-4o",
+ usage: [1312, 187],
+ ttft: 231,
+ modelParameters: { temperature: 0.7, max_tokens: 512 },
+ input: {
+ messages: [
+ {
+ role: "system",
+ content:
+ "Draft a friendly, concise support reply. Facts only from the " +
+ "resolution summary. Match the customer's tone; no corporate " +
+ "boilerplate.",
+ },
+ {
+ role: "user",
+ content:
+ "Resolution: duplicate $49 charge confirmed (retry bug), " +
+ "refund re_8Fj2kQ issued, arrives in 5-10 business days. " +
+ "Customer: Maya, frustrated but polite.",
+ },
+ ],
+ },
+ output: { reply: FINAL_REPLY },
+ },
+ {
+ key: "guard-out",
+ parentKey: "root",
+ type: "GUARDRAIL",
+ name: "guardrail.output",
+ start: 10426,
+ end: 10557,
+ input: { text: FINAL_REPLY, checks: ["policy", "tone", "pii"] },
+ output: { verdict: "pass", tone: "empathetic", policy_violations: [] },
+ metadata: { provider: "internal", policy: "support-v2" },
+ },
+ {
+ key: "send",
+ parentKey: "root",
+ type: "TOOL",
+ name: "zendesk.send-reply",
+ start: 10609,
+ end: 10881,
+ input: { thread_id: "thread_7Hf3kX", body: FINAL_REPLY },
+ output: { message_id: "msg_9uTb4w", status: "sent" },
+ metadata: { provider: "zendesk" },
+ },
+];
+
+const run = async (
+ ctx: ScenarioContext,
+ params: Record<string, string | number | boolean>,
+): Promise<SeedSummary> => {
+ const startedAt = Date.now();
+ const withV4 = params["v4"] as boolean;
+
+ // The prefix IS the trace id (no "-trace" suffix): the id shows in the
+ // trace header, so a demo seeded with a hex-looking prefix (e.g.
+ // --id-prefix 0198f2ab41c7e93d) reads like a production trace on camera.
+ const traceId = ctx.idPrefix;
+ const sessionId = `${ctx.idPrefix}-thread`;
+ const traceTimestamp = utcDayStartMs();
+
+ if (ctx.dryRun) {
+ return {
+ scenario: "support-agent",
+ target: "clickhouse",
+ params,
+ projectId: ctx.projectId,
+ environment: ctx.environment,
+ traceIds: [traceId],
+ sessionIds: [sessionId],
+ counts: {
+ traces: 1,
+ observations: PLAN.length,
+ events: withV4 ? PLAN.length + 1 : 0,
+ },
+ verified: {},
+ links: [
+ traceLink(ctx, traceId, traceTimestamp),
+ sessionLink(ctx, sessionId),
+ ],
+ dryRun: true,
+ durationMs: Date.now() - startedAt,
+ };
+ }
+
+ const root = PLAN[0];
+ const trace = createTrace({
+ id: traceId,
+ project_id: ctx.projectId,
+ environment: ctx.environment,
+ name: "support-copilot",
+ timestamp: traceTimestamp,
+ user_id: "[email protected]",
+ session_id: sessionId,
+ release: "2026.07.03-1",
+ version: "copilot-v3.2",
+ tags: ["support", "billing", "tier:pro"],
+ public: false,
+ bookmarked: false,
+ metadata: {
+ scenario: "support-agent",
+ customer_id: "cus_LqT4v8",
+ channel: "in-app-chat",
+ },
+ input: JSON.stringify(root.input),
+ output: JSON.stringify(root.output),
+ created_at: Date.now(),
+ updated_at: Date.now(),
+ event_ts: Date.now(),
+ });
+
+ const keyToId = new Map<string, string>(
+ PLAN.map((p, i) => [p.key, `${ctx.idPrefix}-obs-${i}`]),
+ );
+
+ const observations: ObservationRecordInsertType[] = PLAN.map((p) => {
+ const prices = p.model ? MODEL_PRICES[p.model] : null;
+ const [usageInput, usageOutput] = p.usage ?? [0, 0];
+ const inputCost = prices ? usageInput * prices.input : 0;
+ const outputCost = prices ? usageOutput * prices.output : 0;
+
+ return createObservation({
+ id: keyToId.get(p.key)!,
+ trace_id: traceId,
+ project_id: ctx.projectId,
+ environment: ctx.environment,
+ type: p.type,
+ parent_observation_id:
+ p.parentKey === null ? null : (keyToId.get(p.parentKey) ?? null),
+ name: p.name,
+ start_time: traceTimestamp + p.start,
+ end_time: traceTimestamp + p.end,
+ completion_start_time:
+ p.ttft !== undefined ? traceTimestamp + p.start + p.ttft : null,
+ level: "DEFAULT",
+ status_message: null,
+ version: null,
+ input: p.input !== undefined ? JSON.stringify(p.input) : null,
+ output: p.output !== undefined ? JSON.stringify(p.output) : null,
+ metadata: { scenario: "support-agent", ...p.metadata },
+ provided_model_name: p.model ?? null,
+ internal_model_id: null,
+ model_parameters: p.modelParameters
+ ? JSON.stringify(p.modelParameters)
+ : "{}",
+ // Empty fields stay explicit for non-generations: the createObservation
+ // factory would otherwise fill non-empty usage/cost defaults.
+ ...(prices
+ ? {
+ provided_usage_details: {
+ input: usageInput,
+ output: usageOutput,
+ total: usageInput + usageOutput,
+ },
+ usage_details: {
+ input: usageInput,
+ output: usageOutput,
+ total: usageInput + usageOutput,
+ },
+ provided_cost_details: { input: inputCost, output: outputCost },
+ cost_details: {
+ input: inputCost,
+ output: outputCost,
+ total: inputCost + outputCost,
+ },
+ total_cost: inputCost + outputCost,
+ }
+ : {
+ provided_usage_details: {},
+ usage_details: {},
+ provided_cost_details: {},
+ cost_details: {},
+ total_cost: null,
+ }),
+ prompt_id: null,
+ prompt_name: null,
+ prompt_version: null,
+ created_at: Date.now(),
+ updated_at: Date.now(),
+ event_ts: Date.now(),
+ });
+ });
+
+ const events = withV4
+ ? [
+ traceToEvent(trace),
+ ...observations.map((o) => observationToEvent(o, trace)),
+ ]
+ : [];
+
+ const counts: Record<string, number> = {
+ traces: 1,
+ observations: observations.length,
+ events: events.length,
+ };
+
+ ctx.log(
+ `writing 1 support-copilot trace, ${observations.length} observations${withV4 ? `, ${events.length} events` : ""}`,
+ );
+ await createTracesCh([trace]);
+ for (const batch of chunk(observations, 1000)) {
+ await createObservationsCh(batch);
+ }
+ for (const batch of chunk(events, 500)) {
+ await createEventsCh(batch);
+ }
+
+ const verified: Record<string, number> = {
+ traces: await countRows(
+ "traces",
+ `project_id = {projectId: String} AND id = {traceId: String}`,
+ { projectId: ctx.projectId, traceId },
+ "uniqExact(id)",
+ ),
+ observations: await countRows(
+ "observations",
+ `project_id = {projectId: String} AND trace_id = {traceId: String}`,
+ { projectId: ctx.projectId, traceId },
+ "uniqExact(id)",
+ ),
+ };
+ if (withV4) {
+ verified.events = await countRows(
+ "events_full",
+ `project_id = {projectId: String} AND trace_id = {traceId: String}`,
+ { projectId: ctx.projectId, traceId },
+ "uniqExact(span_id)",
+ );
+ }
+
+ if (verified.traces < 1) {
+ throw new SeedError(
+ `Readback mismatch: trace ${traceId} not found after insert`,
+ );
+ }
+ if (verified.observations < observations.length) {
+ throw new SeedError(
+ `Readback mismatch: expected ${observations.length} observations, found ${verified.observations}`,
+ );
+ }
+ if (withV4 && verified.events < events.length) {
+ throw new SeedError(
+ `Readback mismatch: expected ${events.length} events_full rows, found ${verified.events}`,
+ );
+ }
+
+ return {
+ scenario: "support-agent",
+ target: "clickhouse",
+ params,
+ projectId: ctx.projectId,
+ environment: ctx.environment,
+ traceIds: [traceId],
+ sessionIds: [sessionId],
+ counts,
+ verified,
+ links: [
+ traceLink(ctx, traceId, traceTimestamp),
+ sessionLink(ctx, sessionId),
+ ],
+ dryRun: false,
+ durationMs: Date.now() - startedAt,
+ };
+};
+
+export const supportAgentScenario: ScenarioDefinition = {
+ name: "support-agent",
+ description:
+ "One demo-grade, fully handcrafted trace: a customer-support copilot resolving a duplicate-charge refund — input guardrail → intent classification → parallel context fan-out (CRM/billing/tickets) → 3-turn ReAct loop (llm.chat + Stripe tools) → drafted reply → output guardrail → send. Real-looking payloads, per-model token/cost numbers, deterministic timings. Built for videos/screenshots; exercises the graph view's Aggregated (llm.chat 3/3 loop) vs Expanded (as-it-ran DAG with fork/join) modes.",
+ supportsV4: true,
+ flags: [
+ {
+ flag: "v4",
+ type: "boolean",
+ default: false,
+ description: "also mirror into v4 events_full/events_core",
+ },
+ ],
+ run,
+};