> ## 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.

# Wrap Tool Call • AI Agent SDK

> wrap_tool_call: Decorator to mark a function as a wrap_tool_call middleware.

# wrap\_tool\_call

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

> This function is defined in the [**middleware**](../modules/middleware) module.

Decorator to mark a function as a wrap\_tool\_call middleware.

The function receives (request, call\_next) and should call call\_next(request)
to continue the chain, or return early to short-circuit.

```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: wrap_tool_call"]
    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 wrap_tool_call(func: WrapToolCallFn) -> WrapToolCallFn
```

## Parameters

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

### Returns

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

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
@wrap_tool_call
    def retry_flaky_tool(request, call_next):
        last_error = None
        for _ in range(3):
            try:
                return call_next(request)
            except Exception as e:
                last_error = e
        raise last_error
```

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/hooks/middleware.py#L272">
  `praisonaiagents/hooks/middleware.py` at line 272
</Card>

***

## Related Documentation

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

  <Card title="Create Custom Tools" icon="plus" href="/docs/guides/tools/create-custom-tools" />

  <Card title="Tool Development" icon="code" href="/docs/tutorials/advanced-tool-development" />
</CardGroup>
