Compare commits

...
9 Commits
Author SHA1 Message Date
Suppai_NekoandDadBot c0f0856501 Add fetch_url tool for reading webpage content
Bot can now fetch and read the text content of URLs shared in chat.
Uses httpx for async HTTP and BeautifulSoup to strip HTML noise.
Output is capped at 8000 chars to avoid blowing the context window.

Co-Authored-By: DadBot <dadbot@localhost>
2026-03-25 16:58:29 -07:00
Suppai_NekoandDadBot 495b7aaaba Persist channel history, add fetch_channel_history tool, fix Qwen tool-use reliability
- Persist per-channel rolling history to disk (channel_history.json) so
  context survives bot restarts
- Add fetch_channel_history tool so the bot can pull Discord channel history
  on demand when it needs more context (e.g. first mention in a channel)
- Add _ensure_user_tail() called proactively before every LLM call to
  prevent Qwen "No user query found" template errors after tool results
- Set tool_choice="required" on the first agent call to guarantee the bot
  always uses a tool before replying; subsequent calls use "auto"

Co-Authored-By: DadBot <dadbot@localhost>
2026-03-25 16:53:32 -07:00
Suppai_NekoandDadBot 02267f0059 Merge experimental into master
Co-Authored-By: DadBot <dadbot@localhost>
2026-03-25 14:52:30 -07:00
Suppai_NekoandDadBot ae49591735 Add README
Co-Authored-By: DadBot <dadbot@localhost>
2026-03-25 14:50:51 -07:00
Suppai_NekoandDadBot a596609d7a Natural message pacing based on word count, misc bot.py updates
- Replace character-based send delay with word-count/15s for natural typing pacing
- Add life simulation, topic exploration, image attachment support
- Add READ_LIFE_HISTORY_TOOL and reflection topic picking
- Retry logic for transient LLM errors (Qwen template quirks)

Co-Authored-By: DadBot <dadbot@localhost>
2026-03-25 14:49:24 -07:00
Suppai_NekoandDadBot 1a82ac19f6 Resolve user mentions to display names before passing to LLM
Replace <@USER_ID> Discord mention syntax with @DisplayName for all
non-bot users in incoming messages, so the LLM sees real names instead
of numeric IDs and responds using names naturally.

Co-Authored-By: DadBot <dadbot@localhost>
2026-03-18 19:34:17 -07:00
Suppai_NekoandDadBot 2001c25bb6 Merge dolphin-mistral: background model split, logging, semaphore, cooldowns, prompt updates
- Structured logging with timestamps and per-task prefixes ([agent], [dossier], etc.)
- Background LLM semaphore to prevent concurrent background calls
- 120s cooldown after background task failures
- 90s timeout on background LLM calls to prevent deadlocks
- BACKGROUND_MODEL env var to use a separate model for dossier/compaction tasks
- Strip <think> tags from model responses (Qwen compat)
- Prompt: read the room for dynamic mood adaptation
- Prompt: blunt one-line self-correction, no apologies
- Prompt: more aggressive stance, never fold under pressure
- Updated personality.txt: less people-pleasing, more authentic

Co-Authored-By: DadBot <dadbot@localhost>
2026-03-18 15:01:30 -07:00
Suppai_NekoandDadBot 82b9bbde73 Add BACKGROUND_MODEL to split chat and background LLM calls
Dossier extraction and compaction now use a separate BACKGROUND_MODEL
(dolphin-mistral) to avoid Qwen3.5 timeout issues on background tasks.

Co-Authored-By: DadBot <dadbot@localhost>
2026-03-18 12:39:35 -07:00
Suppai_NekoandDadBot f283fa5360 Add Qwen3.5 support: logging, semaphore, cooldown, background timeouts
- Switch model to qwen3.5-35b-a3b
- Add structured logging with timestamps and per-task prefixes
- Add background LLM semaphore to prevent concurrent background calls
- Add 120s cooldown after background task failures
- Add 90s timeout on background LLM calls to prevent semaphore deadlock
- Strip <think> tags from Qwen model responses
- Tune prompt: more aggressive stance, no folding under pressure

