Agent unable to save code files to local environment
chiranjeeviga opened this issue · comments
I created an agency with coding/developer capabilities. I asked it to write code for a web portal to upload files. Agency CEO finally confirms that the task is successful and the web portal development is complete, but I don't see any files nor a localhost URL to test. Can the agents via agency be able to create/save code files? like html, css and js locally to my machine?
Yes, but you have to create a tool for this. Here is an example:
import os
from agency_swarm.tools import BaseTool
from pydantic import Field
class FileWriter(BaseTool):
"""Allows you to write new files or modify existing files."""
chain_of_thought: str = Field(
..., description="Please think step-by-step about what needs to be written to the file in order for the program to match the requirements.",
exclude=True,
)
file_path: str = Field(
..., description="The path of the file to write or modify. Will create directories if they don't exist."
)
content: str = Field(
..., description="The full content of the file to write. Content must not be truncated and must represent a correct "
"functioning program with all the imports defined."
)
def run(self):
try:
# create directories if they don't exist
dir_path = os.path.dirname(self.file_path)
os.makedirs(dir_path, exist_ok=True)
with open(self.file_path, 'w') as file:
file.write(self.content)
return f'Successfully wrote to file: {self.file_path}.'
except Exception as e:
return f'Error writing to file: {e}'
thanks @VRSEN
I copied the CodingAgent.py to the newly created agency codeAgent.py and it solved the issue of writing files.
Learning the framework bit by bit now and understanding the importance of tools that are written and given access to each agent.
Closing this