Skip to content

Commit 967eede

Browse files
liqiang-fit2cloudliuruibin
authored andcommitted
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 "
1 parent 585302a commit 967eede

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

apps/application/flow/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import re
1313
import threading
1414
from typing import Iterator
15-
15+
from maxkb.const import CONFIG
1616
from django.http import StreamingHttpResponse
1717
from langchain_core.messages import BaseMessageChunk, BaseMessage, ToolMessage, AIMessageChunk
1818
from langchain_mcp_adapters.client import MultiServerMCPClient
@@ -313,7 +313,7 @@ async def _yield_mcp_response(chat_model, message_list, mcp_servers, mcp_output_
313313
try:
314314
client = MultiServerMCPClient(json.loads(mcp_servers))
315315
tools = await client.get_tools()
316-
agent = create_react_agent(chat_model, tools)
316+
agent = create_react_agent(chat_model, tools).configure(recursion_limit=(int(CONFIG.get("LANGCHAIN_GRAPH_RECURSION_LIMIT", '25'))))
317317
response = agent.astream({"messages": message_list}, stream_mode='messages')
318318

319319
# 用于存储工具调用信息(按 tool_id)以及按 index 聚合分片

0 commit comments

Comments
 (0)