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.5.1
django-htmx>=1.29.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" button.
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" button.
Optional: enable background runs by setting
TASKS_BACKEND=django_tasks_rq.RQBackend and starting an RQ worker:
pdm run python manage.py rqworker --job-class django_tasks_rq.Jobpdm run lint
pdm run typecheck
pdm run docs
pdm run test
pdm run check
npm test
npm run build:csspdm run check runs lint, strict type checks, offline documentation checks, and
Python tests. Install Perfect Doc 0.1.0 or later on PATH before this command.
See Quality for setup and type-check rules.
- 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.