AbstractAbstractrunQueues a callback to execute in a separate worker context with a fresh request limit.
Creates a NEW execution with its own request limit of ~1000 requests (HTTP requests, tool calls, database operations). This is the primary way to stay under request limits when processing large datasets or making many API calls.
The callback will be invoked either immediately or at a scheduled time in an isolated execution environment. Each execution has ~1000 requests and ~60 seconds CPU time. Use this for breaking loops into chunks that stay under the request limit.
Key distinction:
this.run(callback) - Continues same execution, shares request countthis.runTask(callback) - NEW execution, fresh request limitCallback created with this.callback()
Optionaloptions: { runAt?: Date }Optional configuration for the execution
OptionalrunAt?: DateIf provided, schedules execution at this time; otherwise runs immediately
Promise resolving to a cancellation token (only for scheduled executions)
AbstractcancelCancels a previously scheduled execution.
Prevents a scheduled function from executing. No error is thrown if the token is invalid or the execution has already completed.
The cancellation token returned by runTask() with runAt option
Promise that resolves when the cancellation is processed
AbstractcancelCancels all scheduled executions for this tool/twist.
Cancels all pending scheduled executions created by this tool or twist instance. Immediate executions cannot be cancelled.
Promise that resolves when all cancellations are processed
Run background tasks and scheduled jobs.
The Tasks tool enables twists and tools to queue callbacks for execution in separate worker contexts. This is critical for staying under request limits: each execution has a limit of ~1000 requests (HTTP requests, tool calls, database operations), and running a task creates a NEW execution with a fresh request limit.
Key distinction:
this.run()) continues the same execution and shares the request countthis.runTask()) creates a NEW execution with fresh ~1000 request limitWhen to use tasks:
Note: Tasks tool methods are also available directly on Twist and Tool classes via
this.runTask(),this.cancelTask(), andthis.cancelAllTasks(). This is the recommended approach for most use cases.Best Practices:
this.callback()Example