Langchain@next content always empty when tool calling

const getWeather = tool((city: string) => `It's always sunny in ${city}!`, {
  name: 'get_weather',
  description: 'Get the weather for a given city',
});

const agent = createAgent({
  model: 'openai:gpt-4o-mini',
  tools: [getWeather],
});

agent
  .invoke({
    messages: [{ role: 'user', content: "What's the weather in Tokyo?" }],
  })
  .then((res) => {
    console.log(res);
  });

use the code exactly from sample Quickstart - Docs by LangChain
but content in response is always empty

{
  messages: [
    HumanMessage {
      "id": "704fd9e6-9d15-43f7-9268-d50e857897b3",
      "content": "What's the weather in Tokyo?",
      "additional_kwargs": {},
      "response_metadata": {}
    },
    AIMessage {
      "id": "chatcmpl-CEASroUeTijBpNtfPmG8tY8efJ39q",
      "content": "",
      "name": "model",
      "additional_kwargs": {
        "tool_calls": [
          {
            "id": "call_ogZt1iYD5R0jq7yhsqY2P53f",
            "type": "function",
            "function": "[Object]"
          }
        ]
      },
      "response_metadata": {
        "tokenUsage": {
          "promptTokens": 51,
          "completionTokens": 14,
          "totalTokens": 65
        },
        "finish_reason": "tool_calls",
        "model_provider": "openai",
        "model_name": "gpt-4o-mini-2024-07-18",
        "usage": {
          "prompt_tokens": 51,
          "completion_tokens": 14,
          "total_tokens": 65,
          "prompt_tokens_details": {
            "cached_tokens": 0,
            "audio_tokens": 0
          },
          "completion_tokens_details": {
            "reasoning_tokens": 0,
            "audio_tokens": 0,
            "accepted_prediction_tokens": 0,
            "rejected_prediction_tokens": 0
          }
        },
        "system_fingerprint": "fp_8bda4d3a2c"
      },
      "tool_calls": [
        {
          "name": "get_weather",
          "args": {
            "input": "Tokyo"
          },
          "type": "tool_call",
          "id": "call_ogZt1iYD5R0jq7yhsqY2P53f"
        }
      ],
      "invalid_tool_calls": [],
      "usage_metadata": {
        "output_tokens": 14,
        "input_tokens": 51,
        "total_tokens": 65,
        "input_token_details": {
          "audio": 0,
          "cache_read": 0
        },
        "output_token_details": {
          "audio": 0,
          "reasoning": 0
        }
      }
    }
  ]
}

Thanks @duyld for reporting this :folded_hands: it seems like for some reason your project uses multiple versions of @langchain/core which causes some instanceof checks to fail. We have pushed a patch for this and push out a new alpha version now. Thanks for testing and let us know if you encounter more issues.

2 Likes