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.

Add more file abilities

SwiftyOS4de327e0e370
diff --git a/autogpts/forge/forge/sdk/abilities/file_system/files.py b/autogpts/forge/forge/sdk/abilities/file_system/files.py
index 052314d101..834955e7c7 100644
--- a/autogpts/forge/forge/sdk/abilities/file_system/files.py
+++ b/autogpts/forge/forge/sdk/abilities/file_system/files.py
@@ -12,24 +12,57 @@ from ..registry import ability
"description": "Path to the directory",
"type": "string",
"required": True,
+ }
+ ],
+ output_type="list[str]",
+)
+def list_files(agent, task_id:str, path: str) -> List[str]:
+ """
+ List files in a workspace directory
+ """
+ return agent.workspace.list(task_id=task_id, path=path)
+
+@ability(
+ name="write_file",
+ description="Write data to a file",
+ parameters=[
+ {
+ "name": "file_path",
+ "description": "Path to the file",
+ "type": "string",
+ "required": True,
},
{
- "name": "recursive",
- "description": "Recursively list files",
- "type": "boolean",
- "required": False,
+ "name": "data",
+ "description": "Data to write to the file",
+ "type": "bytes",
+ "required": True,
},
],
- output_type="list[str]",
+ output_type="None",
)
-def list_files(agent, path: str, recursive: bool = False) -> List[str]:
+def write_file(agent, task_id: str, file_path: str, data: bytes) -> None:
"""
- List files in a directory
+ Write data to a file
"""
- import glob
- import os
+ agent.workspace.write(task_id=task_id, path=file_path, data=data)
+
- if recursive:
- return glob.glob(os.path.join(path, "**"), recursive=True)
- else:
- return os.listdir(path)
+@ability(
+ name="read_file",
+ description="Read data from a file",
+ parameters=[
+ {
+ "name": "file_path",
+ "description": "Path to the file",
+ "type": "string",
+ "required": True,
+ },
+ ],
+ output_type="bytes",
+)
+def read_file(agent, task_id: str, file_path: str) -> bytes:
+ """
+ Read data from a file
+ """
+ return agent.workspace.read(task_id=task_id, path=file_path)