Skip to main content

tool

Function
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)

Signature

def tool(attr: TokenStream, item: TokenStream) -> TokenStream

Parameters

attr
TokenStream
required
No description available.
item
TokenStream
required
No description available.

Returns

Returns
TokenStream
The 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

  • parser
  • is_ident
  • value
  • parse
  • error
  • name
  • unwrap_or_else
  • path
  • push_str
  • trim

Source

View on GitHub

praisonai-derive/src/lib.rs at line 46

Rust Tools

Rust Code Execution

Rust Web Search