From b971275bad4edad4752487f299ad8421a631065d Mon Sep 17 00:00:00 2001 From: liqiang-fit2cloud Date: Fri, 12 Dec 2025 18:47:46 +0800 Subject: [PATCH] refactor: add LANGCHAIN_GRAPH_RECURSION_LIMIT env to avoid the error "GraphRecursionError: Recursion limit of 25 reached without hitting a stop condition. You can increase the limit by setting the recursion_limit config key. For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/GRAPH_RECURSION_LIMIT " --- apps/application/flow/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/application/flow/tools.py b/apps/application/flow/tools.py index d9d0235837e..6463848f2db 100644 --- a/apps/application/flow/tools.py +++ b/apps/application/flow/tools.py @@ -12,7 +12,7 @@ import re import threading from typing import Iterator - +from maxkb.const import CONFIG from django.http import StreamingHttpResponse from langchain_core.messages import BaseMessageChunk, BaseMessage, ToolMessage, AIMessageChunk from langchain_mcp_adapters.client import MultiServerMCPClient @@ -313,7 +313,7 @@ async def _yield_mcp_response(chat_model, message_list, mcp_servers, mcp_output_ try: client = MultiServerMCPClient(json.loads(mcp_servers)) tools = await client.get_tools() - agent = create_react_agent(chat_model, tools) + agent = create_react_agent(chat_model, tools).configure(recursion_limit=(int(CONFIG.get("LANGCHAIN_GRAPH_RECURSION_LIMIT", '25')))) response = agent.astream({"messages": message_list}, stream_mode='messages') # 用于存储工具调用信息(按 tool_id)以及按 index 聚合分片