For agent tasks that take 30+ seconds (multi-step research, document processing, code generation with verification), async execution is the right shape. User initiates; backend works; user receives notification or polls for status. Beats synchronous wait + timeout risks.
Pattern: client POSTs task; receives task_id + estimated time; backend executes async; client polls /status/{{id}} or receives webhook on completion. UI: progress indicators, in-progress notifications, ability to navigate away. Standard distributed-systems pattern; particularly important for AI given variable execution time.
Pattern
- Client POSTs task to
/tasks - Server returns
{ task_id, status: "running", estimated_time: 60 } - Server executes task async (worker queue)
- Client polls
/tasks/{id}every 5 seconds OR receives webhook - Status transitions: queued → running → completed / failed
- On complete: result available at
/tasks/{id}
UX
- Progress indicator while in-progress (sub-step granularity if available)
- Estimated time remaining
- Allow user to navigate away; return to status later
- Push notification on completion (browser / email / app)
- Result preserved for ~7-30 days
Verdict
For long-running agent tasks, async execution is the right pattern. Better UX than synchronous wait; doesn't depend on connection survival; integrates with notifications. Standard pattern; AI-specific because task time varies more than typical web request.
Bottom line
Async for >30-second agent tasks. See event-driven.