withWorkflow()
Wrap an async function as a traced workflow
Overview
Use withWorkflow(options, fn) to mark an end-to-end run. All nested tasks, agents, and tools are captured under this workflow.
Signature
Basic Usage
With Association Properties
Nested Tasks
Parameters
name
Workflow display name for identification in the Respan dashboard
version
Version number for tracking workflow iterations
associationProperties
Custom metadata to associate with the workflow (user ID, session ID, etc.)
Return Value
Returns a Promise that resolves to the return value of the provided function.
Best Practices
- Use descriptive workflow names for easy navigation in the dashboard
- Keep workflows coarse-grained; use tasks for internal steps
- Add association properties for filtering and grouping in analytics
- Always call
initialize()before usingwithWorkflow()