This Django project exercises the agentic-django package from PyPI.
The library provides agent run/session primitives, tool calling, and web-friendly
UI hooks to build LLM-powered Django apps.
See the agentic-django GitHub repo and
the agentic-django PyPI page.
For repo navigation and maintenance rules, start with AGENTS.md and
docs/index.md. The docs directory is the source of truth for architecture,
operations, quality expectations, and legibility notes.
The dependency is wired in pyproject.toml as:
agentic-django[rq]>=0.2.0
django-htmx>=1.27.0Prereqs: Docker Desktop (or compatible Docker CLI + Compose plugin).
- Configure env vars:
cp .env.example .envSet OPENAI_API_KEY in .env. Optionally set OPENAI_DEFAULT_MODEL.
- Build and run:
docker compose up --buildVisit http://localhost:8000/ and use the "Demo login" link.
Prereqs: Python 3.14+, PDM, and (optionally) Redis if you want background runs.
- Install dependencies:
pdm install --group dev- Configure env vars:
cp .env.example .envSet OPENAI_API_KEY in .env. Optionally set OPENAI_DEFAULT_MODEL.
- Run migrations:
pdm run python manage.py migrate- Start the dev server:
pdm run python manage.py runserverVisit http://localhost:8000/ and use the "Demo login" link.
Optional: enable background runs by setting
TASKS_BACKEND=django_tasks.backends.rq.RQBackend and starting an RQ worker:
pdm run python manage.py rqworker --job-class django_tasks.backends.rq.Jobpdm run lint
pdm run test
pdm run check
npm run build:csspdm run check runs the Python lint and test loop together.
- Agent registry and prompt loading:
apps/sample_app/agent_registry.pybuilds the demoAgentand pulls instructions fromapps/sample_app/prompts/demo_agent.prompt.mdusingpromptdown. - Tool calling:
apps/sample_app/tools.pydefines three@function_toolexamples (find, price, book) to show tool usage. - Agent runs and sessions:
apps/sample_app/views.pywires per-userAgentSessionand uses theagentic_djangorun/session models to track history. - HTMX run flow:
apps/sample_app/templates/sample_app/home.htmlposts toagents:run-create, pollsagents:run-fragment, and refreshes the conversation viaagents:session-items. - HTMX integration wiring:
agentic_django_example/settings.pyenablesdjango_htmx,apps/sample_app/templates/sample_app/base.htmlrenders{% htmx_script %}, and CSP is limited to self-hosted scripts. - Conversation rendering:
templates/agentic_django/partials/conversation.htmlandapps/sample_app/templatetags/sample_app_tags.pyformat messages, tool calls, and reasoning summaries. - Background execution (optional):
agentic_django_example/settings.pyconfiguresdjango_taskswith an RQ backend;docker-compose.ymlstarts Redis + an RQ worker.
- The library now uses
django-htmxinternally. The example therefore enablesdjango_htmxinINSTALLED_APPSanddjango_htmx.middleware.HtmxMiddlewareinMIDDLEWAREso package views can rely onrequest.htmx. - HTMX is now served through
django-htmx's{% htmx_script %}template tag instead of a CDN<script>tag. This keeps the demo aligned with Django 6 CSP support and avoids an externalscript-srcexception. - Run polling now stops server-side with
django_htmx.http.HttpResponseStopPolling(HTTP286) when a run reaches a terminal state. The example test suite covers that behavior.