From 040c6bcd8c98cc771fc43ab02d31cfbf1875352a Mon Sep 17 00:00:00 2001 From: SwiftyOS Date: Thu, 21 Sep 2023 15:21:58 +0200 Subject: [PATCH] Added log messages for task and step creation --- autogpts/forge/forge/agent.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/autogpts/forge/forge/agent.py b/autogpts/forge/forge/agent.py index d220fa14..89a24889 100644 --- a/autogpts/forge/forge/agent.py +++ b/autogpts/forge/forge/agent.py @@ -1,4 +1,6 @@ -from forge.sdk import Agent, AgentDB, Step, StepRequestBody, Workspace +from forge.sdk import Agent, AgentDB, Step, StepRequestBody, Workspace, ForgeLogger, Task, TaskRequestBody + +LOG = ForgeLogger(__name__) class ForgeAgent(Agent): @@ -62,6 +64,19 @@ class ForgeAgent(Agent): Feel free to create subclasses of the database and workspace to implement your own storage """ super().__init__(database, workspace) + + async def create_task(self, task_request: TaskRequestBody) -> Task: + """ + The agent protocol, which is the core of the Forge, works by creating a task and then + executing steps for that task. This method is called when the agent is asked to create + a task. + + We are hooking into function to add a custom log message. Though you can do anything you + want here. + """ + task = await super().create_task(task_request) + LOG.info(f"📦 Task created: {task.task_id} input: {task.input[:40]}{'...' if len(task.input) > 40 else ''}") + return task async def execute_step(self, task_id: str, step_request: StepRequestBody) -> Step: """ @@ -88,12 +103,17 @@ class ForgeAgent(Agent): multiple steps. Returning a request to continue in the step output, the user can then decide if they want the agent to continue or not. """ - # An example that self.workspace.write(task_id=task_id, path="output.txt", data=b"Washington D.C") step = await self.db.create_step( task_id=task_id, input=step_request, is_last=True ) + message = f'\t🔄 Step executed: {step.step_id} input: {step.input[:19]}' + if step.is_last: + message = f'\t✅ Final Step completed: {step.step_id} input: {step.input[:19]}' + + LOG.info(message) + artifact = await self.db.create_artifact( task_id=task_id, step_id=step.step_id,