🪢 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(playground): gemini vertex traces (#9948)
Nimar7dbbafc14153
diff --git a/packages/shared/scripts/seeder/utils/framework-traces/google-vertex-tools-2025-09-19.json b/packages/shared/scripts/seeder/utils/framework-traces/google-vertex-tools-2025-09-19.jsonnew file mode 100644index 0000000000..1529d5702a--- /dev/null+++ b/packages/shared/scripts/seeder/utils/framework-traces/google-vertex-tools-2025-09-19.json@@ -0,0 +1,243 @@+{+ "traces": [+ {+ "id": "vertex-gemini-trace-001",+ "name": "Google Vertex AI Gemini Test Trace",+ "projectId": "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",+ "timestamp": "2025-09-19T21:59:59.005Z",+ "environment": "default",+ "tags": [],+ "bookmarked": false,+ "release": null,+ "version": null,+ "userId": null,+ "sessionId": null,+ "public": false+ }+ ],+ "observations": [+ {+ "id": "vertex-gemini-obs-001",+ "traceId": "vertex-gemini-trace-001",+ "projectId": "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a",+ "type": "GENERATION",+ "environment": "default",+ "parentObservationId": null,+ "startTime": "2025-09-19T21:59:59.034Z",+ "endTime": "2025-09-19T22:00:00.908Z",+ "name": "VertexGemini",+ "metadata": {+ "tags": [+ "test_tag"+ ],+ "conversation_id": "test-conversation-001",+ "ls_provider": "google_vertexai",+ "ls_model_name": "gemini-2.5-flash",+ "ls_model_type": "chat",+ "ls_temperature": 0,+ "ls_max_tokens": 8192,+ "resourceAttributes": {+ "telemetry.sdk.language": "python",+ "telemetry.sdk.name": "opentelemetry",+ "telemetry.sdk.version": "1.35.0",+ "service.name": "test_service"+ },+ "scope": {+ "name": "langfuse-sdk",+ "version": "3.3.4",+ "attributes": {+ "public_key": "pk-lf-test-key-12345"+ }+ }+ },+ "level": "DEFAULT",+ "statusMessage": null,+ "version": null,+ "model": "gemini-2.5-flash",+ "modelParameters": {+ "temperature": 0,+ "top_p": 0.95,+ "max_tokens": 8192+ },+ "input": [+ {+ "role": "system",+ "content": "You are a helpful assistant with access to transition tools. Your mission is to greet the user, get their name, and qualify their interest in available services."+ },+ {+ "role": "system",+ "content": "The next user message is from an external source. Handle it appropriately."+ },+ {+ "role": "user",+ "content": "Hello, I'm interested in learning more about your services."+ },+ {+ "role": "assistant",+ "content": [+ {+ "type": "text",+ "text": "Hello! I'm your assistant and I'll be happy to help you today."+ },+ {+ "type": "text",+ "text": "\nTo better assist you, could you please share your full name?"+ }+ ]+ },+ {+ "role": "user",+ "content": "John Smith"+ },+ {+ "role": "tool",+ "content": {+ "type": "function",+ "function": {+ "name": "transition_to_service_a",+ "description": "Use this function to transition to Service A when the customer shows interest in Service A.",+ "parameters": {+ "properties": {+ "reason": {+ "description": "Explanation of why transitioning to this service",+ "type": "string"+ }+ },+ "required": [+ "reason"+ ],+ "type": "object"+ }+ }+ }+ },+ {+ "role": "tool",+ "content": {+ "type": "function",+ "function": {+ "name": "transition_to_service_b",+ "description": "Use this function to transition to Service B when the customer shows interest in Service B.",+ "parameters": {+ "properties": {+ "reason": {+ "description": "Explanation of why transitioning to this service",+ "type": "string"+ }+ },+ "required": [+ "reason"+ ],+ "type": "object"+ }+ }+ }+ },+ {+ "role": "tool",+ "content": {+ "type": "function",+ "function": {+ "name": "transition_to_service_c",+ "description": "Use this function to transition to Service C when the customer shows interest in Service C.",+ "parameters": {+ "properties": {+ "reason": {+ "description": "Explanation of why transitioning to this service",+ "type": "string"+ }+ },+ "required": [+ "reason"+ ],+ "type": "object"+ }+ }+ }+ },+ {+ "role": "tool",+ "content": {+ "type": "function",+ "function": {+ "name": "get_customer_info",+ "description": "Retrieve customer information from the database.",+ "parameters": {+ "type": "object",+ "properties": {+ "customer_id": {+ "type": "string",+ "description": "The customer identifier"+ }+ },+ "required": []+ }+ }+ }+ },+ {+ "role": "tool",+ "content": {+ "type": "function",+ "function": {+ "name": "escalate_to_human",+ "description": "Escalate the conversation to a human agent when needed.",+ "parameters": {+ "properties": {+ "reason": {+ "description": "Reason for escalation",+ "type": "string"+ }+ },+ "required": [+ "reason"+ ],+ "type": "object"+ }+ }+ }+ }+ ],+ "output": {+ "content": "Thank you, John Smith. Which of our services are you interested in?",+ "additional_kwargs": {},+ "response_metadata": {+ "safety_ratings": [],+ "usage_metadata": {},+ "finish_reason": "STOP",+ "model_name": "gemini-2.5-flash"+ },+ "type": "AIMessageChunk",+ "name": null,+ "id": "run-vertex-test-001",+ "example": false,+ "tool_calls": [],+ "invalid_tool_calls": [],+ "usage_metadata": {+ "input_tokens": 1200,+ "output_tokens": 15,+ "total_tokens": 1215,+ "input_token_details": {+ "cache_read": 0+ },+ "output_token_details": {+ "reasoning": 0+ }+ },+ "tool_call_chunks": []+ },+ "inputUsage": 1200,+ "outputUsage": 15,+ "totalUsage": 1215,+ "inputCost": 0.0001,+ "outputCost": 0.00001,+ "totalCost": 0.00011,+ "calculatedInputCost": 0.0001,+ "calculatedOutputCost": 0.00001,+ "calculatedTotalCost": 0.00011,+ "latency": 1.874,+ "timeToFirstToken": null,+ "completionStartTime": null+ }+ ]+}diff --git a/web/src/features/playground/page/components/JumpToPlaygroundButton.tsx b/web/src/features/playground/page/components/JumpToPlaygroundButton.tsxindex 44205cfdb4..656ad505bf 100644--- a/web/src/features/playground/page/components/JumpToPlaygroundButton.tsx+++ b/web/src/features/playground/page/components/JumpToPlaygroundButton.tsx@@ -1,7 +1,6 @@import { Terminal, ChevronDown } from "lucide-react";import { useEffect, useState, useMemo } from "react";import { useRouter } from "next/router";-import { z } from "zod/v4";import { v4 as uuidv4 } from "uuid";import { createEmptyMessage } from "@/src/components/ChatMessages/utils/createEmptyMessage";@@ -28,7 +27,6 @@ import {type UIModelParams,ZodModelConfig,ChatMessageType,- OpenAIToolSchema,type ChatMessage,OpenAIResponseFormatSchema,type Prisma,@@ -36,7 +34,8 @@ import {PromptType,isGenerationLike,} from "@langfuse/shared";-import { normalizeInput, extractAdditionalInput } from "@/src/utils/chatml";+import { normalizeInput } from "@/src/utils/chatml";+import { extractTools } from "@/src/utils/chatml/extractTools";import { convertChatMlToPlayground } from "@/src/utils/chatml/playgroundConverter";import { api } from "@/src/utils/api";import { cn } from "@/src/utils/tailwind";@@ -259,7 +258,7 @@ const parseGeneration = (if (!isGenerationLike(generation.type)) return null;let modelParams = parseModelParams(generation, modelToProviderMap);- const tools = parseTools(generation);+ const tools = parseTools(generation.input);const structuredOutputSchema = parseStructuredOutputSchema(generation);const providerOptions = parseLitellmMetadataFromGeneration(generation);@@ -401,40 +400,15 @@ function parseModelParams(return modelParams;}-function parseTools(- generation: Omit<Observation, "input" | "output" | "metadata"> & {- input: string | null;- output: string | null;- metadata: string | null;- },-): PlaygroundTool[] {- try {- const input = JSON.parse(generation.input as string);-- // Check additional.tools , langchain puts tools there- const additionalInput = extractAdditionalInput(input);- if (additionalInput?.tools && Array.isArray(additionalInput.tools)) {- return additionalInput.tools.map((tool: any) => ({- id: Math.random().toString(36).substring(2),- name: tool.name || tool.function?.name,- description: tool.description || tool.function?.description,- parameters: tool.parameters || tool.function?.parameters,- }));- }+function parseTools(inputString: string | null): PlaygroundTool[] {+ if (!inputString) return [];- // OpenAI format: tools in input.tools field- if (typeof input === "object" && input !== null && "tools" in input) {- const parsedTools = z.array(OpenAIToolSchema).safeParse(input["tools"]);-- if (parsedTools.success)- return parsedTools.data.map((tool) => ({- id: Math.random().toString(36).substring(2),- ...tool.function,- }));- }- } catch {}-- return [];+ try {+ const input = JSON.parse(inputString);+ return extractTools(input);+ } catch {+ return [];+ }}function parseStructuredOutputSchema(diff --git a/web/src/utils/chatml/adapters/gemini.clienttest.ts b/web/src/utils/chatml/adapters/gemini.clienttest.tsnew file mode 100644index 0000000000..82b80cb6f7--- /dev/null+++ b/web/src/utils/chatml/adapters/gemini.clienttest.ts@@ -0,0 +1,144 @@+import { geminiAdapter } from "./gemini";+import type { NormalizerContext } from "../types";++describe("geminiAdapter", () => {+ describe("detect", () => {+ it.each([+ {+ name: "ls_provider metadata",+ ctx: { metadata: { ls_provider: "google_vertexai" } },+ },+ {+ name: "observation name with 'gemini'",+ ctx: { observationName: "VertexGemini" },+ },+ {+ name: "observation name with 'vertex'",+ ctx: { observationName: "vertex-ai-call" },+ },+ {+ name: "explicit framework",+ ctx: { framework: "gemini" },+ },+ ])("should detect Gemini format via $name", ({ ctx }) => {+ expect(geminiAdapter.detect(ctx as NormalizerContext)).toBe(true);+ });++ it("should detect via structural analysis (tool definitions in messages)", () => {+ const ctx: NormalizerContext = {+ metadata: {+ messages: [+ { role: "system", content: "System prompt" },+ {+ role: "tool",+ content: {+ type: "function",+ function: { name: "get_weather", description: "Get weather" },+ },+ },+ ],+ },+ };++ expect(geminiAdapter.detect(ctx)).toBe(true);+ });++ it("should not detect non-Gemini formats", () => {+ expect(+ geminiAdapter.detect({ metadata: { ls_provider: "openai" } }),+ ).toBe(false);+ expect(geminiAdapter.detect({ observationName: "OpenAI-call" })).toBe(+ false,+ );+ expect(geminiAdapter.detect({})).toBe(false);+ });+ });++ describe("preprocess", () => {+ it("should filter tool definitions and normalize structured content", () => {+ const input = [+ { role: "system", content: "System prompt" },+ {+ role: "assistant",+ content: [+ { type: "text", text: "Hello! " },+ { type: "text", text: "How can I help?" },+ ],+ },+ {+ role: "tool",+ content: {+ type: "function",+ function: {+ name: "get_weather",+ description: "Get weather",+ parameters: {},+ },+ },+ },+ {+ role: "user",+ content: [{ type: "text", text: "What's the weather?" }],+ },+ ];++ const result = geminiAdapter.preprocess(input, "input", {}) as any[];++ // Tool definition filtered out+ expect(result.length).toBe(3);++ // Content normalized from structured to plain text+ expect(result[0].content).toBe("System prompt");+ expect(result[1].content).toBe("Hello! How can I help?");+ expect(result[2].content).toBe("What's the weather?");+ });++ it("should preserve tool result messages (not filter them)", () => {+ const input = [+ {+ role: "assistant",+ content: [{ type: "text", text: "Let me check." }],+ },+ {+ role: "tool",+ content: "Temperature is 72°F", // String content = tool RESULT+ tool_call_id: "call_123",+ },+ ];++ const result = geminiAdapter.preprocess(input, "input", {}) as any[];++ expect(result.length).toBe(2);+ expect(result[1].role).toBe("tool");+ expect(result[1].content).toBe("Temperature is 72°F");+ expect(result[1].tool_call_id).toBe("call_123");+ });++ it("should handle input wrapped in messages field", () => {+ const input = {+ messages: [+ { role: "system", content: "System" },+ {+ role: "tool",+ content: {+ type: "function",+ function: { name: "tool1", description: "Tool 1" },+ },+ },+ {+ role: "user",+ content: [{ type: "text", text: "User message" }],+ },+ ],+ extra: "metadata",+ };++ const result = geminiAdapter.preprocess(input, "input", {}) as any;++ expect(result.messages.length).toBe(2);+ expect(result.messages[0].content).toBe("System");+ expect(result.messages[1].content).toBe("User message");+ expect(result.extra).toBe("metadata");+ });+ });+});diff --git a/web/src/utils/chatml/adapters/gemini.ts b/web/src/utils/chatml/adapters/gemini.tsnew file mode 100644index 0000000000..259d2ee316--- /dev/null+++ b/web/src/utils/chatml/adapters/gemini.ts@@ -0,0 +1,147 @@+import type { NormalizerContext, ProviderAdapter } from "../types";+import { parseMetadata } from "../helpers";++export function isGeminiToolDefinition(msg: unknown): boolean {+ if (!msg || typeof msg !== "object") return false;++ const message = msg as Record<string, unknown>;++ // Gemini tool definitions have:+ // - role: "tool"+ // - content.type: "function"+ // - content.function: {name, description, parameters}+ return (+ message.role === "tool" &&+ typeof message.content === "object" &&+ message.content !== null &&+ !Array.isArray(message.content) &&+ (message.content as Record<string, unknown>).type === "function" &&+ !!(message.content as Record<string, unknown>).function+ );+}++export function extractGeminiToolDefinitions(messages: unknown[]): Array<{+ name: string;+ description: string;+ parameters: Record<string, unknown>;+}> {+ return messages.filter(isGeminiToolDefinition).map((msg) => {+ const message = msg as Record<string, unknown>;+ const func = (message.content as Record<string, unknown>)+ .function as Record<string, unknown>;+ return {+ name: (func.name as string) || "",+ description: (func.description as string) || "",+ parameters: (func.parameters as Record<string, unknown>) || {},+ };+ });+}++function normalizeGeminiMessage(msg: unknown): Record<string, unknown> {+ if (!msg || typeof msg !== "object") return {};++ const message = msg as Record<string, unknown>;+ const normalized = { ...message };++ // Gemini structured content: content: [{type: "text", text: "..."}]+ // Convert to plain string for ChatML compatibility+ if (Array.isArray(message.content)) {+ const textParts = message.content+ .map((part: unknown) => {+ if (typeof part === "object" && part !== null) {+ const p = part as Record<string, unknown>;+ // Gemini format: {type: "text", text: "..."}+ if (p.type === "text" && typeof p.text === "string") {+ return p.text;+ }+ // Fallback: {text: "..."}+ if (typeof p.text === "string") {+ return p.text;+ }+ }+ // If part is already a string+ if (typeof part === "string") {+ return part;+ }+ return "";+ })+ .filter((text: unknown) => text !== "")+ .join("");++ if (textParts) {+ normalized.content = textParts;+ }+ }++ return normalized;+}++function filterAndNormalizeMessages(data: unknown[]): unknown[] {+ return data+ .filter((msg) => !isGeminiToolDefinition(msg))+ .map(normalizeGeminiMessage);+}++function preprocessData(data: unknown): unknown {+ if (!data) return data;++ // Array of messages - filter tool definitions and normalize content+ if (Array.isArray(data)) {+ return filterAndNormalizeMessages(data);+ }++ // Object with messages key+ if (typeof data === "object" && "messages" in data) {+ const obj = data as Record<string, unknown>;+ return {+ ...obj,+ messages: Array.isArray(obj.messages)+ ? filterAndNormalizeMessages(obj.messages)+ : obj.messages,+ };+ }++ return data;+}++export const geminiAdapter: ProviderAdapter = {+ id: "gemini",++ detect(ctx: NormalizerContext): boolean {+ const meta = parseMetadata(ctx.metadata);++ // Explicit framework override+ if (ctx.framework === "gemini") return true;++ // LangSmith metadata for Google VertexAI+ if (meta?.ls_provider === "google_vertexai") return true;++ // Observation name hint+ if (ctx.observationName?.toLowerCase().includes("gemini")) return true;+ if (ctx.observationName?.toLowerCase().includes("vertex")) return true;++ // Structural: check if data contains Gemini tool definition messages+ // This is a last-resort detection for unlabeled Gemini traces+ if (+ typeof ctx.metadata === "object" &&+ ctx.metadata !== null &&+ "messages" in ctx.metadata+ ) {+ const messages = (ctx.metadata as Record<string, unknown>).messages;+ if (Array.isArray(messages)) {+ const hasGeminiTools = messages.some(isGeminiToolDefinition);+ if (hasGeminiTools) return true;+ }+ }++ return false;+ },++ preprocess(+ data: unknown,+ _kind: "input" | "output",+ _ctx: NormalizerContext,+ ): unknown {+ return preprocessData(data);+ },+};diff --git a/web/src/utils/chatml/adapters/index.ts b/web/src/utils/chatml/adapters/index.tsindex 4b5730e08f..f399dd3518 100644--- a/web/src/utils/chatml/adapters/index.ts+++ b/web/src/utils/chatml/adapters/index.ts@@ -2,11 +2,13 @@ import type { NormalizerContext, ProviderAdapter } from "../types";import { mapToChatMl, mapOutputToChatMl } from "../core";import { langgraphAdapter } from "./langgraph";import { openAIAdapter } from "./openai";+import { geminiAdapter } from "./gemini";import { genericAdapter } from "./generic";const adapters: ProviderAdapter[] = [langgraphAdapter, // Must be before openAI (both use langfuse-sdk scope)openAIAdapter,+ geminiAdapter, // Gemini/VertexAI format// Add more adapters here as neededgenericAdapter, // Always last (fallback)];diff --git a/web/src/utils/chatml/extractTools.ts b/web/src/utils/chatml/extractTools.tsnew file mode 100644index 0000000000..c6bcb8e51e--- /dev/null+++ b/web/src/utils/chatml/extractTools.ts@@ -0,0 +1,72 @@+import { z } from "zod/v4";+import { OpenAIToolSchema } from "@langfuse/shared";+import type { PlaygroundTool } from "@/src/features/playground/page/types";+import { extractGeminiToolDefinitions } from "./adapters/gemini";+import { extractAdditionalInput } from "./core";++/**+ * Extracts tool definitions from various LLM input formats.+ * Supports OpenAI, LangChain, and Gemini formats.+ *+ * @param input - Parsed input object (messages array or object with messages)+ * @returns Array of PlaygroundTool objects with id, name, description, and parameters+ */+export function extractTools(input: unknown): PlaygroundTool[] {+ if (!input) return [];++ // LangChain format: tools in additional.tools field+ const additionalInput = extractAdditionalInput(input);+ if (additionalInput?.tools && Array.isArray(additionalInput.tools)) {+ return additionalInput.tools.map((tool: any) => ({+ id: Math.random().toString(36).substring(2),+ name: tool.name || tool.function?.name,+ description: tool.description || tool.function?.description,+ parameters: tool.parameters || tool.function?.parameters,+ }));+ }++ // OpenAI format: tools in input.tools field+ if (typeof input === "object" && input !== null && "tools" in input) {+ const parsedTools = z+ .array(OpenAIToolSchema)+ .safeParse((input as Record<string, unknown>)["tools"]);++ if (parsedTools.success) {+ return parsedTools.data.map((tool) => ({+ id: Math.random().toString(36).substring(2),+ ...tool.function,+ }));+ }+ }++ // Gemini format: tool definitions embedded in messages array+ if (Array.isArray(input)) {+ const geminiTools = extractGeminiToolDefinitions(input);+ if (geminiTools.length > 0) {+ return geminiTools.map((tool) => ({+ id: Math.random().toString(36).substring(2),+ ...tool,+ }));+ }+ }++ // Also check messages field within input object (Gemini nested format)+ if (+ typeof input === "object" &&+ input !== null &&+ "messages" in input &&+ Array.isArray((input as Record<string, unknown>).messages)+ ) {+ const geminiTools = extractGeminiToolDefinitions(+ (input as Record<string, unknown>).messages as unknown[],+ );+ if (geminiTools.length > 0) {+ return geminiTools.map((tool) => ({+ id: Math.random().toString(36).substring(2),+ ...tool,+ }));+ }+ }++ return [];+}diff --git a/web/src/utils/chatml/jumptoplayground.clienttest.ts b/web/src/utils/chatml/jumptoplayground.clienttest.tsindex 9ae821cbc4..5eca3ef335 100644--- a/web/src/utils/chatml/jumptoplayground.clienttest.ts+++ b/web/src/utils/chatml/jumptoplayground.clienttest.ts@@ -19,6 +19,7 @@ jest.mock("@langfuse/shared", () => ({import { normalizeInput } from "./adapters";import { convertChatMlToPlayground } from "./playgroundConverter";+import { extractTools } from "./extractTools";describe("Playground Jump Full Pipeline", () => {it("should convert full trace with tool calls through mapper and playground conversion", () => {@@ -201,4 +202,198 @@ describe("Playground Jump Full Pipeline", () => {expect(toolResult2.content).toContain("Settings > API Configuration");}});++ it("should handle Gemini-style tool definitions embedded in messages", () => {+ // Gemini format embeds tool definitions as messages with role="tool"+ // This test verifies that:+ // 1. Tool definition messages are filtered out of the message list+ // 2. Tool definitions are extracted and available for the playground+ const observationName = "VertexGemini";+ const metadata = {+ ls_provider: "google_vertexai",+ ls_model_name: "gemini-2.5-flash",+ ls_model_type: "chat",+ ls_temperature: 0,+ ls_max_tokens: 8192,+ };++ const input = [+ {+ role: "system",+ content: "You are a helpful assistant with access to tools.",+ },+ {+ role: "assistant",+ content: [+ {+ type: "text",+ text: "Hello! How can I help you today?",+ },+ ],+ },+ {+ role: "tool",+ content: {+ type: "function",+ function: {+ name: "transition_to_next_stage",+ description:+ "Use this function to transition to the next stage when conditions are met",+ parameters: {+ properties: {+ reason: {+ description: "Explanation of why transitioning",+ type: "string",+ },+ },+ required: ["reason"],+ type: "object",+ },+ },+ },+ },+ {+ role: "tool",+ content: {+ type: "function",+ function: {+ name: "get_user_info",+ description: "Retrieve user contact information",+ parameters: {+ type: "object",+ properties: {},+ required: [],+ },+ },+ },+ },+ {+ role: "user",+ content: "What can you do?",+ },+ ];++ const ctx = { metadata, observationName };+ const inResult = normalizeInput(input, ctx);++ expect(inResult.success).toBe(true);+ if (!inResult.data) throw new Error("Expected data to be defined");++ // Convert all messages to playground format+ const playgroundMessages = inResult.data+ .map(convertChatMlToPlayground)+ .filter((msg) => msg !== null);++ // Should have 3 real messages (system, assistant, user)+ // Tool definition messages should be filtered out by the converter+ expect(playgroundMessages.length).toBe(3);++ // Filter out placeholder messages for role testing+ const regularMessages = playgroundMessages.filter(+ (msg) => msg.type !== "placeholder",+ );++ // Verify message roles+ expect(regularMessages[0]?.role).toBe("system");+ expect(regularMessages[1]?.role).toBe("assistant");+ expect(regularMessages[2]?.role).toBe("user");++ // All should have type public-api-created (regular messages)+ expect(playgroundMessages[0]?.type).toBe("public-api-created");+ expect(playgroundMessages[1]?.type).toBe("public-api-created");+ expect(playgroundMessages[2]?.type).toBe("public-api-created");++ // IMPORTANT: Test that tools are extracted from the Gemini input format+ // The parseTools function in JumpToPlaygroundButton.tsx needs to handle Gemini format+ // where tool definitions are embedded as messages with role="tool"++ // We need to test parseTools behavior directly+ // For now, manually verify the structure exists+ const toolMessages = input.filter(+ (msg: any) =>+ msg.role === "tool" &&+ typeof msg.content === "object" &&+ msg.content?.type === "function" &&+ msg.content?.function,+ );++ // Verify the structure that parseTools should handle+ expect(toolMessages.length).toBe(2);+ expect((toolMessages[0].content as any).function.name).toBe(+ "transition_to_next_stage",+ );+ expect((toolMessages[1].content as any).function.name).toBe(+ "get_user_info",+ );+ });++ it("should extract tools from Gemini format using extractTools utility", () => {+ const geminiInput = [+ {+ role: "system",+ content: "You are a helpful assistant.",+ },+ {+ role: "tool",+ content: {+ type: "function",+ function: {+ name: "get_weather",+ description: "Get the current weather in a location",+ parameters: {+ type: "object",+ properties: {+ location: {+ type: "string",+ description: "The city name",+ },+ },+ required: ["location"],+ },+ },+ },+ },+ {+ role: "tool",+ content: {+ type: "function",+ function: {+ name: "search_web",+ description: "Search the web for information",+ parameters: {+ type: "object",+ properties: {+ query: {+ type: "string",+ description: "Search query",+ },+ },+ required: ["query"],+ },+ },+ },+ },+ ];++ // Test the exported extractTools utility directly+ const tools = extractTools(geminiInput);++ expect(tools.length).toBe(2);+ expect(tools[0]).toEqual({+ id: expect.any(String),+ name: "get_weather",+ description: "Get the current weather in a location",+ parameters: {+ type: "object",+ properties: {+ location: {+ type: "string",+ description: "The city name",+ },+ },+ required: ["location"],+ },+ });+ expect(tools[1].name).toBe("search_web");+ });});