Golem Define Tool Rust

Defines and implements a typed Golem tool in Rust. Use when creating a tool provider, command schema, or callable tool component.

golemcloud Updated 1.5k repo stars

File contents

Define a Golem tool in Rust

Declare the public command surface with #[tool_definition], then implement it with #[tool_implementation]. The macro generates metadata, guest exports, and a typed client.

use golem_rust::{tool_definition, tool_implementation};

#[tool_definition(version = "1.0.0")]
pub trait Echo {
    async fn echo(&self, value: String) -> String;
}

struct EchoImpl;

#[tool_implementation]
impl Echo for EchoImpl {
    async fn echo(&self, value: String) -> String {
        value
    }
}

Use IntoSchema and FromSchema for custom inputs, outputs, and error payload types. For a declared command error in Result<T, E>, derive golem_rust::ToolError on E and annotate its variants with #[tool_error(...)]. Keep the definition and implementation in provider source; never edit macro-generated bindings. A tool component can provide tools without defining an agent.

golemcloud/golem commit 19c1febf6f

Frequently asked questions

npx get-skill add golemcloud/golem-define-tool-rust