Skip to content

Installation

pip install django-ag-ui

Core dependencies are django>=4.2 and pydantic-ai-slim[ag-ui]>=1.0. The AG-UI wire types and the AGUIAdapter come from the pydantic-ai-slim[ag-ui] extra; this package does not re-implement them. The slim package ships the AG-UI adapter and wire types but no model-provider library — pick one via a provider extra (see below).

Compatibility

Component Floor Tested
Python 3.10 3.10, 3.11, 3.12, 3.13, 3.14
Django 4.2 LTS 4.2, 5.0, 5.1, 5.2, 6.0
Pydantic-AI 1.0 (with the pydantic-ai-slim[ag-ui] extra) latest in the CI matrix

Model provider extras

Because pydantic-ai-slim ships no provider library, install the one matching your model via a django-ag-ui provider extra:

pip install "django-ag-ui[anthropic]"   # or [openai], or [google]

Each maps to the corresponding pydantic-ai-slim provider extra:

Extra Pulls in
django-ag-ui[anthropic] pydantic-ai-slim[anthropic]
django-ag-ui[openai] pydantic-ai-slim[openai]
django-ag-ui[google] pydantic-ai-slim[google]

When you set API_KEY or PROVIDER so the model is built with an explicit key, the MODEL string's provider: prefix may be any provider Pydantic-AI knows (anthropic, openai, openai-responses, google, google-gla, groq, bedrock, …) — resolution is delegated to Pydantic-AI, so the list tracks whatever your installed version supports. A bare model name it can map to a provider (e.g. claude-…) works too. When the provider can't be resolved, the view raises ImproperlyConfigured (set PROVIDER to a Provider instance instead). Install the matching provider extra for whichever you use.

ASGI is required

DjangoAGUIView is an async view that returns a StreamingHttpResponse of Server-Sent Events. AG-UI's SSE streaming needs an event loop, which the synchronous WSGI worker does not provide. Deploy under an ASGI server such as Uvicorn or Daphne and point it at your project's asgi.py:

uvicorn myproject.asgi:application

The view marks itself as a coroutine function (via asgiref.sync.markcoroutinefunction) so Django's request handler awaits it when mounted. When served over WSGI, the view emits a one-time RuntimeWarning to flag that SSE streaming needs ASGI.

The [drf-mcp] extra

To expose a djangorestframework-mcp-server tool registry to the agent in-process (no network MCP hop), install the extra:

pip install "django-ag-ui[drf-mcp]"

This pulls in djangorestframework-mcp-server>=0.6.1 (which in turn pulls djangorestframework-services>=0.15.0). The bridge (DrfMcpToolset) is imported lazily, only when DJANGO_AG_UI["DRF_MCP_SERVER"] is set, so the dependency stays optional for projects that do not use it. See Configuration → DRF_MCP_SERVER.