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

OPEN-165: Improvement - check for duplicate command #6937

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
8 changes: 8 additions & 0 deletions autogpts/autogpt/autogpt/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
AgentException,
AgentTerminated,
CommandExecutionError,
DuplicateOperationError,
UnknownCommandError,
)

Expand Down Expand Up @@ -186,6 +187,13 @@ def parse_and_process_response(
assistant_reply_dict,
) = self.prompt_strategy.parse_response_content(llm_response)

# Check if command_name and arguments are already in the event_history
if self.event_history.matches_last_command(command_name, arguments):
raise DuplicateOperationError(
f"The command {command_name} with arguments {arguments} "
f"has been just executed."
)

self.log_cycle_handler.log_cycle(
self.ai_profile.ai_name,
self.created_at,
Expand Down
10 changes: 10 additions & 0 deletions autogpts/autogpt/autogpt/models/action_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from autogpt.prompts.utils import format_numbered_list, indent

if TYPE_CHECKING:
from autogpt.agents.base import CommandArgs, CommandName
from autogpt.config.config import Config
from autogpt.core.resource.model_providers import ChatModelProvider

Expand Down Expand Up @@ -159,6 +160,15 @@ def register_result(self, result: ActionResult) -> None:
self.current_episode.result = result
self.cursor = len(self.episodes)

def matches_last_command(
self, command_name: CommandName, arguments: CommandArgs
) -> bool:
"""Check if the last command matches the given name and arguments."""
if len(self.episodes) > 0:
last_command = self.episodes[-1].action
return last_command.name == command_name and last_command.args == arguments
return False

def rewind(self, number_of_episodes: int = 0) -> None:
"""Resets the history to an earlier state.

Expand Down
Loading