mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
fix: solve the infinite loop caused by 'add_memory' function when run… (#4318)
fix: solve the infinite loop caused by 'add_memory' function when run 'pause_to_reflect' function run steps: 'add_memory' -> 'pause_to_reflect' -> 'add_memory': infinite loop
This commit is contained in:
parent
aa11f7c89b
commit
b04d84f6b3
@ -44,6 +44,7 @@ class GenerativeAgentMemory(BaseMemory):
|
|||||||
relevant_memories_key: str = "relevant_memories"
|
relevant_memories_key: str = "relevant_memories"
|
||||||
relevant_memories_simple_key: str = "relevant_memories_simple"
|
relevant_memories_simple_key: str = "relevant_memories_simple"
|
||||||
most_recent_memories_key: str = "most_recent_memories"
|
most_recent_memories_key: str = "most_recent_memories"
|
||||||
|
reflecting: bool = False
|
||||||
|
|
||||||
def chain(self, prompt: PromptTemplate) -> LLMChain:
|
def chain(self, prompt: PromptTemplate) -> LLMChain:
|
||||||
return LLMChain(llm=self.llm, prompt=prompt, verbose=self.verbose)
|
return LLMChain(llm=self.llm, prompt=prompt, verbose=self.verbose)
|
||||||
@ -136,10 +137,13 @@ class GenerativeAgentMemory(BaseMemory):
|
|||||||
if (
|
if (
|
||||||
self.reflection_threshold is not None
|
self.reflection_threshold is not None
|
||||||
and self.aggregate_importance > self.reflection_threshold
|
and self.aggregate_importance > self.reflection_threshold
|
||||||
|
and not self.reflecting
|
||||||
):
|
):
|
||||||
|
self.reflecting = True
|
||||||
self.pause_to_reflect()
|
self.pause_to_reflect()
|
||||||
# Hack to clear the importance from reflection
|
# Hack to clear the importance from reflection
|
||||||
self.aggregate_importance = 0.0
|
self.aggregate_importance = 0.0
|
||||||
|
self.reflecting = False
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def fetch_memories(self, observation: str) -> List[Document]:
|
def fetch_memories(self, observation: str) -> List[Document]:
|
||||||
|
Loading…
Reference in New Issue
Block a user