Skip to content

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.

Changed abilities to async

SwiftyOS01f68601d3a6
diff --git a/autogpts/forge/forge/sdk/abilities/file_system/files.py b/autogpts/forge/forge/sdk/abilities/file_system/files.py
index 834955e7c7..6584471c87 100644
--- a/autogpts/forge/forge/sdk/abilities/file_system/files.py
+++ b/autogpts/forge/forge/sdk/abilities/file_system/files.py
@@ -16,7 +16,7 @@ from ..registry import ability
],
output_type="list[str]",
)
-def list_files(agent, task_id:str, path: str) -> List[str]:
+async def list_files(agent, task_id:str, path: str) -> List[str]:
"""
List files in a workspace directory
"""
@@ -41,11 +41,15 @@ def list_files(agent, task_id:str, path: str) -> List[str]:
],
output_type="None",
)
-def write_file(agent, task_id: str, file_path: str, data: bytes) -> None:
+async def write_file(agent, task_id: str, file_path: str, data: bytes) -> None:
"""
Write data to a file
"""
+ if isinstance(data, str):
+ data = data.encode()
+
agent.workspace.write(task_id=task_id, path=file_path, data=data)
+ await agent.db.create_artifact(task_id=task_id, file_name=file_path.split('/')[-1], relative_path=file_path, agent_created=True)
@ability(
@@ -61,7 +65,7 @@ def write_file(agent, task_id: str, file_path: str, data: bytes) -> None:
],
output_type="bytes",
)
-def read_file(agent, task_id: str, file_path: str) -> bytes:
+async def read_file(agent, task_id: str, file_path: str) -> bytes:
"""
Read data from a file
"""
diff --git a/autogpts/forge/forge/sdk/abilities/finish.py b/autogpts/forge/forge/sdk/abilities/finish.py
index aa36778634..a0424bdd16 100644
--- a/autogpts/forge/forge/sdk/abilities/finish.py
+++ b/autogpts/forge/forge/sdk/abilities/finish.py
@@ -18,7 +18,7 @@ logger = ForgeLogger(__name__)
],
output_type="None"
)
-def finish(agent, task_id: str, reason: str,) -> str:
+async def finish(agent, task_id: str, reason: str,) -> str:
"""
A function that takes in a string and exits the program
diff --git a/autogpts/forge/forge/sdk/abilities/registry.py b/autogpts/forge/forge/sdk/abilities/registry.py
index 0290c116a7..1c0b84cec2 100644
--- a/autogpts/forge/forge/sdk/abilities/registry.py
+++ b/autogpts/forge/forge/sdk/abilities/registry.py
@@ -80,6 +80,7 @@ def ability(
[AbilityParameter.parse_obj(param).name for param in parameters]
)
param_names.add("agent")
+ param_names.add("task_id")
func_param_names = set(func_params.keys())
if param_names != func_param_names:
raise ValueError(
@@ -104,7 +105,6 @@ class AbilityRegister:
self.agent = agent
def register_abilities(self) -> None:
- print(os.path.join(os.path.dirname(__file__), "*.py"))
for ability_path in glob.glob(
os.path.join(os.path.dirname(__file__), "**/*.py"), recursive=True
):
@@ -117,7 +117,7 @@ class AbilityRegister:
).replace("/", ".")
try:
module = importlib.import_module(
- f".{ability[:-3]}", package="autogpt.sdk.abilities"
+ f".{ability[:-3]}", package="forge.sdk.abilities"
)
for attr in dir(module):
func = getattr(module, attr)
@@ -156,7 +156,7 @@ class AbilityRegister:
return abilities_description
- def run_ability(self, task_id: str, ability_name: str, *args: Any, **kwds: Any) -> Any:
+ async def run_ability(self, task_id: str, ability_name: str, *args: Any, **kwds: Any) -> Any:
"""
This method runs a specified ability with the provided arguments and keyword arguments.
@@ -177,7 +177,7 @@ class AbilityRegister:
"""
try:
ability = self.abilities[ability_name]
- return ability(self.agent, task_id, *args, **kwds)
+ return await ability(self.agent, task_id, *args, **kwds)
except Exception:
raise