Fix :This PR can resolve the issue of exceeding the default tool invocation limit by setting the recursion limit through an environment variable.mit (#138)

* set ecursion limit

* set ecursion limit

* fix:check if the recession_limit within a reasonalbe range

* style: format code with black
This commit is contained in:
changqingla 2025-05-18 11:37:03 +08:00 committed by GitHub
parent ffe706d0df
commit c6bbc595c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -5,6 +5,8 @@ APP_ENV=development
# docker build args
NEXT_PUBLIC_API_URL="http://localhost:8000/api"
AGENT_RECURSION_LIMIT=30
# Search Engine, Supported values: tavily (recommended), duckduckgo, brave_search, arxiv
SEARCH_API=tavily
TAVILY_API_KEY=tvly-xxx

View File

@ -3,6 +3,7 @@
import json
import logging
import os
from typing import Annotated, Literal
from langchain_core.messages import AIMessage, HumanMessage
@ -350,7 +351,31 @@ async def _execute_agent_step(
)
# Invoke the agent
result = await agent.ainvoke(input=agent_input)
default_recursion_limit = 25
try:
env_value_str = os.getenv("AGENT_RECURSION_LIMIT", str(default_recursion_limit))
parsed_limit = int(env_value_str)
if parsed_limit > 0:
recursion_limit = parsed_limit
logger.info(f"Recursion limit set to: {recursion_limit}")
else:
logger.warning(
f"AGENT_RECURSION_LIMIT value '{env_value_str}' (parsed as {parsed_limit}) is not positive. "
f"Using default value {default_recursion_limit}."
)
recursion_limit = default_recursion_limit
except ValueError:
raw_env_value = os.getenv("AGENT_RECURSION_LIMIT")
logger.warning(
f"Invalid AGENT_RECURSION_LIMIT value: '{raw_env_value}'. "
f"Using default value {default_recursion_limit}."
)
recursion_limit = default_recursion_limit
result = await agent.ainvoke(
input=agent_input, config={"recursion_limit": recursion_limit}
)
# Process the result
response_content = result["messages"][-1].content