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
1
Initialize the project with uv
2
Create a Django project and app
3
Register the app
Add
"agent_api" to INSTALLED_APPS in myproject/settings.py.4
Configure URLs
In
myproject/urls.py, include the app URLs:myproject/urls.py
5
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
6
Run the server
http://localhost:8000/api/ask/?query=HelloStep 2: Docker
1
Create a `.dockerignore` file
.dockerignore
2
Create a `Dockerfile`
Dockerfile
3
Build and run the image
4
Access the app
Call the agent:
http://localhost:8000/api/ask/?query=HelloFor 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.

