forked from VRSEN/agency-swarm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ReadRequirements tool to genesis agency
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
agency_swarm/agency/genesis/GenesisCEO/tools/ReadRequirements.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from agency_swarm.tools import BaseTool | ||
from pydantic import Field | ||
import os | ||
|
||
|
||
class ReadRequirements(BaseTool): | ||
""" | ||
Use this tool to read the agency requirements if user provides them as a file. | ||
""" | ||
|
||
file_path: str = Field( | ||
..., description="The path to the file that needs to be read." | ||
) | ||
|
||
def run(self): | ||
""" | ||
Checks if the file exists, and if so, opens the specified file, reads its contents, and returns them. | ||
If the file does not exist, raises a ValueError. | ||
""" | ||
if not os.path.exists(self.file_path): | ||
raise ValueError(f"File path does not exist: {self.file_path}") | ||
|
||
try: | ||
with open(self.file_path, 'r', encoding='utf-8') as file: | ||
content = file.read() | ||
return content | ||
except Exception as e: | ||
return f"An error occurred while reading the file: {str(e)}" |