Building a Pluggable AI Agent System with Django
How HyperSaaS keeps its AI framework behind one boundary: LangGraph ships with it, and another framework is one more handler, not a rewrite.
Updated October 2026: HyperSaaS ships one agent framework, LangGraph. The boundary this post describes is what keeps adding another a contained change.
The Problem with Monolithic AI Integrations
Most SaaS boilerplates hard-wire a single AI framework into their codebase, and its message types end up in your views, your database code and your tests. When you want to move to another framework, or add your own inference pipeline, you're looking at a rewrite.
Our Approach: Framework-Agnostic Boundaries
HyperSaaS keeps the framework behind three things:
- AgentMessage: a framework-agnostic dataclass that every handler returns.
- BaseAgentHandler: the abstract base class every handler implements:
invoke(),astream(), andstream()for streamed replies. - Plain Python tools: ordinary functions with no framework imports, which a handler wraps for its runtime.
The LangGraph handler converts LangChain's messages into AgentMessage at the boundary, so the code that streams replies to the browser, saves them and counts their usage doesn't depend on LangGraph. A chat set to none skips the agent and calls the model directly.
Adding a New Framework
To run chats on another framework, such as PydanticAI or the OpenAI Agents SDK:
- Create a handler in
chat/handlers/your_framework/. - Implement
invoke()andastream(), andstream()if replies should stream. - Wrap the plain tools for your framework, and register the handler in the factory.
- Add it to the
agent_frameworkchoices.
Saving replies, counting usage, streaming and the frontend work without changes.
Why This Matters
Your AI stack will evolve. New frameworks emerge constantly. By keeping a clean boundary between your business logic and your AI runtime, you can adopt new tools without rewriting your application.