mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-10 07:38:04 -05:00
fix(agent): Handle action_history-related exceptions gracefully (#6990)
Fix resume-related exceptions - CLI: prevent resumed agent to register action on already existing one - Server: prevent trying to json() command without result
This commit is contained in:
committed by
GitHub
parent
89cf0154f4
commit
fd2c26188f
@@ -40,7 +40,11 @@ from autogpt.core.resource.model_providers.openai import (
|
||||
from autogpt.core.runner.client_lib.logging.helpers import dump_prompt
|
||||
from autogpt.file_storage.base import FileStorage
|
||||
from autogpt.llm.providers.openai import get_openai_command_specs
|
||||
from autogpt.models.action_history import ActionResult, EpisodicActionHistory
|
||||
from autogpt.models.action_history import (
|
||||
ActionResult,
|
||||
ActionSuccessResult,
|
||||
EpisodicActionHistory,
|
||||
)
|
||||
from autogpt.prompts.prompt import DEFAULT_TRIGGERING_PROMPT
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -173,6 +177,14 @@ class BaseAgent(Configurable[BaseAgentSettings], ABC):
|
||||
self.legacy_config = legacy_config
|
||||
"""LEGACY: Monolithic application configuration."""
|
||||
|
||||
# In case the agent is resumed, cursor is set to the last episode
|
||||
if self.event_history:
|
||||
# To prevent errors, when the last action is "finish", we register a result
|
||||
# And move cursor to the next action
|
||||
if self.event_history.current_episode.action.name == "finish":
|
||||
self.event_history.register_result(ActionSuccessResult())
|
||||
self.event_history.cursor = len(self.event_history)
|
||||
|
||||
self.llm_provider = llm_provider
|
||||
|
||||
self.prompt_strategy = prompt_strategy
|
||||
|
||||
@@ -311,12 +311,16 @@ class AgentProtocolServer:
|
||||
"name": execute_command,
|
||||
"args": execute_command_args,
|
||||
"result": (
|
||||
orjson.loads(execute_result.json())
|
||||
if not isinstance(execute_result, ActionErrorResult)
|
||||
else {
|
||||
"error": str(execute_result.error),
|
||||
"reason": execute_result.reason,
|
||||
}
|
||||
""
|
||||
if execute_result is None
|
||||
else (
|
||||
orjson.loads(execute_result.json())
|
||||
if not isinstance(execute_result, ActionErrorResult)
|
||||
else {
|
||||
"error": str(execute_result.error),
|
||||
"reason": execute_result.reason,
|
||||
}
|
||||
)
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -190,16 +190,14 @@ async def run_auto_gpt(
|
||||
# Resume an Existing Agent #
|
||||
############################
|
||||
if load_existing_agent:
|
||||
agent_state = agent_manager.load_agent_state(load_existing_agent)
|
||||
agent_state = None
|
||||
while True:
|
||||
answer = await clean_input(config, "Resume? [Y/n]")
|
||||
if answer.lower() == "y":
|
||||
if answer == "" or answer.lower() == "y":
|
||||
agent_state = agent_manager.load_agent_state(load_existing_agent)
|
||||
break
|
||||
elif answer.lower() == "n":
|
||||
agent_state = None
|
||||
break
|
||||
else:
|
||||
print("Please respond with 'y' or 'n'")
|
||||
|
||||
if agent_state:
|
||||
agent = configure_agent_with_state(
|
||||
|
||||
Reference in New Issue
Block a user