withTool()
Wrap an async function as a traced tool
Overview
Use withTool(options, fn) to trace tool or function calls within agents. Tools represent specific capabilities that agents can invoke.
Signature
Basic Usage
Tools within an Agent
API Integration Tool
Database Query Tool
Custom Calculator Tool
Parameters
name
Tool display name for identification in the Respan dashboard
version
Version number for tracking tool iterations
associationProperties
Custom metadata to associate with the tool (inputs, configuration, etc.)
Return Value
Returns a Promise that resolves to the return value of the provided function.
Best Practices
- Use tools for specific capabilities that agents can invoke
- Name tools clearly to reflect their function
- Always nest tools within agents for proper hierarchy
- Add association properties to track tool inputs and configuration
- Tools are automatically linked to their parent agent in traces
- Tools can be reused across multiple agents