diff options
author | Reinier van der Leer <pwuts@agpt.co> | 2024-01-19 12:08:59 +0100 |
---|---|---|
committer | Reinier van der Leer <pwuts@agpt.co> | 2024-01-19 12:08:59 +0100 |
commit | c5b17851e08eb73b86fe12cbf6780f880ea14cd4 (patch) | |
tree | 6d939692a7416ba71eb0f7fdeb5e2b01b487bf10 | |
parent | feat(forge/db): Add `AgentDB.update_artifact` method (diff) | |
download | Auto-GPT-c5b17851e08eb73b86fe12cbf6780f880ea14cd4.tar.gz Auto-GPT-c5b17851e08eb73b86fe12cbf6780f880ea14cd4.tar.bz2 Auto-GPT-c5b17851e08eb73b86fe12cbf6780f880ea14cd4.zip |
fix(agent): Handle artifact modification properly
- When an Artifact's file is modified by the agent, set its `agent_created` attribute to `True` instead of registering a new Artifact
- Update the `autogpt-forge` dependency to the newest version, in which `AgentDB.update_artifact` has been implemented
-rw-r--r-- | autogpts/autogpt/autogpt/app/agent_protocol_server.py | 32 | ||||
-rw-r--r-- | autogpts/autogpt/poetry.lock | 14 | ||||
-rw-r--r-- | autogpts/autogpt/pyproject.toml | 2 |
3 files changed, 34 insertions, 14 deletions
diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.py index aeb8d8f46..7bebca930 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 action if 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.lock index bb948bff2..da4c46304 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.toml index 5d92cfac7..3edc64106 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" |