mirror of
https://git.mirrors.martin98.com/https://github.com/bytedance/deer-flow
synced 2025-08-16 13:25:55 +08:00
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:
parent
ffe706d0df
commit
c6bbc595c3
@ -5,6 +5,8 @@ APP_ENV=development
|
|||||||
# docker build args
|
# docker build args
|
||||||
NEXT_PUBLIC_API_URL="http://localhost:8000/api"
|
NEXT_PUBLIC_API_URL="http://localhost:8000/api"
|
||||||
|
|
||||||
|
AGENT_RECURSION_LIMIT=30
|
||||||
|
|
||||||
# Search Engine, Supported values: tavily (recommended), duckduckgo, brave_search, arxiv
|
# Search Engine, Supported values: tavily (recommended), duckduckgo, brave_search, arxiv
|
||||||
SEARCH_API=tavily
|
SEARCH_API=tavily
|
||||||
TAVILY_API_KEY=tvly-xxx
|
TAVILY_API_KEY=tvly-xxx
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
from typing import Annotated, Literal
|
from typing import Annotated, Literal
|
||||||
|
|
||||||
from langchain_core.messages import AIMessage, HumanMessage
|
from langchain_core.messages import AIMessage, HumanMessage
|
||||||
@ -350,7 +351,31 @@ async def _execute_agent_step(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Invoke the agent
|
# 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
|
# Process the result
|
||||||
response_content = result["messages"][-1].content
|
response_content = result["messages"][-1].content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user