Skip to content

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

fix(tracing): parse standalone Responses tool calls (#14654)

Hassieb Pakzad65fd06a48ba1
diff --git a/packages/shared/src/server/ingestion/extractToolsBackend.ts b/packages/shared/src/server/ingestion/extractToolsBackend.ts
index 6678767857..44dbbeb11d 100644
--- a/packages/shared/src/server/ingestion/extractToolsBackend.ts
+++ b/packages/shared/src/server/ingestion/extractToolsBackend.ts
@@ -91,7 +91,7 @@ function flattenToolCall(call: unknown): {
typeof rawArgs === "string" ? rawArgs : JSON.stringify(rawArgs ?? {});
return {
- id: (c.id ?? c.toolCallId ?? c.call_id) as string | undefined,
+ id: (c.call_id ?? c.id ?? c.toolCallId) as string | undefined,
name,
arguments: args,
type: (c.type ?? (func ? "function" : undefined)) as string | undefined,
@@ -307,6 +307,11 @@ function extractToolCallsFromRawOutput(
if (typeof output !== "object") return;
const obj = output as Record<string, unknown>;
+ if (isToolCallLike(obj) && !isMessageLike(obj)) {
+ addToolArgument(args, obj);
+ return;
+ }
+
// Direct tool_calls at top level
const directToolCalls =
parseArrayIfString(obj.tool_calls) ?? parseArrayIfString(obj.toolCalls);
diff --git a/packages/shared/src/utils/chatml/adapters/openai.ts b/packages/shared/src/utils/chatml/adapters/openai.ts
index 1bba889103..692d917d2f 100644
--- a/packages/shared/src/utils/chatml/adapters/openai.ts
+++ b/packages/shared/src/utils/chatml/adapters/openai.ts
@@ -340,6 +340,16 @@ function preprocessData(data: unknown): unknown {
}
}
+ if (
+ typeof data === "object" &&
+ !Array.isArray(data) &&
+ ["function_call", "tool_call", "function_call_output"].includes(
+ String((data as Record<string, unknown>).type),
+ )
+ ) {
+ return normalizeMessage(data);
+ }
+
// Array of messages
if (Array.isArray(data)) {
return data.map(normalizeMessage);
diff --git a/web/src/utils/chatml/jumptoplayground.clienttest.ts b/web/src/utils/chatml/jumptoplayground.clienttest.ts
index a033b614a0..98da6c8844 100644
--- a/web/src/utils/chatml/jumptoplayground.clienttest.ts
+++ b/web/src/utils/chatml/jumptoplayground.clienttest.ts
@@ -763,6 +763,32 @@ describe("Playground Jump Full Pipeline", () => {
}
});
+ it("should normalize standalone OpenAI Responses function_call output", () => {
+ const output = {
+ id: "fc_order_status",
+ type: "function_call",
+ status: "completed",
+ arguments: '{"orderIds":null}',
+ call_id: "call_order_status",
+ name: "getOrderStatus",
+ };
+
+ const outputResult = normalizeOutput(output, { framework: "openai" });
+ expect(outputResult.success).toBe(true);
+
+ expect(outputResult.data![0]).toMatchObject({
+ role: "assistant",
+ tool_calls: [
+ {
+ id: "call_order_status",
+ name: "getOrderStatus",
+ arguments: '{"orderIds":null}',
+ type: "function",
+ },
+ ],
+ });
+ });
+
it("should handle VAPI camelCase toolCalls and preserve IDs", () => {
// VAPI uses camelCase toolCalls instead of tool_calls
// Critical: Tool call IDs must be preserved for OpenAI API compatibility
diff --git a/worker/src/__tests__/extractToolsBackend.test.ts b/worker/src/__tests__/extractToolsBackend.test.ts
index e8e9467308..444b4e726f 100644
--- a/worker/src/__tests__/extractToolsBackend.test.ts
+++ b/worker/src/__tests__/extractToolsBackend.test.ts
@@ -503,6 +503,27 @@ describe("extractToolsFromObservation", () => {
});
});
+ it("extracts standalone OpenAI Responses function_call output", () => {
+ const output = {
+ id: "fc_order_status",
+ type: "function_call",
+ status: "completed",
+ arguments: '{"orderIds":null}',
+ call_id: "call_order_status",
+ name: "getOrderStatus",
+ };
+
+ const { toolArguments } = extractToolsFromObservation(null, output);
+
+ expect(toolArguments).toHaveLength(1);
+ expect(toolArguments[0]).toEqual({
+ id: "call_order_status",
+ name: "getOrderStatus",
+ arguments: '{"orderIds":null}',
+ type: "function_call",
+ });
+ });
+
it("extracts Anthropic tool_use from content array", () => {
const output = {
content: [