Django ↔ Pydantic-AI ↔ AG-UI integration: async view, tool registry, audit logger.
Project description
django-ag-ui
Wire a Pydantic-AI agent into any Django project and
speak the AG-UI protocol to a browser — a streaming
agent endpoint, a typed tool registry, and the plumbing in between. No admin
specifics; that lives in the downstream
django-admin-agent, and the
browser half is
@artooi/ag-ui-web-component.
- Async AG-UI endpoint —
DjangoAGUIViewwraps Pydantic-AI'sAGUIAdapterand returns aStreamingHttpResponseof AG-UI events (SSE). Conversation state rides in each request, so there's no cross-request session store and multi-worker deployments are safe by default. - Typed tool registry — register plain callables with
@tool; JSON Schema is derived from their signatures.destructive=/category=/confirm=/summary=metadata surface asx-destructive/x-category/x-confirm/x-summaryextensions for client-side gating. - Configurable agent —
AgentConfig+ theDJANGO_AG_UIsettings cover the model,MODEL_SETTINGS,RETRIES, externalTOOLSETS/CAPABILITIES, an explicitAPI_KEY/PROVIDERcredential path, and anAGENT_FACTORYescape hatch for full control of construction. - Authentication hooks —
require_authenticated=Truefails closed (401) for anonymous requests, and aget_user(request)hook establishes the user tools, the drf-mcp bridge, and conversation ownership act as. - One-object mounting — an
AGUIServer(registry, …)config object exposing a namespaced.urls, mounted theadmin.siteway withpath("agent/", server.urls). It builds the agent view and every sub-view from the registry passed once, and forwards one auth policy to all of them. - Skills — a
SkillRegistry/SkillSpeccatalog of pre-defined prompts served at<prefix>skills/(viaAGUIServer(..., skills=...)), surfaced by the web component as chips and a/-command palette. - Tool metadata catalog — a read-only
ToolsViewserved at<prefix>tools/(mounted automatically byAGUIServer), giving the web component (data-tools-url) friendly card labels for server-side tools whose schema never reaches the browser. - Audit boundary — an
AuditLoggerProtocol (Null/Loggingshipped, pluggable by dotted path) records every server-side tool call. - Opt-in conversation persistence — a
ConversationStoreProtocol with a no-op default, a session-backed store, and an abstract model-backed base. - Thread history — the store can
listandrenamea user's threads, and aThreadsViewserved at<prefix>threads/(mounted byAGUIServerwhen a store is active) backs a chat-history drawer (owner-scoped GET list / GET messages / PATCH rename / DELETE). An opt-indjango_ag_ui.contrib.storeapp ships a ready-made durable model +DefaultConversationStore(add it toINSTALLED_APPSandmigrate); the base package still ships no model. - File uploads — an
AttachmentStoreProtocol (owner-scoped, off by default) with anAttachmentsViewserved at<prefix>attachments/(mounted byAGUIServerwhen a store is active; server-validated POST upload / owner-checked GET download / DELETE). Uploads travel as lightweight refs, and a per-requestread_attachmenttool lets the agent read the bytes server-side. The samecontrib.storeapp ships aStorage-backedDefaultAttachmentStore. - Voice input — a
TranscriptionBackendProtocol (off by default) with aTranscribeViewserved at<prefix>transcribe/(mounted byAGUIServerwhen a backend is active; multipart audio in,{"text"}out). An opt-inOpenAITranscriptionBackendworks against any OpenAI-compatible/audio/transcriptionsendpoint (the[openai]extra). - Model reasoning — when a reasoning model is configured to think (via
MODEL_SETTINGS), its chain-of-thought streams to the client as standard AG-UI reasoning events (pure pass-through);FORWARD_REASONING = Falsekeeps it server-side. - Reach external tools — compose any Pydantic-AI toolset, including an
in-process
drf-mcpbridge (the[drf-mcp]extra) so the agent can query DRF-exposed data. - drf-services specs as tools, no MCP hop — point
SERVICE_SPECSat aname → specmapping and the agent calls them in-process viadjangorestframework-pydantic-ai'sSpecCapability(the[spec-tools]extra) — permission-checked, acting as the logged-in user, with the spec conventions taught to the model. - 100% test coverage, type-checked, Python 3.10–3.14, Django 4.2–6.0.
📖 Full documentation: https://artui.github.io/django-ag-ui/
pip install "django-ag-ui[anthropic]" # or [openai], or [google]
# or, with uv:
uv add "django-ag-ui[anthropic]"
The core dep is
pydantic-ai-slim[ag-ui], which ships no model-provider library — pick one via a provider extra (anthropic/openai/
ASGI required. The agent endpoint streams Server-Sent Events, which the sync WSGI worker can't serve — deploy under Daphne / Uvicorn.
Quick start
Register a read-only tool, mount the endpoint, and point a browser AG-UI client at it.
# tools.py
from django_ag_ui import ToolRegistry, tool
registry = ToolRegistry()
@tool(registry)
def count_active_users() -> int:
"""How many users are currently active."""
from django.contrib.auth import get_user_model
return get_user_model().objects.filter(is_active=True).count()
# urls.py
from django.urls import path
from django_ag_ui import AGUIServer
from .tools import registry
urlpatterns = [
path("agent/", AGUIServer(registry).urls),
]
# settings.py
DJANGO_AG_UI = {
"MODEL": "anthropic:claude-sonnet-4.6", # any Pydantic-AI model string
# "API_KEY": os.environ["ANTHROPIC_API_KEY"], # else inferred from env
# "MODEL_SETTINGS": {"temperature": 0.2},
# "AUDIT_LOGGER": "django_ag_ui.LoggingAuditLogger",
# "CONVERSATION_STORE": "django_ag_ui.DjangoSessionConversationStore",
}
POSTing an AG-UI RunAgentInput to /agent/ now streams the agent's run.
Frontend-declared tools in the request are merged into the agent's catalog
automatically; server-side tools run in-process. See the
docs for the full settings reference,
the persistence stores, and the drf-mcp bridge.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_ag_ui-0.18.1.tar.gz.
File metadata
- Download URL: django_ag_ui-0.18.1.tar.gz
- Upload date:
- Size: 292.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
796d644c172019c7cf5c26e10b7b5ea9a373b4c2b202fbb0ba5b3876f8a0b100
|
|
| MD5 |
f270ab71c664b61dc5df30b8e70b6808
|
|
| BLAKE2b-256 |
5fa0ca151bb6184b235c5473df492302d84fdf516625b0621eb37d0933610a52
|
Provenance
The following attestation bundles were made for django_ag_ui-0.18.1.tar.gz:
Publisher:
release.yml on Artui/django-ag-ui
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_ag_ui-0.18.1.tar.gz -
Subject digest:
796d644c172019c7cf5c26e10b7b5ea9a373b4c2b202fbb0ba5b3876f8a0b100 - Sigstore transparency entry: 2186987060
- Sigstore integration time:
-
Permalink:
Artui/django-ag-ui@fffba3a49e08b45f7fa16d96bcfc45b5a52a4d06 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Artui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fffba3a49e08b45f7fa16d96bcfc45b5a52a4d06 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_ag_ui-0.18.1-py3-none-any.whl.
File metadata
- Download URL: django_ag_ui-0.18.1-py3-none-any.whl
- Upload date:
- Size: 101.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c462f62170572d37f1e035fd7131f4cf1825788a9ec25fa61ee5acf809e5477c
|
|
| MD5 |
4d013e69b81f1c8773ae42a624347cbe
|
|
| BLAKE2b-256 |
61ae2f9862d74ae356a24239d9d09cc12c3f43baea9218ad4c2b71d8fdde91aa
|
Provenance
The following attestation bundles were made for django_ag_ui-0.18.1-py3-none-any.whl:
Publisher:
release.yml on Artui/django-ag-ui
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_ag_ui-0.18.1-py3-none-any.whl -
Subject digest:
c462f62170572d37f1e035fd7131f4cf1825788a9ec25fa61ee5acf809e5477c - Sigstore transparency entry: 2186987071
- Sigstore integration time:
-
Permalink:
Artui/django-ag-ui@fffba3a49e08b45f7fa16d96bcfc45b5a52a4d06 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Artui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fffba3a49e08b45f7fa16d96bcfc45b5a52a4d06 -
Trigger Event:
push
-
Statement type: