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(agent): Handle action_history-related exceptions gracefully #6990

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
14 changes: 13 additions & 1 deletion autogpts/autogpt/autogpt/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
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__)
Expand Down Expand Up @@ -173,6 +177,14 @@ def __init__(
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
Expand Down
16 changes: 10 additions & 6 deletions autogpts/autogpt/autogpt/app/agent_protocol_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,16 @@ async def execute_step(self, task_id: str, step_request: StepRequestBody) -> Ste
"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,
}
)
),
},
}
Expand Down
8 changes: 3 additions & 5 deletions autogpts/autogpt/autogpt/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading