Skip to content

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

fix(playground): parse pipecat tools (#14120)

Nimarec2138d5c2ec
diff --git a/web/src/utils/chatml/extractTools.ts b/web/src/utils/chatml/extractTools.ts
index ab3a663c3a..4372af4224 100644
--- a/web/src/utils/chatml/extractTools.ts
+++ b/web/src/utils/chatml/extractTools.ts
@@ -72,6 +72,11 @@ export function extractTools(
);
if (genAiTools.length > 0) return genAiTools;
+ // Some traces store OpenAI-style tool definitions in a plain metadata
+ // attributes.tools field instead of the canonical GenAI key.
+ const metadataTools = mapToolsToPlayground(attributes.tools);
+ if (metadataTools.length > 0) return metadataTools;
+
// pydantic-ai: tools in model_request_parameters.function_tools
const modelRequestParameters = asRecord(
attributes.model_request_parameters,
diff --git a/web/src/utils/chatml/jumptoplayground.clienttest.ts b/web/src/utils/chatml/jumptoplayground.clienttest.ts
index 06f5a9d6b9..a033b614a0 100644
--- a/web/src/utils/chatml/jumptoplayground.clienttest.ts
+++ b/web/src/utils/chatml/jumptoplayground.clienttest.ts
@@ -1033,6 +1033,73 @@ describe("Playground Jump Full Pipeline", () => {
});
});
+ it("should pass metadata attributes.tools into playground tools", () => {
+ const input = [
+ {
+ role: "assistant",
+ tool_calls: [
+ {
+ id: "call_demo_lookup",
+ function: {
+ name: "demo_lookup",
+ arguments: '{"query":"example"}',
+ },
+ type: "function",
+ },
+ ],
+ },
+ {
+ role: "tool",
+ content: '{"status":"ok"}',
+ tool_call_id: "call_demo_lookup",
+ },
+ ];
+ const expectedTool = {
+ name: "demo_lookup",
+ description: "Lookup a demo value.",
+ parameters: {
+ type: "object",
+ properties: { query: { type: "string" } },
+ required: ["query"],
+ },
+ };
+ const metadata = {
+ attributes: {
+ tools: JSON.stringify([
+ {
+ type: "function",
+ function: expectedTool,
+ },
+ ]),
+ tool_count: "1",
+ },
+ };
+ const ctx = { metadata, observationName: "llm" };
+
+ const inResult = normalizeInput(input, ctx);
+ expect(inResult.success).toBe(true);
+ if (!inResult.data) throw new Error("Expected data to be defined");
+
+ const playgroundMessages = inResult.data
+ .map(convertChatMlToPlayground)
+ .filter((msg) => msg !== null);
+
+ expect(
+ playgroundMessages.some((msg) => msg.type === "assistant-tool-call"),
+ ).toBe(true);
+ expect(playgroundMessages.some((msg) => msg.type === "tool-result")).toBe(
+ true,
+ );
+
+ // Same merge behavior as JumpToPlaygroundButton.parseGeneration.
+ const normalizedTools = extractTools(inResult.data, ctx.metadata);
+ const rawTools = extractTools(input, metadata);
+ const mergedTools = normalizedTools.length > 0 ? normalizedTools : rawTools;
+
+ expect(mergedTools).toHaveLength(1);
+ expect(mergedTools[0]).toMatchObject(expectedTool);
+ });
+
it("should handle double-stringified messages array", () => {
// ClickHouse can store messages as double-stringified:
// { "messages": "[{\"role\":\"user\",\"content\":\"...\"}]" }