|
|
ADK with Cloud Tasks for Deferred Execution
Author: Venkata Sudhakar
Some agent tasks are too slow to run inline with a user request - generating a 50-page report, processing a large data export, or running a multi-step pipeline. Cloud Tasks lets you enqueue these jobs and execute them asynchronously on a Cloud Run worker. ShopMax India uses Cloud Tasks to generate monthly sales analysis reports without blocking the dashboard UI. The pattern: the main application enqueues a task with the job parameters, Cloud Tasks delivers it to a Cloud Run handler after an optional delay, and the worker runs the ADK agent and stores the result. The client polls or receives a notification when the job completes. The below example shows how ShopMax India enqueues a report generation task and processes it asynchronously with an ADK agent.
The Cloud Run worker that processes the task with an ADK agent,
It gives the following output,
Task enqueued: projects/shopmax-india/locations/asia-south1/queues/report-jobs/tasks/12345
# Worker logs when task executes:
Processing report job: Mumbai / 2024-10
Agent generated report: 847 words
Report saved to GCS: reports/Mumbai/2024-10.txt
Notification sent to: [email protected]
Cloud Tasks automatically retries failed tasks with exponential backoff. Set max_attempts to 3 and max_retry_duration to 24 hours for report jobs. Use the task name as a deduplication key to prevent duplicate reports if the same job is accidentally enqueued twice.
|
|