mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-02-05 06:14:23 +01:00
feat(agent/logging): Log warning when action raises error
- Add logging to capture errors raised during execution of actions in the Agent - Move `fmt_kwargs` function from `agent_protocol_server.py` to `logs/utils.py`
This commit is contained in:
@@ -26,6 +26,7 @@ from autogpt.logs.log_cycle import (
|
||||
USER_INPUT_FILE_NAME,
|
||||
LogCycleHandler,
|
||||
)
|
||||
from autogpt.logs.utils import fmt_kwargs
|
||||
from autogpt.models.action_history import (
|
||||
Action,
|
||||
ActionErrorResult,
|
||||
@@ -254,6 +255,9 @@ class Agent(
|
||||
raise
|
||||
except AgentException as e:
|
||||
result = ActionErrorResult.from_exception(e)
|
||||
logger.warning(
|
||||
f"{command_name}({fmt_kwargs(command_args)}) raised an error: {e}"
|
||||
)
|
||||
|
||||
result_tlength = self.llm_provider.count_tokens(str(result), self.llm.name)
|
||||
if result_tlength > self.send_token_limit // 3:
|
||||
|
||||
@@ -39,6 +39,7 @@ from autogpt.file_workspace import (
|
||||
FileWorkspaceBackendName,
|
||||
get_workspace,
|
||||
)
|
||||
from autogpt.logs.utils import fmt_kwargs
|
||||
from autogpt.models.action_history import ActionErrorResult, ActionSuccessResult
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -428,7 +429,3 @@ class AgentProtocolServer:
|
||||
|
||||
def task_agent_id(task_id: str | int) -> str:
|
||||
return f"AutoGPT-{task_id}"
|
||||
|
||||
|
||||
def fmt_kwargs(kwargs: dict) -> str:
|
||||
return ", ".join(f"{n}={repr(v)}" for n, v in kwargs.items())
|
||||
|
||||
@@ -3,3 +3,7 @@ import re
|
||||
|
||||
def remove_color_codes(s: str) -> str:
|
||||
return re.sub(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])", "", s)
|
||||
|
||||
|
||||
def fmt_kwargs(kwargs: dict) -> str:
|
||||
return ", ".join(f"{n}={repr(v)}" for n, v in kwargs.items())
|
||||
|
||||
Reference in New Issue
Block a user