An agentic joke generation application powered by Groq's LLaMA model, featuring a dual-agent architecture with independent writer and critic roles for quality-controlled humor generation.
This project implements a sophisticated Writer-Critic pattern for generating high-quality jokes. The system uses two specialized LLM agents:
- Writer Agent: Generates creative, original jokes with high creativity settings (temperature: 0.9)
- Critic Agent: Reviews jokes against quality criteria with strict, deterministic evaluation (temperature: 0.0)
graph TD
A[User Request] --> B[Writer Agent]
B -->|Generate Joke| C[Critic Agent]
C -->|Approved| D[Display Joke]
C -->|Rejected| E[Retry Loop]
E -->|Max Retries| F[Fail]
E -->|Retry| B
B -.->|Temperature 0.9| G[High Creativity]
C -.->|Temperature 0.0| H[Strict Evaluation]
- Multi-category jokes: programming, dad jokes, dark humor, one-liners, slapstick, knock-knock, tech, career, relationships, random
- Multi-language support: English, Spanish, French, German, Italian, Portuguese, Hindi, Japanese, Chinese, Korean, Russian, Arabic, Tamil, Telugu
- Quality control: Automatic review against humor, appropriateness, category match, originality, and language criteria
- Retry mechanism: Up to 3 attempts per joke with feedback integration
- Interactive CLI: User-friendly menu for category/language selection
llm-writer-critic-system/
├── README.md # This file
├── requirements.txt # Python dependencies
├── config.yaml # Configuration settings
├── .env.example # Environment template
└── app/
├── __init__.py
├── main.py # Main CLI application
├── llm.py # LLM initialization & validation
├── writer.py # Writer agent for joke generation
└── critic.py # Critic agent for quality review
-
Clone the repository
cd llm-writer-critic-system -
Create virtual environment
python -m venv venv source venv/bin/activate # Linux/Mac # or .\venv\Scripts\activate # Windows
-
Install dependencies
pip install -r requirements.txt
-
Configure environment
cp .env.example .env # Edit .env and add your Groq API key
Edit config.yaml to customize:
- LLM provider and model settings
- Temperature parameters (writer creativity vs. critic strictness)
- Application defaults (max retries, categories, languages)
- Logging preferences
python -m app.mainn- Generate next jokec- Change categoryl- Change languagem- Show full menue- Exit
Writer Agent (app/writer.py)
Generates jokes using a carefully crafted prompt with:
- Category-specific descriptions
- Language targeting
- Previous attempt avoidance
- Creative temperature (0.9)
Critic Agent (app/critic.py)
Evaluates jokes against six criteria:
- Funny - Genuine humor
- Appropriate - Clean and suitable
- Category Match - Fits the theme
- Original - Creative, not clichéd
- Concise - Short (1-3 lines)
- Language - Correctly written
LLM Interface (app/llm.py)
Uses LangChain's ChatGroq integration with Groq's llama-3.1-8b-instant model.
- Python 3.8+
- Groq API key (get one here)
- Dependencies:
langchain-groq,python-dotenv,langchain-core
MIT License