我正在使用 n8n Cloud(免費方案)、版本 2.36.7 ,搭配原生的 Google Gemini Chat Model 和 AI Agent / Agent Tool 框架。
我的主管使用:
Gemma 4 31B IT (models/gemma-4-31b-it)
我的子代理使用:
Gemma 4 26B A4B IT (models/gemma-4-26b-a4b-it)
當主管呼叫子代理時,我收到此錯誤:
Unknown content type thinking
不使用工具呼叫的正常請求運作正常。錯誤發生在代理使用工具時,因此我懷疑這與 Gemma 的思考輸出被傳遞到代理/工具呼叫迴圈有關。
Google AI Studio 允許我設定:
"thinkingConfig": {
"thinkingLevel": "MINIMAL"
}
但我在 n8n 的原生 Google Gemini Chat Model 節點中找不到等效的設定。
我的問題:
有沒有辦法在原生 Gemini Chat Model 節點中停用思考或設定 thinkingLevel: MINIMAL?
如果沒有,有沒有其他方法可以解決 Unknown content type thinking 錯誤,同時保持 n8n 主管 + 子代理/Agent Tool 架構?
我不想用 HTTP Request 替換 Chat Model,因為我想保留 n8n 的原生代理/工具呼叫框架。
謝謝!
嘿 @T_Al ,在等待回覆的同時,這裡有一些可能對你有幫助的資源:
建議的資源
自動匹配到你的問題。
文件:
論壇:
@wilfridoco 、@nguyenthieutoan 、@Anshul_Namdev - 你們之前幫忙解決過類似的問題,能看一下嗎?
由 n8n 社群機器人自動建議。這是試點計畫 - 請在此分享回饋 。
Hi @T_Al 歡迎!
Gemini 節點沒有思考控制,其選項僅限於最大令牌、溫度、Top K、Top P 和安全設置。Vertex 節點具有您想要的開關「思考預算」,其中 0 可禁用自動思考:
將監督者和兩個子代理都指向 Google Vertex Chat Model 子節點,並將思考預算設為 0。代理和代理工具的接線保持完全相同,只有憑證會變更,因為 Vertex 使用 Google Cloud 服務帳戶而不是 AI Studio 密鑰。
該錯誤本身是上游的。Gemini 的思考區塊解析為轉換器在下一輪重新播放歷史記錄時沒有對應情況的內容類型,這就是為什麼只有在調用工具時才會觸發:
opened 11:51PM - 19 Feb 26 UTC
closed 08:42PM - 16 Mar 26 UTC
## Description
When using `ChatGoogleGenerativeAI` with `thinkingConfig.include… Thoughts: true` and tools bound, the first LLM call succeeds but the **second turn crashes** with `Unknown content type thinking`.
The issue is in `_convertLangChainContentToPart` (`packages/langchain-google-genai/src/utils/common.ts`). When Gemini returns thinking blocks, they're correctly parsed into LangChain content blocks with `type: "thinking"`. However, when the conversation history is sent back to Gemini on the next turn, `_convertLangChainContentToPart` has no case for `type: "thinking"` and throws.
This makes `thinkingConfig` **completely unusable** in any multi-turn agent loop with tools (e.g., LangGraph's `createReactAgent`).
## Reproduction
```typescript
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
import { tool } from "@langchain/core/tools";
import { z } from "zod";
const getWeather = tool(
async ({ city }) => `Weather in ${city}: 72°F, sunny`,
{
name: "get_weather",
description: "Get weather for a city",
schema: z.object({ city: z.string() }),
}
);
const model = new ChatGoogleGenerativeAI({
model: "gemini-2.5-flash", // any thinking-capable model
thinkingConfig: {
includeThoughts: true,
thinkingBudget: 8000,
},
});
const agent = createReactAgent({ llm: model, tools: [getWeather] });
const result = await agent.invoke({
messages: [{ role: "user", content: "What's the weather in Tokyo and SF? Compare them." }],
});
// ^ Crashes on second LLM call after tool results are returned
```
## Error
```
Error: Unknown content type thinking
at _convertLangChainContentToPart (node_modules/@langchain/google-genai/src/utils/common.ts:343:13)
at convertMessageContentToParts (node_modules/@langchain/google-genai/src/utils/common.ts:406:21)
at convertBaseMessagesToContent (node_modules/@langchain/google-genai/src/utils/common.ts:473:21)
at ChatGoogleGenerativeAI._streamResponseChunks (node_modules/@langchain/google-genai/src/chat_models.ts:915:20)
```
## Root Cause
In `src/utils/common.ts`, `_convertLangChainContentToPart` handles `text`, `image_url`, `media`, `tool_use`, `tool_call`, and MIME types — but has no case for `thinking`:
```typescript
// Current code (around line 343):
else if ("type" in content) throw new Error(`Unknown content type ${content.type}`);
```
## Suggested Fix
Add a case for `thinking` content blocks, converting them back to Gemini's thought part format:
```typescript
else if (content.type === "thinking") {
return {
text: content.text ?? "",
thought: true,
...(content.thoughtSignature ? { thoughtSignature: content.thoughtSignature } : {}),
};
}
```
Per [Gemini docs](https://ai.google.dev/gemini-api/docs/thinking), thought signatures must be returned in subsequent turns for Gemini 3+ models, so filtering them out is not a correct fix.
## Expected Behavior
Multi-turn conversations with `thinkingConfig` enabled should work without crashing. Thinking content blocks should be properly round-tripped back to Gemini API format.
## Environment
- `@langchain/google-genai`: 2.1.19 (latest)
- `@langchain/core`: 0.3.x
- `@langchain/langgraph`: 0.2.x
- Node.js: 22.x
- Models tested: `gemini-2.5-flash`, `gemini-2.5-pro`, `gemini-3.1-pro-preview`
謝謝!
我想知道:既然這個問題在 langchain github 上已經解決了好幾個月,而且可以通過修復 n8n 中 Chat Model 的底層代碼來解決。是否有某些版本的 n8n 已經解決了這個問題?或者有計劃這樣做嗎?
我想像任何在使用工具調用和歷史記錄的思考代理下的聊天模型都可能發生這種情況,不僅僅是 Gemini
T_Al:
T_Al:
這些模型與 OpenAI 工具呼叫不相容。您需要切換到其他模型。
您的 2.36.7 已經固定 @langchain/google-genai 2.1.24,而目前 n8n master 也固定同一版本,所以沒有 n8n 發布版本可升級以改變此情況。您找到的 10103 修復已在三月合併,且已包含在您執行的構建中。
仍未解決的是 10729,針對 AI Studio 上的 gemma-4-31b-it 提出:Gemma 4 將其思考區塊混入內容欄位,沒有可靠的方法將乾淨的文本提取回來,這是在工具調用時重新播放歷史記錄後失敗的原因。
opened 02:05PM - 18 Apr 26 UTC
bug
### Checked other resources
- [x] This is a bug, not a usage question. For ques… tions, please use the LangChain Forum (https://forum.langchain.com/).
- [x] I added a very descriptive title to this issue.
- [x] I searched the LangChain.js documentation with the integrated search.
- [x] I used the GitHub search to find a similar question and didn't find it.
- [x] I am sure that this is a bug in LangChain.js rather than my code.
- [x] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
### Example Code
### Problem
When using the **Gemma 4** model (`gemma-4-31b-it`) from Google AI Studio with `@langchain/google` in TypeScript, thinking/reasoning content is frequently mixed into the final response.
It is difficult to reliably extract a clean text response from the model output.
### Model Configuration
```ts
const model = new ChatGoogle({
model: 'gemma-4-31b-it',
apiKey: process.env.GEMINI_API_KEY,
temperature: 0.9,
});
```
### Observed Behavior
- The `content` field (from the last message after `agent.invoke()`) sometimes contains a mix of thinking steps and the actual answer.
- The output format is inconsistent (`content` can be a string or an array of objects).
- There is no straightforward, reliable way to get only the final clean text response.
In comparison, the same model works cleanly in the Python SDK, where `response.text` provides a clean answer without thinking content leaking in.
### Environment
- `langchain`: ^1.3.1
- `@langchain/core`: ^1.1.39
- `@langchain/google`: ^0.1.10
- `@google/genai`: ^1.43.0
- `@langchain/langgraph`: ^1.2.8
- Model: `gemma-4-31b-it` (Google AI Studio)
- Using LangGraph agent with `agent.invoke(...)`
### Additional Context
Gemma 4 is a reasoning model that tends to generate internal thinking steps before producing the final answer. This behavior causes the mixed output in the TypeScript integration.
This makes it significantly harder to use Gemma 4 reliably in TypeScript compared to Python.
I can provide raw response examples or more details if needed.
Thank you!
### Error Message and Stack Trace (if applicable)
_No response_
### Description
In langchain TS sdk, when using google models, now i am using __, it is too difficult to get the text response, it seems like there is not realiable way.
I use the python sdk too, and it has a realiable way, the documentation explicitly says,
response.content # -> [{"type": "text", "text": "Hello!", "extras": {"signature": "EpQFCp..."}}]
response.text # -> "Hello!"
i follow this and it works well. But for langchain TS, it's messay.
### System Info
{
"scripts": {
"bot": "tsx bot/index.ts",
"voice": "tsx main.mts",
"test-live": "tsx bot/test-live-audio.ts"
},
"dependencies": {
"@google/genai": "^1.43.0",
"@langchain/core": "^1.1.39",
"@langchain/google": "^0.1.10",
"@langchain/langgraph": "^1.2.8",
"@langchain/langgraph-checkpoint-sqlite": "^1.0.1",
"@langchain/xai": "^1.3.16",
"@types/ws": "^8.18.1",
"dotenv": "^17.4.1",
"ffmpeg-static": "^5.3.0",
"langchain": "^1.3.1",
"langsmith": "^0.5.17",
"playwright": "^1.59.1"
},
"devDependencies": {
"@types/node": "^25.3.3",
"tsx": "^4.21.0",
"typescript": "^5.9.3"
}
}
關於您更廣泛的觀點,這比看起來更狹隘。Gemma 4 確實支援原生函數調用,所以工具連接不是破裂的原因。Gemma 內容形狀才是。
上面提到的 Vertex-node 思考預算答案是乾淨的解決方案。如果留在 AI Studio 金鑰很重要(免費方案,無 GCP 專案),有兩個替代方案:
繞過 Supervisor 的節點。 只將 Supervisor 的模型替換為呼叫 Gemini API 的 HTTP Request 節點,您可以傳遞 "thinkingConfig": {"thinkingLevel": "MINIMAL"} — 與 AI Studio 提供的相同酬載。您會失去該模型的原生代理佈線,但子代理繼續正常運作。
選擇非思考模型變體。 Unknown content type thinking 錯誤來自思考塊進入代理/工具迴圈,所以不產生思考塊的模型變體完全避免它,代價是某些推理品質的損失。
也值得點讚/關注原生 Gemini 節點上的思考切換功能請求——AI Studio 選項和節點選項之間的差距是已知的,而工具呼叫 + 思考正是它造成問題的地方。
若要在 n8n 中的 Gemini Chat Model 節點停用思考功能,請透過「其他欄位」新增 Body 參數:generationConfig.thinkingConfig.thinkingBudget = 0。這會告訴 Gemini 2.5 完全跳過推理步驟,可大幅加快直接任務(查詢、簡單問答)的回應速度。
如果您的 n8n 版本在 Gemini 節點上直接公開「模型參數」,thinking_budget: 0 的功能相同。請注意,停用思考功能會降低複雜多步驟推理的品質,因此對於需要謹慎邏輯的任何工作,請保持啟用。
謝謝,但 Gemini 模型節點中沒有 body 參數選項(這就是問題所在)。以下是額外的選項: