tool • Rust AI Agent SDK
tool: The `#[tool]` attribute macro for defining tools. This macro transforms a function into a tool that can be used by agents. # Attributes -…
tool
Function
</div>
This function is defined in the praisonai_derive module.
The #[tool] attribute macro for defining tools. This macro transforms a function into a tool that can be used by agents. # Attributes – description: A description of what the tool does (required for LLM understanding) – name: Override the tool name (defaults to function name)
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8B0000', 'primaryTextColor': '#fff', 'primaryBorderColor': '#710101', 'lineColor': '#189AB4', 'secondaryColor': '#189AB4', 'tertiaryColor': '#fff' }}}%%
graph LR
agent["Agent"] -- "uses" --> tool["Tool: tool"]
tool -- "returns" --> result["Result"]
style tool fill:#189AB4,color:#fff
style agent fill:#8B0000,color:#fff
style result fill:#8B0000,color:#fffSignature
def tool(attr: TokenStream, item: TokenStream) -> TokenStreamParameters
ParamField
TokenStreamNo description available.
ParamField
TokenStreamNo description available.
Returns
ResponseField
TokenStreamThe result of the operation.
Usage
use praisonai::tool;
#[tool(description = "Search the web")]
async fn search(query: String) -> String {
format!("Results for: {}", query)
}
// With custom name
#[tool(name = "web_search", description = "Search the internet")]
async fn my_search_fn(query: String, max_results: u32) -> Vec<String> {
vec![format!("Result for: {}", query)]
}Uses
parseris_identvalueparseerrornameunwrap_or_elsepathpush_strtrim
Source
View on GitHubpraisonai-derive/src/lib.rs at line 46