Skip to content

Commit edc2259

Browse files
liuxukun2000Satan
and
Satan
authored
fix dr_science (#50)
Co-authored-by: Satan <liuxk2019@mail.sustech.edu.cn>
1 parent aa0b729 commit edc2259

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

gentopia/agent/base_agent.py

+6
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,9 @@ def _format_function_map(self) -> Dict[str, Callable]:
9191
else:
9292
function_map[plugin.name] = plugin.run
9393
return function_map
94+
95+
def clear(self):
96+
"""
97+
Clear and reset the agent.
98+
"""
99+
pass

gentopia/agent/openai/agent.py

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def run(self, instruction: str, output: Optional[BaseOutput] = None) -> AgentOut
123123
:param output: Output manager object to be used, defaults to None.
124124
:type output: Optional[BaseOutput], optional
125125
"""
126+
self.clear()
126127
if output is None:
127128
output = BaseOutput()
128129
self.message_scratchpad.append({"role": "user", "content": instruction})
@@ -209,3 +210,6 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
209210
# else:
210211
# self.message_scratchpad.append({"role": "user", "content": "Summarize what you have done and continue if you have not finished."})
211212
# self.stream(output=output)
213+
214+
def clear(self):
215+
self.message_scratchpad = self.message_scratchpad[:1]

gentopia/agent/openai_memory/agent.py

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def run(self, instruction: str, output: Optional[BaseOutput] = None) -> AgentOut
126126
:return: Output of the agent.
127127
:rtype: AgentOutput
128128
"""
129+
self.clear()
129130
if output is None:
130131
output = BaseOutput()
131132
self.memory.clear_memory_II()

gentopia/agent/react/agent.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def run(self, instruction, max_iterations=10):
148148
:return: AgentOutput object.
149149
:rtype: AgentOutput
150150
"""
151-
self.intermediate_steps.clear()
151+
self.clear()
152152
logging.info(f"Running {self.name + ':' + self.version} with instruction: {instruction}")
153153
total_cost = 0.0
154154
total_token = 0
@@ -192,7 +192,7 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
192192
:return: AgentOutput object.
193193
:rtype: AgentOutput
194194
"""
195-
self.intermediate_steps.clear()
195+
self.clear()
196196
total_cost = 0.0
197197
total_token = 0
198198
if output is None:
@@ -229,3 +229,9 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
229229
output.panel_print(result, f"[green] Function Response of [blue]{action}: ")
230230
self.intermediate_steps[-1].append(result)
231231
return AgentOutput(output=content, cost=total_cost, token_usage=total_token)
232+
233+
def clear(self):
234+
"""
235+
Clear and reset the agent.
236+
"""
237+
self.intermediate_steps.clear()

0 commit comments

Comments
 (0)