agent-runtime-control-tools 0.1.1

Internal Runtime-owned control tools
Documentation
//! Generic Runtime-owned control tools.

use async_trait::async_trait;
use runtime_extension_api::{
    ExtensionError, SideEffect, Tool, ToolContext, ToolDescriptor, ToolOutcome,
};
use serde_json::{Value, json};

pub struct CompleteTool;

#[async_trait]
impl Tool for CompleteTool {
    fn descriptor(&self) -> ToolDescriptor {
        ToolDescriptor {
            name: "runtime.complete".into(),
            description: "Finish the execution and return the final answer to the caller.".into(),
            input_schema: json!({
                "type":"object",
                "properties":{"answer":{"type":"string","minLength":1}},
                "required":["answer"],
                "additionalProperties":false
            }),
            required_capabilities: Vec::new(),
            side_effect: SideEffect::ReadOnly,
        }
    }

    async fn invoke(
        &self,
        _: ToolContext,
        arguments: Value,
    ) -> Result<ToolOutcome, ExtensionError> {
        let answer = arguments
            .get("answer")
            .and_then(Value::as_str)
            .ok_or_else(|| ExtensionError::Invalid("answer is required".into()))?;
        Ok(ToolOutcome::complete(answer))
    }
}