Skip to content

The agent engineering platform.

Strip trailing whitespaces in agent's stop sequences (#1566)

Ryan Daoa95028720694
diff --git a/langchain/agents/agent.py b/langchain/agents/agent.py
index 095e736539..01bc233a5e 100644
--- a/langchain/agents/agent.py
+++ b/langchain/agents/agent.py
@@ -47,7 +47,10 @@ class Agent(BaseModel):
@property
def _stop(self) -> List[str]:
- return [f"\n{self.observation_prefix}", f"\n\t{self.observation_prefix}"]
+ return [
+ f"\n{self.observation_prefix.rstrip()}",
+ f"\n\t{self.observation_prefix.rstrip()}",
+ ]
def _construct_scratchpad(
self, intermediate_steps: List[Tuple[AgentAction, str]]