AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix: Serialize Exception objects in ActionErrorResult
Reinier van der Leerfc1d73ba60a4
diff --git a/autogpts/autogpt/autogpt/agents/agent.py b/autogpts/autogpt/autogpt/agents/agent.pyindex b136310526..633c3e62b9 100644--- a/autogpts/autogpt/autogpt/agents/agent.py+++ b/autogpts/autogpt/autogpt/agents/agent.py@@ -243,7 +243,7 @@ class Agent(result = ActionSuccessResult(outputs=return_value)except AgentException as e:- result = ActionErrorResult(reason=e.message, error=e)+ result = ActionErrorResult.from_exception(e)result_tlength = self.llm_provider.count_tokens(str(result), self.llm.name)if result_tlength > self.send_token_limit // 3:diff --git a/autogpts/autogpt/autogpt/agents/planning_agent.py b/autogpts/autogpt/autogpt/agents/planning_agent.pyindex f68611e31c..c59faf76e8 100644--- a/autogpts/autogpt/autogpt/agents/planning_agent.py+++ b/autogpts/autogpt/autogpt/agents/planning_agent.py@@ -276,7 +276,7 @@ class PlanningAgent(ContextMixin, FileWorkspaceMixin, BaseAgent):result = ActionSuccessResult(outputs=return_value)except AgentException as e:- result = ActionErrorResult(reason=e.message, error=e)+ result = ActionErrorResult.from_exception(e)result_tlength = count_string_tokens(str(result), self.llm.name)memory_tlength = count_string_tokens(diff --git a/autogpts/autogpt/autogpt/models/action_history.py b/autogpts/autogpt/autogpt/models/action_history.pyindex fc19cf12a6..01ab47171b 100644--- a/autogpts/autogpt/autogpt/models/action_history.py+++ b/autogpts/autogpt/autogpt/models/action_history.py@@ -26,12 +26,40 @@ class ActionSuccessResult(BaseModel):return f"```\n{self.outputs}\n```" if multiline else str(self.outputs)-# FIXME: implement validators instead of allowing arbitrary types-class ActionErrorResult(BaseModel, arbitrary_types_allowed=True):+class ErrorInfo(BaseModel):+ args: tuple+ message: str+ exception_type: str+ _repr: str++ @staticmethod+ def from_exception(exception: Exception) -> ErrorInfo:+ return ErrorInfo(+ args=exception.args,+ message=getattr(exception, "message", exception.args[0]),+ exception_type=exception.__class__.__name__,+ _repr=repr(exception),+ )++ def __str__(self):+ return repr(self)++ def __repr__(self):+ return self._repr+++class ActionErrorResult(BaseModel):reason: str- error: Optional[Exception] = None+ error: Optional[ErrorInfo] = Nonestatus: Literal["error"] = "error"+ @staticmethod+ def from_exception(exception: Exception) -> ActionErrorResult:+ return ActionErrorResult(+ reason=getattr(exception, "message", exception.args[0]),+ error=ErrorInfo.from_exception(exception),+ )+def __str__(self) -> str:return f"Action failed: '{self.reason}'"