Skip to content

Commit 72acf14

Browse files
committed
fix : force process_step as abstractmethod in base class
1 parent 16bdf75 commit 72acf14

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

mesa_llm/memory/episodic_memory.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,14 @@ def get_communication_history(self) -> str:
131131
if "message" in entry.content
132132
]
133133
)
134+
135+
def process_step(self, pre_step: bool = False):
136+
"""
137+
Process the step of the agent :
138+
- Add the new entry to the memory
139+
- Display the new entry
140+
"""
141+
if pre_step:
142+
self.add_to_memory(type="observation", content=self.step_content)
143+
self.step_content = {}
144+
return

mesa_llm/memory/memory.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ def get_communication_history(self) -> str:
111111
Get the communication history in a format that can be used for reasoning
112112
"""
113113

114+
@abstractmethod
115+
def process_step(self, pre_step: bool = False):
116+
r"""
117+
A function that is called before and after the step of the agent is called.
118+
It is implemented to ensure that the memory is up to date when the agent is starting a new step.
119+
120+
/!\ If you consider that you do not need this function, you can write "pass" in its implementation.
121+
"""
122+
114123
def add_to_memory(self, type: str, content: dict):
115124
"""
116125
Add a new entry to the memory

mesa_llm/memory/st_lt_memory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ def process_step(self, pre_step: bool = False):
101101
return
102102

103103
elif not self.short_term_memory[-1].content.get("step", None):
104-
pre_step = self.short_term_memory.pop()
105-
self.step_content.update(pre_step.content)
106-
new_entry = MemoryEntry(
104+
pre_step_entry = self.short_term_memory.pop()
105+
self.step_content.update(pre_step_entry.content)
106+
new_st_entry = MemoryEntry(
107107
agent=self.agent,
108108
content=self.step_content,
109109
step=self.agent.model.steps,
110110
)
111111

112-
self.short_term_memory.append(new_entry)
112+
self.short_term_memory.append(new_st_entry)
113113
self.step_content = {}
114114

115115
# Consolidate memory if the short term memory is over capacity

0 commit comments

Comments
 (0)