Overview
Some APIs return anasync_result_id. While this is useful if you want to continue the workflow while it is running, sometimes you want to wait for the operation to complete. This is where the suspend_fn method comes in.
Suspending a Workflow
To suspend a workflow, you can use thectx.suspend_fn method within a Step function. This will suspend the workflow until a resume event is received.
The standard way to trigger a resume event when a async_result_id is ready is to use the resume_when_complete method.
reasoning_sync) will be called when the workflow is resumed, and the resume data will be passed via the ctx.resume_data property (in this case, the result from the async_result_id).
Suspend Payloads
The payload passed toctx.suspend_fn is stored with the suspended task and is
useful for observability (for example, recording which async_result_id the
step is waiting on). Except for payloads with "type": "screen" (see below),
the platform does not interpret the payload — you can use any JSON-serializable
shape that helps you debug suspended runs.
Resume Priority
Resumes are processed from a queue. By default they run at background priority, which is appropriate for scheduled and bulk workflows. When a user is actively waiting on the result — for example, watching a loading screen — passpriority: "interactive" so the resume is processed sooner:
If your SDK version does not accept
priority as a keyword argument, pass it
via extra_body as shown above.Showing a Loading Screen
While waiting for async results to complete, you can show a loading screen to provide visual feedback to users. To display a loading screen, callctx.suspend_fn with a screen payload before the function returns:
- You must call
suspend_fnbefore the function returns to ensure the loading screen is displayed - Any props passed in the
propsparameter will be passed to the React component atscreenPathas props - This allows you to pass necessary metadata (such as the
async_result_idor task descriptions) that the loading screen can use to provide more detailed feedback
screenPath while the workflow is suspended, providing a better user experience during long-running operations.
Delays and Scheduled Resumes
Sometimes you want a workflow to wait for a period of time rather than for an external operation — for example, to retry a check the next day or to follow up on a request after a waiting period. Thesleep endpoint
returns an async_result_id that completes after the given delay, so you can
use the same suspend and resume pattern as any other async result.
sleep accepts either of the following parameters:
- delay: Time to wait in milliseconds.
- resume_at: An ISO 8601 timestamp to resume at, e.g.
(datetime.now(timezone.utc) + timedelta(days=7)).isoformat().