Skip to content

Commit

Permalink
Fixed lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewaucie committed Dec 3, 2024
1 parent 0b516ff commit 4feb9e5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions libs/core/tests/integration_tests/test_react_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from langchain.tools import Tool
from langchain.llms.openai import OpenAI


class TestReActAgentIntegration(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down
6 changes: 2 additions & 4 deletions libs/langchain/langchain/agents/react/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@ def parse(self, text: str):
if "iteration limit exceeded" in text.lower():
return {"error": "Agent terminated due to iteration limit."}

# Detect repetitive reasoning or circular loops
reasoning_history = getattr(self, "_reasoning_history", [])
if text in reasoning_history:
raise ValueError("Detected repetitive reasoning. Terminating.")

reasoning_history.append(text)

# Keep last 3 outputs

setattr(self, "_reasoning_history", reasoning_history[-3:])

return super().parse(text)
Expand Down

0 comments on commit 4feb9e5

Please sign in to comment.