withTask()
Wrap an async function as a traced task
Overview
Use withTask(options, fn) to mark a discrete step within a workflow. Tasks are automatically linked to their parent workflow or agent.
Signature
Basic Usage
With Metadata
Within a Workflow
Error Handling
Parameters
name
Task display name for identification in the Respan dashboard
version
Version number for tracking task iterations
associationProperties
Custom metadata to associate with the task
Return Value
Returns a Promise that resolves to the return value of the provided function.
Best Practices
- Use tasks for discrete, measurable operations within workflows
- Name tasks clearly to reflect their purpose
- Nest tasks within workflows or agents for proper hierarchy
- Tasks automatically capture timing and error information