mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 22:14:28 +01:00
feat(agent): Catch & disallow duplicate commands in LLM response parser (#6937)
Raise in `parse_and_process_response` if the proposed operation is the same as the last executed one.
This commit is contained in:
committed by
GitHub
parent
5047fd9fce
commit
2c96f6125f
@@ -50,6 +50,7 @@ from .utils.exceptions import (
|
|||||||
AgentException,
|
AgentException,
|
||||||
AgentTerminated,
|
AgentTerminated,
|
||||||
CommandExecutionError,
|
CommandExecutionError,
|
||||||
|
DuplicateOperationError,
|
||||||
UnknownCommandError,
|
UnknownCommandError,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -186,6 +187,13 @@ class Agent(
|
|||||||
assistant_reply_dict,
|
assistant_reply_dict,
|
||||||
) = self.prompt_strategy.parse_response_content(llm_response)
|
) = 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.log_cycle_handler.log_cycle(
|
||||||
self.ai_profile.ai_name,
|
self.ai_profile.ai_name,
|
||||||
self.created_at,
|
self.created_at,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from autogpt.processing.text import summarize_text
|
|||||||
from autogpt.prompts.utils import format_numbered_list, indent
|
from autogpt.prompts.utils import format_numbered_list, indent
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from autogpt.agents.base import CommandArgs, CommandName
|
||||||
from autogpt.config.config import Config
|
from autogpt.config.config import Config
|
||||||
from autogpt.core.resource.model_providers import ChatModelProvider
|
from autogpt.core.resource.model_providers import ChatModelProvider
|
||||||
|
|
||||||
@@ -159,6 +160,15 @@ class EpisodicActionHistory(BaseModel):
|
|||||||
self.current_episode.result = result
|
self.current_episode.result = result
|
||||||
self.cursor = len(self.episodes)
|
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:
|
def rewind(self, number_of_episodes: int = 0) -> None:
|
||||||
"""Resets the history to an earlier state.
|
"""Resets the history to an earlier state.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user