Prerequisites
- Django 4.1+ (for async view support if you use
agent.do_async()) - A Django project already created, or follow the steps below to create one
Setup
Create the agent view and URL
In In
agent_api/views.py:agent_api/views.py
agent_api/urls.py (create the file):agent_api/urls.py
Step 2: Docker
For production, replace Add Gunicorn as a dependency:
manage.py runserver with Gunicorn:uv add gunicorn.Async view with agent.do_async()
Django 4.1+ supports async views. Use agent.do_async() so the worker is not blocked during LLM calls.
agent_api/views.py
agent_api/urls.py:
Using with Django auth and DB
You can use the request user and DB in the same view before or after calling the agent.agent_api/views.py
agent_api/models.py), running migrations, and saving after agent.do() or agent.do_async().
Key takeaways
- Use sync views with
agent.do(task)when you rely onrunserveror a WSGI server. - Use async views with
await agent.do_async(task)and an ASGI server for better concurrency. - Combine with Django auth, ORM, and admin when you need user management and persistence.

