WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@liqiang-fit2cloud
Copy link
Member

…"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 "

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

…"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 "
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 12, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 12, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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 聚合分片
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks generally structured correctly but has a few areas where improvements can be made:

  1. Imports: The maxkb.const module is imported, which suggests that you have a custom module named const.py. Ensure this file exists and contains the necessary configuration variables.

  2. Tool Configuration: In the _yield_mcp_response function, there's an attempt to configure the reaction agent with a maximum recursion limit fetched from the CONFIG dictionary using CONFIG.get("LANGCHAIN_GRAPH_RECURSION_LIMIT", '25'). Make sure that "LANGCHAIN_GRAPH_RECURSION_LIMIT" exists in your CONFIG settings or default it appropriately if not set.

  3. Code Comments: Add comments describing what each section of the code does, especially around the recursive limiting logic and how the response is being streamed.

  4. Error Handling: Consider adding more detailed error handling to manage cases such as failed tool retrieval from MCP servers or issues during streaming.

Here’s a revised version of the key part of your code with these suggestions:

import re
import threading
from typing import Iterator

# Import your CONFIG constants from the appropriate module
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

async def _yield_mcp_response(chat_model, message_list, mcp_servers, mcp_output_queue):
    try:
        # Initialize theMulti Server Management Console (MCP) client
        client = MultiServerMCPClient(json.loads(mcp_servers))

        # Fetch available tools from the MCP servers
        tools = await client.get_tools()

        // Create a reaction agent with specific configurations
        # Set recursion limit based on the configuration
       agent = create_react_agent(
            chat_model,
            tools,
            config={
                "RECURSION_LIMIT": int(CONFIG.get("LANGCHAIN_GRAPH_RECURSION_LIMIT", '25'))
            }
        )

        # Stream responses from the agent
        response = agent.astream(
            {
                "messages": message_list,
                "stream_mode": 'messages'
            },
            stream_mode='message_chunks'  # Adjust mode as needed for better performance
        )
        
        # Process each chunk received from the streaming generator
        async for content in response.stream():
            if isinstance(content, BaseMessageChunk):
                yield StreamingHttpResponse(chunk_to_bytes(content.content), status=200)

This revision ensures clarity about the purpose of variable assignments, provides adequate comments explaining critical parts of the code, and includes default values and logging that could help diagnose problems when running the application.

@liuruibin
Copy link
Member

do not merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants