Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

2.2 KB
Raw Blame
//! LLM-callable wrappers over the `health` domain. Read-only, default-ON.

use async_trait::async_trait;
use serde_json::json;

use tinytools::{Tool, ToolResult};

use super::ops;

/// Component health snapshot.
pub struct HealthSnapshotTool;

#[async_trait]
impl Tool for HealthSnapshotTool {
    fn exposure(&self) -> tinytools::ToolExposure {
        tinytools::ToolExposure::Deferred
    }

    fn name(&self) -> &str {
        "health_snapshot"
    }

    fn description(&self) -> &str {
        "Return a snapshot of core component health (subsystem readiness flags). \
         Use for a quick liveness/readiness check of the running core."
    }

    fn parameters_schema(&self) -> serde_json::Value {
        json!({ "type": "object", "properties": {} })
    }

    async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {
        log::debug!("[tool][health] snapshot invoked");
        let outcome = ops::health_snapshot();
        Ok(ToolResult::success(serde_json::to_string(&outcome.value)?))
    }

    fn is_concurrency_safe(&self, _args: &serde_json::Value) -> bool {
        true
    }
}

/// Version / OS / arch / pid.
pub struct HealthSystemInfoTool;

#[async_trait]
impl Tool for HealthSystemInfoTool {
    fn exposure(&self) -> tinytools::ToolExposure {
        tinytools::ToolExposure::Deferred
    }

    fn name(&self) -> &str {
        "health_system_info"
    }

    fn description(&self) -> &str {
        "Return basic system info for the running core: version, OS, arch, and \
         process id."
    }

    fn parameters_schema(&self) -> serde_json::Value {
        json!({ "type": "object", "properties": {} })
    }

    async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {
        log::debug!("[tool][health] system_info invoked");
        let outcome = ops::system_info();
        Ok(ToolResult::success(serde_json::to_string(&outcome.value)?))
    }

    fn is_concurrency_safe(&self, _args: &serde_json::Value) -> bool {
        true
    }
}

/// Build this domain's tools in their persisted catalogue order.
pub(crate) fn registered_tools() -> Vec<Box<dyn tinytools::Tool>> {
    vec![Box::new(HealthSnapshotTool), Box::new(HealthSystemInfoTool)]
}

#[cfg(test)]
#[path = "tools_tests.rs"]
mod tests;