Async Jobs
Async Jobs provide a server-based approach to running recipes and agents. Jobs are submitted to an API server, persisted, and can be monitored, streamed, and cancelled. Ideal for production deployments with multiple clients.
Python API
Submitting a Job
JobHandle Methods
Waiting for Completion
Deterministic cleanup with with
JobHandle is a long-lived handle: one wait() may poll the jobs API dozens of times. It holds a lazily-constructed shared httpx.Client, so those polls share one keep-alive connection instead of doing a fresh TLS handshake per call. Use the handle as a context manager — or call close() — to release the connection pool deterministically:
Not using with? Call close() explicitly:
A 10-minute wait(poll_interval=5) uses one keep-alive HTTP connection for all ~120 polls, not one fresh TCP+TLS handshake per poll. This applies to get_status(), get_result(), cancel(), and every iteration of wait().
Using the Jobs API Directly
recipe_name and recipe_config are honoured by the router as of PR #4085; earlier versions accepted the fields but did not forward them to the executor.
If your code creates its own client to hit the Jobs API directly (rather than using submit_job), keep the client alive across calls — the wrapper’s own JobHandle does exactly this.
Starting the Jobs Server
Server Configuration
Job Status Values
queued - Job is waiting to be processed
running - Job is currently executing
succeeded - Job completed successfully
failed - Job failed with an error
cancelled - Job was cancelled
Webhooks
Configure webhooks to receive notifications when jobs complete:
Webhook payload:
Idempotency
Prevent duplicate job submissions with idempotency keys:
Idempotency Scopes
TEMPLATE.yaml Runtime Block
Configure job defaults in your recipe:
Error Handling
Best Practices
- Use idempotency keys - Prevent duplicate submissions
- Set appropriate timeouts - Match job complexity
- Configure webhooks - For async notification
- Monitor job status - Use streaming for real-time updates
- Handle failures gracefully - Implement retry logic
See Also