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(agent): Handle artifact modification properly
Reinier van der Leerc5b17851e08e
diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.pyindex aeb8d8f46f..7bebca930a 100644--- a/autogpts/autogpt/autogpt/app/agent_protocol_server.py+++ b/autogpts/autogpt/autogpt/app/agent_protocol_server.py@@ -213,12 +213,8 @@ class AgentProtocolServer:# Execute previously proposed actionif execute_command:assert execute_command_args is not None- agent.workspace.on_write_file = lambda path: self.db.create_artifact(- task_id=step.task_id,- step_id=step.step_id,- file_name=path.parts[-1],- agent_created=True,- relative_path=str(path),+ agent.workspace.on_write_file = lambda path: self._on_agent_write_file(+ task=task, step=step, relative_path=path)if step.is_last and execute_command == finish.__name__:@@ -317,6 +313,30 @@ class AgentProtocolServer:agent.state.save_to_json_file(agent.file_manager.state_file_path)return step+ async def _on_agent_write_file(+ self, task: Task, step: Step, relative_path: pathlib.Path+ ) -> None:+ """+ Creates an Artifact for the written file, or updates the Artifact if it exists.+ """+ if relative_path.is_absolute():+ raise ValueError(f"File path '{relative_path}' is not relative")+ for a in task.artifacts or []:+ if a.relative_path == str(relative_path):+ logger.debug(f"Updating Artifact after writing to existing file: {a}")+ if not a.agent_created:+ await self.db.update_artifact(a.artifact_id, agent_created=True)+ break+ else:+ logger.debug(f"Creating Artifact for new file '{relative_path}'")+ await self.db.create_artifact(+ task_id=step.task_id,+ step_id=step.step_id,+ file_name=relative_path.parts[-1],+ agent_created=True,+ relative_path=str(relative_path),+ )+async def get_step(self, task_id: str, step_id: str) -> Step:"""Get a step by ID.diff --git a/autogpts/autogpt/poetry.lock b/autogpts/autogpt/poetry.lockindex bb948bff27..da4c46304d 100644--- a/autogpts/autogpt/poetry.lock+++ b/autogpts/autogpt/poetry.lock@@ -345,8 +345,8 @@ benchmark = ["agbenchmark @ git+https://github.com/Significant-Gravitas/AutoGPT.[package.source]type = "git"url = "https://github.com/Significant-Gravitas/AutoGPT.git"-reference = "HEAD"-resolved_reference = "39fd1d6be1979875c077ef575051867f105dcb18"+reference = "b238aba"+resolved_reference = "b238abac52a4f945325603d433b7eade5bb92d2a"subdirectory = "autogpts/forge"[[package]]@@ -2083,12 +2083,12 @@ files = [google-auth = ">=2.14.1,<3.0.dev0"googleapis-common-protos = ">=1.56.2,<2.0.dev0"grpcio = [- {version = ">=1.33.2,<2.0dev", optional = true, markers = "python_version < \"3.11\" and extra == \"grpc\""},{version = ">=1.49.1,<2.0dev", optional = true, markers = "python_version >= \"3.11\" and extra == \"grpc\""},+ {version = ">=1.33.2,<2.0dev", optional = true, markers = "python_version < \"3.11\" and extra == \"grpc\""},]grpcio-status = [- {version = ">=1.33.2,<2.0.dev0", optional = true, markers = "python_version < \"3.11\" and extra == \"grpc\""},{version = ">=1.49.1,<2.0.dev0", optional = true, markers = "python_version >= \"3.11\" and extra == \"grpc\""},+ {version = ">=1.33.2,<2.0.dev0", optional = true, markers = "python_version < \"3.11\" and extra == \"grpc\""},]protobuf = ">=3.19.5,<3.20.0 || >3.20.0,<3.20.1 || >3.20.1,<4.21.0 || >4.21.0,<4.21.1 || >4.21.1,<4.21.2 || >4.21.2,<4.21.3 || >4.21.3,<4.21.4 || >4.21.4,<4.21.5 || >4.21.5,<5.0.0.dev0"requests = ">=2.18.0,<3.0.0.dev0"@@ -2221,8 +2221,8 @@ google-cloud-audit-log = ">=0.1.0,<1.0.0dev"google-cloud-core = ">=2.0.0,<3.0.0dev"grpc-google-iam-v1 = ">=0.12.4,<1.0.0dev"proto-plus = [- {version = ">=1.22.0,<2.0.0dev", markers = "python_version < \"3.11\""},{version = ">=1.22.2,<2.0.0dev", markers = "python_version >= \"3.11\""},+ {version = ">=1.22.0,<2.0.0dev", markers = "python_version < \"3.11\""},]protobuf = ">=3.19.5,<3.20.0 || >3.20.0,<3.20.1 || >3.20.1,<4.21.0 || >4.21.0,<4.21.1 || >4.21.1,<4.21.2 || >4.21.2,<4.21.3 || >4.21.3,<4.21.4 || >4.21.4,<4.21.5 || >4.21.5,<5.0.0dev"@@ -4233,9 +4233,9 @@ files = [[package.dependencies]numpy = [- {version = ">=1.22.4,<2", markers = "python_version < \"3.11\""},{version = ">=1.23.2,<2", markers = "python_version == \"3.11\""},{version = ">=1.26.0,<2", markers = "python_version >= \"3.12\""},+ {version = ">=1.22.4,<2", markers = "python_version < \"3.11\""},]python-dateutil = ">=2.8.2"pytz = ">=2020.1"@@ -7191,4 +7191,4 @@ benchmark = ["agbenchmark"][metadata]lock-version = "2.0"python-versions = "^3.10"-content-hash = "e57e40785a96af53fd3977536b7bf2a912073c24034449ec45c95234738f134a"+content-hash = "aab84eef0d990d25803675669e775d18cd7801cd03bd0f72f3a92859d24db68b"diff --git a/autogpts/autogpt/pyproject.toml b/autogpts/autogpt/pyproject.tomlindex 5d92cfac73..3edc641061 100644--- a/autogpts/autogpt/pyproject.toml+++ b/autogpts/autogpt/pyproject.toml@@ -24,7 +24,7 @@ serve = "autogpt.app.cli:serve"python = "^3.10"auto-gpt-plugin-template = {git = "https://github.com/Significant-Gravitas/Auto-GPT-Plugin-Template", rev = "0.1.0"}# autogpt-forge = { path = "../forge" }-autogpt-forge = {git = "https://github.com/Significant-Gravitas/AutoGPT.git", subdirectory = "autogpts/forge"}+autogpt-forge = {git = "https://github.com/Significant-Gravitas/AutoGPT.git", rev = "b238aba", subdirectory = "autogpts/forge"}beautifulsoup4 = "^4.12.2"boto3 = "^1.33.6"charset-normalizer = "^3.1.0"