Skip to content

Commit

Permalink
refactor: make file_read tool framework-agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
1 parent e99eaa1 commit 9933cad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
32 changes: 32 additions & 0 deletions agentstack/tools/file_read/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Framework-agnostic implementation of file reading functionality.
"""
from typing import Optional
from pathlib import Path


def read_file(file_path: str) -> str:
"""Read contents of a file at the given path.
Args:
file_path: Path to the file to read
Returns:
str: The contents of the file as a string
Raises:
FileNotFoundError: If the file does not exist
PermissionError: If the file cannot be accessed
Exception: For other file reading errors
"""
try:
path = Path(file_path).resolve()
if not path.exists():
return f"Error: File not found at path {file_path}"
if not path.is_file():
return f"Error: Path {file_path} is not a file"

with open(path, "r", encoding="utf-8") as file:
return file.read()
except (FileNotFoundError, PermissionError, Exception) as e:
return f"Failed to read file {file_path}. Error: {str(e)}"
8 changes: 5 additions & 3 deletions agentstack/tools/file_read/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "file_read",
"url": "https://github.com/crewAIInc/crewAI-tools/tree/main/crewai_tools/tools/file_read_tool",
"category": "computer-control",
"tools": ["file_read_tool"]
}
"tools": ["read_file"],
"description": "Read contents of files",
"url": "https://github.com/AgentOps-AI/AgentStack/tree/main/agentstack/tools/file_read",
"dependencies": []
}
3 changes: 0 additions & 3 deletions agentstack/tools/file_read/crewai.py

This file was deleted.

0 comments on commit 9933cad

Please sign in to comment.