tool

Attribute Macro tool 

Source
#[tool]
Expand description

Turn an async fn into a registrable Gemini tool.

The attribute takes a single string literal — the tool’s description, as surfaced to the model:

#[tool("Get the current weather for a city")]
async fn get_weather(city: String, units: Option<String>) -> Result<Value, ToolError> {
    Ok(json!({ "city": city, "units": units.unwrap_or("metric".into()) }))
}

§What it generates

For a function fn foo(...), the macro emits:

  • A hidden args struct __FooArgs deriving serde::Deserialize and schemars::JsonSchema, with one field per parameter. This drives both argument deserialization and JSON-Schema generation.
  • A hidden tool type __FooTool implementing gemini_adk_rs::tool::ToolFunction:
    • name() returns the function name ("foo").
    • description() returns the attribute string.
    • parameters() returns the schemars-generated JSON Schema.
    • call(args) deserializes args into __FooArgs, runs the original function body, and returns its Result<Value, ToolError>.
  • A public constructor fn foo() -> __FooTool (visibility matches the original fn) that you register with a gemini_adk_rs::tool::ToolDispatcher:
dispatcher.register_function(std::sync::Arc::new(foo()));

§Supported parameters

Any parameter type that is serde::Deserialize + schemars::JsonSchema is supported. Option<T> parameters are optional in the schema. Zero-parameter tools are supported (the generated schema is an empty object).

§Path hygiene

Generated code references serde, schemars, serde_json, async_trait, and gemini_adk_rs via absolute (::-rooted) paths in your crate graph. Consumers of gemini-adk-rs already have all of these as dependencies, so no extra setup is required.

§Follow-ups (not yet supported)

  • Per-parameter doc descriptions are not extracted into the schema in v1. Function parameters cannot carry doc comments in Rust, so this would require a #[doc = "..."]-style attribute on each param.