From 374e510f94ad89186412cc6b363f0216347280dc Mon Sep 17 00:00:00 2001 From: Francisco Ingham Date: Fri, 27 Jan 2023 00:47:01 -0300 Subject: [PATCH] Upper bound on number of iterations (#754) Some custom agents might continue to iterate until they find the correct answer, getting stuck on loops that generate request after request and are really expensive for the end user. Putting an upper bound for the number of iterations by default controls this and can be explicitly tweaked by the user if necessary. Co-authored-by: Francisco Ingham <> --- langchain/agents/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/langchain/agents/agent.py b/langchain/agents/agent.py index 29010663051..22e7667b6ba 100644 --- a/langchain/agents/agent.py +++ b/langchain/agents/agent.py @@ -199,7 +199,7 @@ class AgentExecutor(Chain, BaseModel): agent: Agent tools: List[Tool] return_intermediate_steps: bool = False - max_iterations: Optional[int] = None + max_iterations: Optional[int] = 15 early_stopping_method: str = "force" @classmethod