Co-Authored-By: DadBot <dadbot@localhost>
2026-03-18 12:28:49 -07:00
5 changed files with 910 additions and 87 deletions

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY bot.py .
COPY bot.py topics.txt ./
ENV PYTHONUNBUFFERED=1
+85
View File
@@ -0,0 +1,85 @@
# DadBot
A Discord bot with a persistent personality, long-term memory, and a simulated inner life. Runs through LiteLLM so you can point it at any model.
## Features
- **Persistent personality** — DadBot can rewrite his own personality prompt via a tool call. Changes persist to `personality.txt` and are logged to `personality_changelog.txt`.
- **User dossiers** — Automatically builds and maintains a per-user fact file (`dossiers.json`) from conversation history.
- **Self-reflection** — When idle, DadBot runs a private reflection session: explores a topic from `topics.txt`, updates his reflection notes, and may refine his personality.
- **Life simulation** — Alternates with reflection sessions to run scripted life events (`life_events.json`) as a two-LLM dialogue. Outcomes are summarised into `life_history.txt` and can influence personality.
- **Web search** — Connected to a SearXNG MCP server for live web search during conversations and reflections.
- **Image support** — Handles image attachments in messages (base64-encoded, passed to the model as vision input).
- **Multi-message replies** — Use `[SPLIT]` in model output to send multiple Discord messages with natural word-count-based pacing.
- **Rolling context** — Per-channel message history with a configurable window (`MAX_CONTEXT`).
## Requirements
- Python 3.11+
- A running [LiteLLM](https://github.com/BerriAI/litellm) proxy
- A running [SearXNG MCP](https://github.com/ihor-sokoliuk/mcp-searxng) instance (optional but expected)
- A Discord bot token
## Setup
1. Copy `.env.example` to `.env` and fill in your values:
```env
DISCORD_TOKEN=your_discord_bot_token
LITELLM_BASE_URL=http://your-litellm-host:4000/v1
LITELLM_API_KEY=your_key
MODEL=your-chat-model
BACKGROUND_MODEL=your-background-model # defaults to MODEL if unset
SYSTEM_PROMPT=...
MAX_CONTEXT=20
MCP_URL=http://mcp-searxng:4001/mcp
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Run:
```bash
python bot.py
```
## Docker
```bash
docker compose up -d
```
The compose file expects an external Docker network named `aiplayground_litellm_internal` and mounts all persistent data files from the project directory.
## Configuration
| Variable | Default | Description |
|---|---|---|
| `MODEL` | `gpt-4` | Model for chat and reflection |
| `BACKGROUND_MODEL` | `MODEL` | Model for background tasks (life sim, reflection) |
| `MAX_CONTEXT` | `20` | Rolling message history per channel |
| `SYSTEM_PROMPT` | `You are a helpful assistant.` | Base system prompt |
| `MCP_URL` | `http://mcp-searxng:4001/mcp` | SearXNG MCP endpoint |
| `REFLECTION_IDLE_MIN` | (see bot.py) | Minutes of inactivity before background task fires |
| `REFLECTION_MAX_TURNS` | `5` | Max LLM turns per reflection session |
| `LIFE_SIM_MAX_TURNS` | `6` | Max turns per life simulation event |
## Data Files
| File | Purpose |
|---|---|
| `personality.txt` | DadBot's current personality prompt (editable by the bot) |
| `dossiers.json` | Per-user and self fact store |
| `reflection_notes.txt` | Notes DadBot saves for future reflection sessions |
| `reflection_log.txt` | Full transcripts of past reflection sessions |
| `personality_changelog.txt` | Log of every personality change with reasoning |
| `topics.txt` | One topic per line — exploration pool for reflection sessions |
| `used_topics.json` | Tracks which topics have been used |
| `life_events.json` | Ordered list of life events to simulate |
| `used_life_events.json` | Tracks which life events have been played |
| `life_history.txt` | Summaries of completed life events |
| `life_sim_log.txt` | Full transcripts of life simulation sessions |
+807 -85
View File
File diff suppressed because it is too large. Load diff
+15 -1
View File
@@ -1,11 +1,25 @@
services:
discordbot:
build: .
restart: unless-stopped
restart: on-failure
deploy:
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 5
window: 120s
env_file: .env
volumes:
- ./dossiers.json:/app/dossiers.json
- ./personality.txt:/app/personality.txt
- ./reflection_log.txt:/app/reflection_log.txt
- ./personality_changelog.txt:/app/personality_changelog.txt
- ./reflection_notes.txt:/app/reflection_notes.txt
- ./used_topics.json:/app/used_topics.json
- ./life_events.json:/app/life_events.json
- ./used_life_events.json:/app/used_life_events.json
- ./life_history.txt:/app/life_history.txt
- ./life_sim_log.txt:/app/life_sim_log.txt
networks:
- litellm_net
+2
View File
@@ -2,3 +2,5 @@ discord.py>=2.3
openai>=1.0
python-dotenv>=1.0
mcp>=1.0
httpx>=0.27
beautifulsoup4>=4.12