Hey devs!
This is my first post on here, and I am sharing what I built
Have you ever wanted an AI that argues with itself? I recently built a project called "AI Devil's Advocate" — a multi-agent debate application that lets two AI agents argue a topic while a Judge AI delivers the final verdict.
But building it came with a major challenges like: API Rate Limits etc.
Here is how I built it, how it works, and how I solved the rate-limit issue using Automatic Fallback.
What is AI Devil's Advocate?
It's an autonomous multi-agent system where:
- Agent A (For): Argues in favor of the topic.
- Agent B (Against): Argues against the topic.
- Judge AI: Listens to both sides and provides a structured verdict.
It's fully built with Python, LangGraph, and Streamlit, supporting multiple free-tier providers like Groq, Google Gemini, and OpenRouter.
Key Features
- Multi-Provider Architecture: Switch between Groq, Gemini, and OpenRouter on the fly.
- Automatic 429 Fallback (The Magic): If your active provider hits a rate limit or quota exhaustion, the app automatically switches to your next configured provider with zero interruption to the debate.
- Polished UI & Animations: Custom CSS, Google Fonts (Inter/Poppins), fade-in animations, and stylized debater cards.
- Transcript Exports: Download the entire debate as a styled PDF or Markdown file with 1 click.
- Session API Call Counter:** Real-time sidebar counter to monitor your free-tier usage.
Tech Stack & Architecture
- Frontend: Streamlit (with custom CSS for animations)
- Orchestration: LangGraph (State machine for multi-agent flow)
- LLM Factory: Custom
FallbackLLMWrapperclass that handles provider switching. - Providers: Groq (ultra-low latency), Google Gemini, OpenRouter.
- Exports: ReportLab (for PDF generation).
How the Fallback Works
Instead of relying on one API, I built an llm_factory.py that wraps all providers. If the primary LLM throws a 429 Too Many Requests error, the wrapper catches it and immediately routes the prompt to the next available provider in the list. The debate never stops!
Try it Live!
I have deployed it on Streamlit Community Cloud. You can try it right now:
Open Source
The project is completely open-source. Feel free to fork it, add new providers, or improve the UI!
What I Learned
Building this taught me a lot about:
- State Management in LangGraph for multi-agent conversations.
- Error Handling in Production LLMs (the 429 fallback is a lifesaver).
- UI/UX in Streamlit — you can make it look like a real SaaS product with a bit of custom CSS.
If you have any questions or feedback, drop a comment below! I'm currently exploring more Agentic AI workflows.
And this is my first post, so please let me know if I made any mistakes in writing or anywhere else. Also, if you like the repo, please consider giving it a star..
Happy coding!
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.