tiny-agent 0.3.0

一个小而完整的 Rust LLM Agent 运行时:可中断、可恢复、可观测、可插拔的 agent loop / A small but complete LLM agent runtime in Rust — an interruptible, resumable, observable, pluggable agent loop.
Documentation
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ToolDefinition {
    pub name: String,
    pub desc: String,
    pub arguments: serde_json::Value,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Message {
    pub role: Role,
    pub blocks: Vec<ContentBlock>,
}

impl Message {
    pub fn text(role: Role, text: impl Into<String>) -> Self {
        Self {
            role,
            blocks: vec![ContentBlock::Text { text: text.into() }],
        }
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ContentBlock {
    Text {
        text: String,
    },
    Thinking {
        text: String,
    },
    ToolUse {
        id: String,
        name: String,
        input: serde_json::Value,
    },
    ToolResult {
        tool_use_id: String,
        content: Vec<ContentBlock>,
        is_error: bool,
    },
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Role {
    User,
    Assistant,
    Tool,
    System,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ToolCall {
    pub call_id: String,
    pub tool_name: String,
    pub arguments: Value,
}

/// 工具向 runtime 声明"需要用户交互"时携带的最小协议。
///
/// 这类请求会作为合法 `tool_result` 写入 transcript,同时进入
/// `Agent::WaitingForUser` checkpoint,方便 UI 在用户下次回来时恢复展示。
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct UserInteraction {
    pub kind: String,
    pub payload: Value,
}