AI Background Jobs with Django, Celery, and React | Reliable Agent Workflows

Learn how to build reliable AI agent workflows using Django, Celery, and React with background jobs, progress tracking, retries, and production guardrails.

Published: July 17, 2026

Category: AI

AI products are moving beyond one-shot chat boxes. Teams now want assistants that read documents, call internal tools, summarize CRM activity, draft emails, and keep working even when the browser tab closes. That shift has made background AI jobs one of the most practical trends for Django and React teams in 2026. For Gsoft Technologies clients, the question is no longer “Can we add an LLM?” It is “Can this AI workflow run safely, recover from failures, show progress, and fit our existing software stack?” Django, Celery, and React are a strong answer. Why AI Agents Need a Job Queue LLM calls are slower and less predictable than normal CRUD operations. A useful agent may need to retrieve context, call multiple APIs, validate outputs, and retry when a model or network request fails. Running all of that inside a single web request creates timeouts, duplicate work, and a poor user experience. A background queue separates the user action from the long-running workflow. Django accepts the request, creates an AIJob record, sends work to Celery, and returns a job ID immediately. React can then show a live status screen instead of a frozen submit button. A Simple Django and Celery Pattern Start by modeling each AI workflow as a first-class object. This gives your application auditability, progress tracking, and a clean place to store model outputs. # models.py class AIJob(models.Model): STATUS = [("queued", "Queued"), ("running", "Running"), ("done", "Done"), ("failed", "Failed")] user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) status = models.CharField(max_length=20, choices=STATUS, default="queued") progress = models.PositiveIntegerField(default=0) prompt = models.TextField() result = models.JSONField(null=True, blank=True) error = models.TextField(blank=True) created_at = models.DateTimeField(auto_now_add=True) The Celery task becomes the orchestrator. It can update progress after retrieval, tool execution, model generation, and validation. # tasks.py @app.task(bind=True, max_retries=3) def run_ai_job(self, job_id): job = AIJob.objects.get(id=job_id) job.status = "running"; job.progress = 10; job.save(update_fields=["status", "progress"]) context = retrieve_company_context(job.prompt) job.progress = 45; job.save(update_fields=["progress"]) answer = call_llm_with_tools(prompt=job.prompt, context=context) job.result = {"answer": answer} job.status = "done"; job.progress = 100 job.save(update_fields=["result", "status", "progress"]) React UX: Progress Beats Waiting On the frontend, the best AI experience is transparent. After creating a job, React can poll an endpoint every few seconds or subscribe through WebSockets/SSE for real-time updates. The interface should show the current stage, allow users to leave and return, and clearly display failures with a retry option. useEffect(() => { const timer = setInterval(async () => { const res = await fetch('/api/ai-jobs/' + jobId + '/'); setJob(await res.json()); }, 2000); return () => clearInterval(timer); }, [jobId]); This pattern is especially valuable for document analysis, RAG reports, content generation, lead enrichment, invoice processing, and internal operations copilots. Production Guardrails Matter Reliable AI background jobs need more than a queue. Add idempotency keys to avoid duplicate charges, store prompts and outputs for review, limit concurrency per user, and log model cost per task. For sensitive workflows, add a human approval step before an agent sends email, updates a database, or triggers a payment-related action. It is also smart to separate quick AI features from heavy workflows. A small autocomplete can run synchronously, while multi-step agents should run through Celery workers with monitoring and alerts. Build AI That Works Like Software The future of AI in business applications is not just smarter prompts. It is dependable architecture: queues, retries, observability, permissions, and great UX. Django, Celery, and React give teams a pro

Back to Blog | Home | Services | Contact Us