Skip to content

ChatVertexAI tool call not added in message parts #9950

@Specy

Description

@Specy

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

import dotenv from 'dotenv';
import { createAgent } from 'langchain';
import { tool } from '@langchain/core/tools';
import { z } from 'zod';
import { ChatVertexAI } from '@langchain/google-vertexai';

dotenv.config();

const agent = createAgent({
    model: new ChatVertexAI({
        model: 'gemini-3-pro-preview',
        location: 'global',
    }),
    tools: [
        tool(({ a, b }) => String(a + b), {
            name: 'add',
            description: 'Adds two numbers together',
            schema: z.object({
                a: z.number(),
                b: z.number(),
            }),
        }),
        // get value
        tool(
            ({ key }) => {
                return key === 'a' ? 1 : 2;
            },
            {
                name: 'get_value',
                description: 'Gets a value for a given key, either "a" or "b"',
                schema: z.object({
                    key: z.string(),
                }),
            },
        ),
        //print number
        tool(
            ({ value }) => {
                console.log('Value:', value);
                return 'Printed value to console';
            },
            {
                name: 'print_value',
                description: 'Prints a value to the console',
                schema: z.object({
                    value: z.number(),
                }),
            },
        ),
    ],
    systemPrompt: `You are a calculator, first, in parallel ask for the values of "a" and "b" using the "get_value" tool. Once you have both values, use the "add" tool to add them together. Finally, use the "print_value" tool to print the result. the explain a summary of what you did and why.`,
});

async function runAgent() {
    const response = await agent.invoke({
        messages: [
            {
                role: 'user',
                content: 'Calculate the sum of a and b',
            },
        ],
    });
    const parts = response.messages.map((v) => [v.type, v.contentBlocks]);
    console.log('Agent response:', JSON.stringify(parts, null, 2));
}

runAgent();

Error Message and Stack Trace (if applicable)

Details
[
  [
    "human",
    [
      {
        "type": "text",
        "text": "Calculate the sum of a and b"
      }
    ]
  ],
  [
    "ai",
    [
      {
        "type": "text",
        "text": ""
      }
    ]
  ],
  [
    "tool",
    [
      {
        "type": "text",
        "text": "1"
      }
    ]
  ],
  [
    "tool",
    [
      {
        "type": "text",
        "text": "2"
      }
    ]
  ],
  [
    "ai",
    [
      {
        "type": "text",
        "text": ""
      }
    ]
  ],
  [
    "tool",
    [
      {
        "type": "text",
        "text": "3"
      }
    ]
  ],
  [
    "ai",
    [
      {
        "type": "text",
        "text": ""
      }
    ]
  ],
  [
    "tool",
    [
      {
        "type": "text",
        "text": "Printed value to console"
      }
    ]
  ],
  [
    "ai",
    [
      {
        "type": "text",
        "text": "I have successfully completed the task.\n\n**Summary of actions:**\n1.  **Retrieval**: I requested the values for variables \"a\" and \"b\" simultaneously to maximize efficiency. The system returned `1` for \"a\" and `2` for \"b\".\n2.  **Calculation**: Using the retrieved numbers, I performed an addition operation ($1 + 2$).\n3.  **Output**: Finally, I printed the resulting sum, `3`, to the console.\n\n**Why:**\nThis sequence ensured that the correct values were obtained before processing, the mathematical operation was handled by the dedicated calculation tool, and the final result was displayed as requested."
      }
    ]
  ]
]

Description

When using tool calls with ChatVertexAI, tool call contents have type text instead of tool_call and there is no metadata inside of it.

If i use openai instead, each tool call makes a tool_call content block inside of the message.

There is also no thought signature inside of them. I'd need to rebuild the content blocks out of the messages myself.

System Info

langchain@1.2.18 | MIT | deps: 5 | versions: 381
Windows
node 24

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions