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=metadata surface asx-destructive/x-categoryextensions for client-side gating. - Configurable agent —
AgentConfig+ theDJANGO_AG_UIsettings cover the model,MODEL_SETTINGS,RETRIES, externalTOOLSETS/CAPABILITIES, and anAGENT_FACTORYescape hatch for full control of construction. - 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. - 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. - 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
# or, with uv:
uv add django-ag-ui
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 # noqa: F401
from django_ag_ui import DjangoAGUIView, get_urls
from .tools import registry
urlpatterns = [
*get_urls(DjangoAGUIView(registry), prefix="agent/"),
]
# settings.py
DJANGO_AG_UI = {
"MODEL": "anthropic:claude-sonnet-4.6", # any Pydantic-AI model string
# "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
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.1.1.tar.gz.
File metadata
- Download URL: django_ag_ui-0.1.1.tar.gz
- Upload date:
- Size: 309.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ce17a287aeef355c6aa8ad5faa4d97906e0e656536b3c2962d56d1bd8397d51
|
|
| MD5 |
ee64825c458e25913d2a2af0294dcf3f
|
|
| BLAKE2b-256 |
10d38a891fb1066cddf4ec3ffab77695b08a44704d71865d8af627b3efa00212
|
Provenance
The following attestation bundles were made for django_ag_ui-0.1.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.1.1.tar.gz -
Subject digest:
0ce17a287aeef355c6aa8ad5faa4d97906e0e656536b3c2962d56d1bd8397d51 - Sigstore transparency entry: 1692450099
- Sigstore integration time:
-
Permalink:
Artui/django-ag-ui@bb239efcae8c6293523c57b2f633aeb2ffe965c7 -
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@bb239efcae8c6293523c57b2f633aeb2ffe965c7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_ag_ui-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_ag_ui-0.1.1-py3-none-any.whl
- Upload date:
- Size: 33.0 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 |
06e4022bd0b3876dc4062427747d3bb3494727385df06d85963e612323904bfe
|
|
| MD5 |
b46ec15b4ae111dd0aed112e3321b086
|
|
| BLAKE2b-256 |
f790deb5c3e2c017a16abcd2a1d07ad3c3fed4d4452d1219db2c442dd370b7c5
|
Provenance
The following attestation bundles were made for django_ag_ui-0.1.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.1.1-py3-none-any.whl -
Subject digest:
06e4022bd0b3876dc4062427747d3bb3494727385df06d85963e612323904bfe - Sigstore transparency entry: 1692450272
- Sigstore integration time:
-
Permalink:
Artui/django-ag-ui@bb239efcae8c6293523c57b2f633aeb2ffe965c7 -
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@bb239efcae8c6293523c57b2f633aeb2ffe965c7 -
Trigger Event:
push
-
Statement type: