rho-coding-agent 3.12.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! The `report_to_starter` tool of a session that reports to the session
//! that started it (see `app::starter_report`).

use std::sync::Arc;

use rho_sdk::tool::{
    OperationKind, Tool as SdkTool, ToolContext as SdkToolContext, ToolError as SdkToolError,
    ToolErrorKind, ToolFuture, ToolInvocation, ToolMetadata, ToolOutput, ToolSecurity,
};

use crate::app::starter_report::{ReportKind, StarterReport};

pub(crate) const TOOL_NAME: &str = "report_to_starter";

/// The tool for a session whose reports go to `report`'s starter.
pub(crate) fn report_to_starter_bundle(
    report: StarterReport,
) -> super::sdk_registry::StaticToolBundle {
    super::sdk_registry::StaticToolBundle::new(vec![Arc::new(ReportToStarter { report })])
}

struct ReportToStarter {
    report: StarterReport,
}

impl SdkTool for ReportToStarter {
    fn spec(&self) -> rho_sdk::model::ToolSpec {
        rho_sdk::model::ToolSpec {
            name: TOOL_NAME.into(),
            description: "Report to the session that started you. Your turns tell it nothing unless you call this: call it once your whole task is done (done), when you can't go on without a decision it or a person must make (needs_decision), or when something you can't fix stops you (blocked). Your final message of this turn is the report it reads, so write it after this call, then end your turn. Don't report progress.".into(),
            input_schema: serde_json::json!({
                "type": "object",
                "properties": {
                    "kind": {
                        "type": "string",
                        "enum": ReportKind::ALL.map(ReportKind::as_str),
                        "description": "What the report says of your task"
                    }
                },
                "required": ["kind"],
                "additionalProperties": false
            }),
        }
    }

    fn security(&self) -> ToolSecurity {
        ToolSecurity::built_in([])
    }

    fn call<'a>(&'a self, invocation: ToolInvocation, _context: SdkToolContext) -> ToolFuture<'a> {
        Box::pin(async move {
            let mut arguments = invocation.into_arguments();
            let kind =
                serde_json::from_value::<ReportKind>(arguments["kind"].take()).map_err(|_| {
                    SdkToolError::new(
                        ToolErrorKind::InvalidArguments,
                        "kind must be done, needs_decision or blocked",
                    )
                })?;
            self.report.mark(kind);
            Ok(ToolOutput::text(format!(
                "Reported {}. Write your report as your final message, then end your turn.",
                kind.as_str()
            ))
            .metadata(ToolMetadata::new().operation(OperationKind::Other(TOOL_NAME.into()))))
        })
    }
}