Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dr_science #50

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gentopia/agent/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ def _format_function_map(self) -> Dict[str, Callable]:
else:
function_map[plugin.name] = plugin.run
return function_map

def clear(self):
"""
Clear and reset the agent.
"""
pass
4 changes: 4 additions & 0 deletions gentopia/agent/openai/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def run(self, instruction: str, output: Optional[BaseOutput] = None) -> AgentOut
:param output: Output manager object to be used, defaults to None.
:type output: Optional[BaseOutput], optional
"""
self.clear()
if output is None:
output = BaseOutput()
self.message_scratchpad.append({"role": "user", "content": instruction})
Expand Down Expand Up @@ -209,3 +210,6 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
# else:
# self.message_scratchpad.append({"role": "user", "content": "Summarize what you have done and continue if you have not finished."})
# self.stream(output=output)

def clear(self):
self.message_scratchpad = self.message_scratchpad[:1]
1 change: 1 addition & 0 deletions gentopia/agent/openai_memory/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def run(self, instruction: str, output: Optional[BaseOutput] = None) -> AgentOut
:return: Output of the agent.
:rtype: AgentOutput
"""
self.clear()
if output is None:
output = BaseOutput()
self.memory.clear_memory_II()
Expand Down
10 changes: 8 additions & 2 deletions gentopia/agent/react/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def run(self, instruction, max_iterations=10):
:return: AgentOutput object.
:rtype: AgentOutput
"""
self.intermediate_steps.clear()
self.clear()
logging.info(f"Running {self.name + ':' + self.version} with instruction: {instruction}")
total_cost = 0.0
total_token = 0
Expand Down Expand Up @@ -192,7 +192,7 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
:return: AgentOutput object.
:rtype: AgentOutput
"""
self.intermediate_steps.clear()
self.clear()
total_cost = 0.0
total_token = 0
if output is None:
Expand Down Expand Up @@ -229,3 +229,9 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
output.panel_print(result, f"[green] Function Response of [blue]{action}: ")
self.intermediate_steps[-1].append(result)
return AgentOutput(output=content, cost=total_cost, token_usage=total_token)

def clear(self):
"""
Clear and reset the agent.
"""
self.intermediate_steps.clear()