abu_agent/toolbox/tools/
fs.rs1#[abu_macros::tool(
2 struct_name = FileCreator,
3 description = "Create a new file",
4)]
5pub fn create_file(filepath: &str) -> std::io::Result<()> {
6 match std::fs::File::create(filepath) {
7 Ok(_) => Ok(()),
8 Err(err) => Err(err.into()),
9 }
10}
11
12#[abu_macros::tool(
13 struct_name = FileWriter,
14 description =
15r#"Write content to file.
16If the file already exists, the original content will be overwritten directly."#,
17)]
18pub fn write_file(filepath: &str, content: &str) -> std::io::Result<()> {
19 std::fs::write(filepath, content)
20}
21
22#[abu_macros::tool(
23 struct_name = FileReader,
24 description = "Read file and return its content",
25)]
26pub fn read_file(filepath: &str) -> std::io::Result<String> {
27 std::fs::read_to_string(filepath)
28}