nakul-bhai/group-chat
0
Crazy Ones Group Chat
A Hugging Face Space where 4 AI characters (Hakuo, Chika, Hyouka, Tomoko) independently decide whether to reply to user messages in a shared Discord group channel.
Architecture
Simple decentralized design — no central orchestrator, no complex framework. Just 4 independent "brains" that each make their own yes/no decision in parallel.
[Discord Group Channel]
↓ User sends message
[Discord Relay Bot] → POST /group-chat
↓
[HF Space Group Chat Server]
├─→ Agent 1 (Hakuo) — decides: reply? yes/no
├─→ Agent 2 (Chika) — decides: reply? yes/no
├─→ Agent 3 (Hyouka) — decides: reply? yes/no
└─→ Agent 4 (Tomoko) — decides: reply? yes/no
↓
[SSE Stream] → replies back to Relay → posted to DiscordTech Stack
- Python 3.11
- FastAPI (HTTP server)
- asyncio (parallel agent decisions)
- aiohttp (Qwen API client)
- SQLite (conversation history per agent)
- SSE (Server-Sent Events for real-time replies)
Quick Start
- Copy
.env.exampleto.envand set yourQWEN_API_KEY:
cp .env.example .env- Install dependencies:
pip install -r requirements.txt- Run the server:
uvicorn main:app --host 0.0.0.0 --port 7860API Endpoints
POST /group-chat
Receive a message from the Discord relay bot. Agents decide in parallel and replies stream via SSE.
{
"message_id": "uuid",
"user_id": "123456789",
"username": "user",
"message": "Hey everyone, what are you all up to?",
"channel_id": "discord-channel-id",
"timestamp": "2026-05-16T06:30:00Z"
}GET /events
SSE stream for real-time agent replies. Connect your Discord relay bot here.
GET /health
Health check endpoint.
Deployment
Hugging Face Spaces (Docker)
- Create a new HF Space with Docker template
- Push all files to the space
- Set
QWEN_API_KEYin Space secrets - The space will build and start automatically
Environment Variables
File Structure
crazyones-group-hf/
├── main.py # FastAPI app, endpoints
├── config.py # Settings, Qwen API key
├── agents/
│ ├── hakuo.py # Hakuo agent
│ ├── chika.py # Chika agent
│ ├── hyouka.py # Hyouka agent
│ ├── tomoko.py # Tomoko agent
│ └── base_agent.py # Shared Agent class
├── database/
│ └── db.py # SQLite + queries
├── services/
│ └── qwen_client.py # Async OpenAI-compatible client
├── prompts/
│ ├── hakuo.xml
│ ├── chika.xml
│ ├── hyouka.xml
│ └── tomoko.xml
├── data/
│ └── group.db # SQLite database (auto-created)
├── requirements.txt
├── Dockerfile
└── README.mdHow It Works
- Parallel Decision Making: All 4 agents receive the message simultaneously and independently decide whether to reply using the Qwen API.
- Priority System: Each agent has a priority (Hakuo=8, Tomoko=7, Hyouka=6, Chika=5). Higher priority agents reply first.
- Cooldown: Agents won't reply again within 30 seconds of their last reply.
- Max Replies: Maximum 3 agents can reply to a single message to avoid spam.
- Staggered Delivery: Replies are staggered by 2-second delays based on priority order.
- Force Reply: If a message mentions an agent (e.g.,
@Hakuo,@Chika Ono,@Tomoko), that agent bypasses the decision and replies directly. Supports multiple name forms:@hakuo,@hyouka natsume,@natsume,@chika ono,@ono, etc. - Shared History: All agents see the same last 12 messages, enabling them to react to what others said.
- Agent-to-Agent Replies: Agents can naturally reply to each other's messages in the chat history. This creates organic group chat dynamics where characters react to one another.
- Loop Prevention: Multiple safeguards prevent endless agent-to-agent chains:
- After 2+ consecutive agent replies, priority is reduced by 2
- After 3+ consecutive agent replies, agents are strongly told to stay silent unless directly addressed
- After 4+ consecutive agent replies, agents skip entirely (hard cutoff)
- The decision prompt explicitly instructs agents to let the user respond first when agents have been talking
- Messages are tagged with
source: userorsource: agentso the system tracks reply chains
