-
Notifications
You must be signed in to change notification settings - Fork 44.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement watchdog feature for dynamic switching between smart & fast…
… LLMs
- Loading branch information
Showing
7 changed files
with
96 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from contextlib import ExitStack | ||
|
||
from autogpt.models.agent_actions import ActionHistory | ||
|
||
from ..base import BaseAgent | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class WatchdogMixin: | ||
""" | ||
Mixin that adds a watchdog feature to an agent class. Whenever the agent starts | ||
looping, the watchdog will switch from the FAST_LLM to the SMART_LLM and re-think. | ||
""" | ||
|
||
event_history: ActionHistory | ||
|
||
def __init__(self, **kwargs) -> None: | ||
# Initialize other bases first, because we need the event_history from BaseAgent | ||
super(WatchdogMixin, self).__init__(**kwargs) | ||
|
||
if not isinstance(self, BaseAgent): | ||
raise NotImplementedError( | ||
f"{__class__.__name__} can only be applied to BaseAgent derivatives" | ||
) | ||
|
||
def think(self, *args, **kwargs) -> BaseAgent.ThoughtProcessOutput: | ||
command_name, command_args, thoughts = super(WatchdogMixin, self).think( | ||
*args, **kwargs | ||
) | ||
|
||
if not self.big_brain and len(self.event_history) > 1: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Pwuts
Author
Member
|
||
# Detect repetitive commands | ||
previous_cycle = self.event_history.cycles[self.event_history.cursor - 1] | ||
if ( | ||
command_name == previous_cycle.action.name | ||
and command_args == previous_cycle.action.args | ||
): | ||
logger.info( | ||
f"Repetitive command detected ({command_name}), re-thinking with SMART_LLM..." | ||
) | ||
with ExitStack() as stack: | ||
|
||
@stack.callback | ||
def restore_state() -> None: | ||
# Executed after exiting the ExitStack context | ||
self.big_brain = False | ||
|
||
# Remove partial record of current cycle | ||
self.event_history.rewind() | ||
|
||
# Switch to SMART_LLM and re-think | ||
self.big_brain = True | ||
return self.think(*args, **kwargs) | ||
|
||
return command_name, command_args, thoughts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi pwuts, am I missing something or is this much simpler than the originally proposed patch which was literally hashing all/most agent state ? I am only seeing command + params being taken into account here ? How would this work inside a valid situation, such as looping or re-trying some action that previously failed ?