diff --git a/autogpt/agent.py b/autogpt/agent.py index 99c001df..2b5a1424 100644 --- a/autogpt/agent.py +++ b/autogpt/agent.py @@ -88,4 +88,19 @@ class AutoGPTAgent(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. """ - raise NotImplementedError + + # 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 + ) + artifact = await self.db.create_artifact( + task_id=task_id, + step_id=step.step_id, + file_name="output.txt", + relative_path="", + agent_created=True, + ) + step.output = "Washington D.C" + + return step diff --git a/autogpt/sdk/agent.py b/autogpt/sdk/agent.py index b2c66e5f..2ca3378b 100644 --- a/autogpt/sdk/agent.py +++ b/autogpt/sdk/agent.py @@ -2,7 +2,7 @@ import asyncio import os from uuid import uuid4 -from fastapi import APIRouter, FastAPI, Response, UploadFile +from fastapi import APIRouter, FastAPI, UploadFile from fastapi.responses import FileResponse from hypercorn.asyncio import serve from hypercorn.config import Config @@ -116,10 +116,8 @@ class Agent: artifacts, pagination = await self.db.list_artifacts( task_id, page, pageSize ) - response = TaskArtifactsListResponse( - artifacts=artifacts, pagination=pagination - ) - return Response(content=response.json(), media_type="application/json") + return TaskArtifactsListResponse(artifacts=artifacts, pagination=pagination) + except Exception as e: raise diff --git a/autogpt/sdk/db.py b/autogpt/sdk/db.py index eec35002..bf5eeb05 100644 --- a/autogpt/sdk/db.py +++ b/autogpt/sdk/db.py @@ -218,7 +218,11 @@ class AgentDB: with self.Session() as session: if ( existing_artifact := session.query(ArtifactModel) - .filter_by(relative_path=relative_path) + .filter_by( + task_id=task_id, + file_name=file_name, + relative_path=relative_path, + ) .first() ): session.close() diff --git a/autogpt/sdk/routes/agent_protocol.py b/autogpt/sdk/routes/agent_protocol.py index 153239b5..ced59908 100644 --- a/autogpt/sdk/routes/agent_protocol.py +++ b/autogpt/sdk/routes/agent_protocol.py @@ -324,7 +324,7 @@ async def list_agent_task_steps( @base_router.post("/agent/tasks/{task_id}/steps", tags=["agent"], response_model=Step) async def execute_agent_task_step( - request: Request, task_id: str, step: StepRequestBody + request: Request, task_id: str, step: Optional[StepRequestBody] = None ) -> Step: """ Executes the next step for a specified task based on the current task status and returns the @@ -367,6 +367,9 @@ async def execute_agent_task_step( """ agent = request["agent"] try: + # An empty step request represents a yes to continue command + if not step: + step = StepRequestBody(input="y") step = await agent.execute_step(task_id, step) return Response( content=step.json(), @@ -479,7 +482,10 @@ async def list_agent_task_artifacts( """ agent = request["agent"] try: - artifacts = await agent.list_artifacts(task_id, page, page_size) + artifacts: TaskArtifactsListResponse = await agent.list_artifacts( + task_id, page, page_size + ) + LOG.info(f"Artifacts: {artifacts.json()}") return artifacts except NotFoundError: LOG.exception("Error whilst trying to list artifacts") @@ -501,7 +507,7 @@ async def list_agent_task_artifacts( "/agent/tasks/{task_id}/artifacts", tags=["agent"], response_model=Artifact ) async def upload_agent_task_artifacts( - request: Request, task_id: str, file: UploadFile, relative_path: str + request: Request, task_id: str, file: UploadFile, relative_path: Optional[str] = "" ) -> Artifact: """ This endpoint is used to upload an artifact associated with a specific task. The artifact is provided as a file.