> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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

<div className="flex items-center gap-2">
  <Badge color="teal">Function</Badge>
</div>

> This function is defined in the [**praisonai\_derive**](../modules/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)

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
%%{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:#fff
```

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def tool(attr: TokenStream, item: TokenStream) -> TokenStream
```

## Parameters

<ParamField query="attr" type="TokenStream" required={true}>
  No description available.
</ParamField>

<ParamField query="item" type="TokenStream" required={true}>
  No description available.
</ParamField>

### Returns

<ResponseField name="Returns" type="TokenStream">
  The result of the operation.
</ResponseField>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai-derive/src/lib.rs#L46">
  `praisonai-derive/src/lib.rs` at line 46
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Rust Tools" icon="wrench" href="/docs/rust/tools" />

  <Card title="Rust Code Execution" icon="terminal" href="/docs/rust/code-execution" />

  <Card title="Rust Web Search" icon="search" href="/docs/rust/web-search" />
</CardGroup>
