tiny-agent 0.1.0

一个小而完整的 Rust LLM Agent 运行时:可中断、可恢复、可观测、可插拔的 agent loop / A small but complete LLM agent runtime in Rust — an interruptible, resumable, observable, pluggable agent loop.
Documentation
use super::sh_quote;
use crate::{sandbox::Sandbox, tools::ToolOutcome};
use schemars::JsonSchema;
use serde::Deserialize;
use serde_json::json;
use std::sync::Arc;

#[derive(Deserialize, JsonSchema)]
pub struct ReadFileArgs {
    /// 要读取的文件路径
    pub path: String,
}

pub async fn read_file(
    sandbox: Arc<dyn Sandbox>,
    args: ReadFileArgs,
) -> Result<ToolOutcome, String> {
    let cmd = format!("cat -- {}", sh_quote(&args.path));
    let out = sandbox.execute(&cmd).await.map_err(|e| e.to_string())?;
    if !out.is_success() {
        return Err(format!("读取文件失败: {}", out.stderr.trim()));
    }
    Ok(json!({ "content": out.stdout }).into())
}