Skip to content

Commit

Permalink
feat(agent/logging): Log warning when action raises error
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
Pwuts committed Dec 14, 2023
1 parent 167fea3 commit efb5fed
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions autogpts/autogpt/autogpt/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
USER_INPUT_FILE_NAME,
LogCycleHandler,
)
from autogpt.logs.utils import fmt_kwargs
from autogpt.models.action_history import (
Action,
ActionErrorResult,
Expand Down Expand Up @@ -254,6 +255,9 @@ async def execute(
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:
Expand Down
5 changes: 1 addition & 4 deletions autogpts/autogpt/autogpt/app/agent_protocol_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
FileWorkspaceBackendName,
get_workspace,
)
from autogpt.logs.utils import fmt_kwargs
from autogpt.models.action_history import ActionErrorResult, ActionSuccessResult

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -428,7 +429,3 @@ def _get_task_llm_provider(

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())
4 changes: 4 additions & 0 deletions autogpts/autogpt/autogpt/logs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

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())

0 comments on commit efb5fed

Please sign in to comment.