Batteries included: agents, workflows, subagents, oversight, and RAG when you need it. Ready in days.
uv add django-ai-sdk
Create an AI agent in minutes.
Add the package and configure Django.
uv add django-ai-sdk
# or
pip install django-ai-sdk
INSTALLED_APPS = [
...
"django_ai_sdk",
]
python manage.py migrate
Create a class with name, model, and instructions.
from django_ai_sdk import Agent
from django_ai_sdk.adapters.base import Stream
from django_ai_sdk.generators import openai_responses_chat
from haystack import Pipeline
class HelpDeskAgent(Agent):
name = "Help Desk"
model = "gpt-5-mini"
instructions = "You are a helpful support agent."
llm = openai_responses_chat
async def get_pipeline_adapter(self, thread_id=None, user=None):
storage_adapter = await self.get_storage_adapter(thread_id)
generator = self.get_llm()
return Stream(
pipeline=Pipeline(),
generator=generator,
storage_adapter=storage_adapter,
)
Optional: override two methods to ground answers in your documents.
from django_ai_sdk.rags import (
BM25QueryExpanderRAG,
BM25QueryExpanderRAGConfig,
)
async def get_rag_queryset(self, memory_id=None):
if memory_id:
return Entry.objects.filter(memory_id=memory_id)
return Entry.objects.all()
async def get_rag_pipeline(self, memory_id=None):
documents = await self.get_rag_documents(memory_id)
if not documents:
return None
return BM25QueryExpanderRAG(
documents=documents,
config=BM25QueryExpanderRAGConfig(top_k=5),
)
Use as_view() to return an SSE response.
from .agents import HelpDeskAgent
agent = HelpDeskAgent()
@router.post("/chat")
async def chat(request, payload: ChatRequest):
return await agent.as_view(
payload.messages,
thread_id=payload.thread_id,
)
More than chat with your documents.
Answers stream in as they are written. Reasoning, tool calls and citations arrive as their own events, and the Vercel AI SDK and OpenAI clients render them as they come in.
Chain agents into steps that run in a worker. A step can stop for approval and continue on the next worker after a restart.
Block prompt injection, mask personal data and send risky turns to a person. Lenses ask the questions and rules act on the answers, in one Python class.
A coordinator splits the job between specialists that run in parallel, each with its own tools and instructions.
Run the same agent from a view, a background task or a plain API call.
Chain agent calls into steps. Every step is recorded, so you can see what ran and why.
Split a hard problem across specialist agents instead of one agent that does everything.
Give agents MCP servers, memory and your own Python functions as tools.
Answers stream as they are generated, in the format the Vercel AI SDK reads.
Threads keep their history, so you don't write message storage yourself.
Ground answers in your documents with hybrid search and query expansion.
Refresh embeddings when your documents change, without a rebuild.
Answer questions about the spreadsheets, contracts and reports your users upload.
Let agents act in the tools your team already uses, such as Zendesk, Linear and GitHub.
Workflow runs and uploads run in a worker on DBOS, in your own database. If a worker dies, the next one picks up the run where it stopped.
Block prompt injection, mask personal data and send risky turns to a person, from one Python class.
from django_ai_sdk import Agent
from django_ai_sdk.adapters.base import Stream
from django_ai_sdk.generators import openai_responses_chat
from django_ai_sdk.rags import (
BM25QueryExpanderRAG,
BM25QueryExpanderRAGConfig,
)
from haystack import Pipeline
class HelpDeskAgent(Agent):
name = "Help Desk"
model = "gpt-5-mini"
instructions = "You are a helpful support agent."
llm = openai_responses_chat
async def get_rag_queryset(self, memory_id=None):
if memory_id:
return Entry.objects.filter(memory_id=memory_id)
return Entry.objects.all()
async def get_rag_pipeline(self, memory_id=None):
documents = await self.get_rag_documents(memory_id)
if not documents:
return None
return BM25QueryExpanderRAG(
documents=documents,
config=BM25QueryExpanderRAGConfig(top_k=5),
)
async def get_pipeline_adapter(self, thread_id=None, user=None):
storage_adapter = await self.get_storage_adapter(thread_id)
generator = self.get_llm()
return Stream(
pipeline=Pipeline(),
generator=generator,
storage_adapter=storage_adapter,
)
from .agents import HelpDeskAgent
agent = HelpDeskAgent()
@router.post("/chat")
async def chat(request, payload: ChatRequest):
return await agent.as_view(
payload.messages,
thread_id=payload.thread_id,
)
See it all running in Studio.
Studio is the open-source reference app for the SDK: a Django project that uses every feature, and native apps for macOS, iPhone and iPad that talk to it.
Chat agents, swarms, deep research, memories and RAG, workflows with a worker, MCP integrations, and django-ninja and DRF APIs. Run it in Docker, against your own SDK checkout or the release on PyPI.
A native SwiftUI client. Streamed chat with reasoning, tool calls, artifacts, citations and file uploads. Build your own agents, and run a workflow and follow it live.