🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(assistant): preserve model prompts in traces (#16407)
Ben Bachemb8e8c832d620
diff --git a/worker/src/features/in-app-agent/runtime/instrumentation.test.ts b/worker/src/features/in-app-agent/runtime/instrumentation.test.tsindex 35c902e029..97fd6c687e 100644--- a/worker/src/features/in-app-agent/runtime/instrumentation.test.ts+++ b/worker/src/features/in-app-agent/runtime/instrumentation.test.ts@@ -1396,6 +1396,29 @@ describe("InAppAgentInstrumentation", () => {expect(finalAgentCreate).not.toHaveProperty("model");});+ it("drops circular provider options from model call input", () => {+ const instrumentation = createInstrumentation();+ const providerOptions: Record<string, unknown> = {};+ providerOptions.circular = providerOptions;++ instrumentation.recordModelCallStart({+ prompt: [{ role: "user", content: "hello" }],+ providerOptions,+ });+ instrumentation.recordModelStreamPart({+ type: "finish",+ usage: { inputTokens: 100, outputTokens: 10, totalTokens: 110 },+ finishReason: "stop",+ });++ const generation = mocks.handler.langfuse.enqueue.mock.calls.find(+ ([type]) => type === "generation-create",+ )?.[1];+ expect(generation?.input).toEqual({+ messages: [{ role: "user", content: "hello" }],+ });+ });+it("emits tools after the generation using actual execution timing", () => {const instrumentation = createInstrumentation();const modelCallStart = new Date("2026-01-01T00:00:00.000Z");diff --git a/worker/src/features/in-app-agent/runtime/instrumentation.ts b/worker/src/features/in-app-agent/runtime/instrumentation.tsindex 0cfecf2e53..6ed9eb8ec5 100644--- a/worker/src/features/in-app-agent/runtime/instrumentation.ts+++ b/worker/src/features/in-app-agent/runtime/instrumentation.ts@@ -1283,8 +1283,7 @@ function getModelCallInput(options: unknown): unknown {return undefined;}- const input = {- messages: options.prompt,+ const serializedOptions = toSerializableJson({maxOutputTokens: options.maxOutputTokens,temperature: options.temperature,stopSequences: options.stopSequences,@@ -1297,9 +1296,14 @@ function getModelCallInput(options: unknown): unknown {tools: options.tools,toolChoice: options.toolChoice,providerOptions: options.providerOptions,- };+ });- return toSerializableJson(input);+ // The prompt is the exact provider-bound payload. Preserve it losslessly in+ // tracing; this copy does not affect the options passed to the model.+ return {+ ...(options.prompt === undefined ? {} : { messages: options.prompt }),+ ...(isRecord(serializedOptions) ? serializedOptions : {}),+ };}function getModelUsageDetails(