A self-hosted AI workspace supporting multiple LLM providers (Gemini, OpenAI, Anthropic, Ollama) with streaming responses, an agentic ReAct loop for autonomous tool use, reasoning/thinking blocks, voice input & output, document upload, code interpreter, and per-user chat history.
Requirements: Docker + Docker Compose
1. Clone the repository
git clone https://github.com/MaximilianRau04/AI-Workspace.git
cd AI-Workspace2. Create a .env file in the project root
SECRET_KEY=your_random_secret_key_here
# Add the key for whichever provider(s) you want to use:
GEMINI_API_KEY=your_gemini_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
# Shared secret between the app and the code executor service (required for Docker)
CODE_EXECUTOR_TOKEN=another_random_secret_here
# Optional: behind a reverse proxy, trust its X-Forwarded-For header
# FORWARDED_ALLOW_IPS=172.18.0.0/16
# Optional: serve the session cookie over HTTPS only
# SESSION_COOKIE_SECURE=true
# Optional: run sandbox containers under gVisor (must be installed on the host)
# SANDBOX_RUNTIME=runsc
# Optional: max. concurrent code interpreter runs (default 4)
# SANDBOX_MAX_CONCURRENT=4Generate a secure SECRET_KEY and CODE_EXECUTOR_TOKEN (run once for each):
python3 -c "import secrets; print(secrets.token_hex(32))"3. Create empty data files (first run only)
touch chatbot.db model_config.json mcp_servers.json system_prompt.txtDocker bind-mounts these as files into the container (see docker-compose.yml). If a mounted file doesn't exist on the host yet, Docker creates a directory at that path instead, which breaks the app on startup — pre-creating them as empty files avoids that.
4. Start
docker compose up --buildOpen http://localhost:5000. Data (database, config, uploads) is stored in the project root and persists across container restarts.
Note: The code interpreter runs user code in isolated Docker containers with no network access. Docker must be running on the host for this feature to work. With Docker Compose, a separate
executorservice (Dockerfile.executor) is the only container with access to the Docker socket; the app talks to it over an internal network and only sends{code, language}. Without Docker (CODE_EXECUTOR_URLunset), the backend starts the sandbox containers itself.
Requirements: Python 3.10+, Node.js 18+
1. Clone the repository
git clone https://github.com/MaximilianRau04/AI-Workspace.git
cd AI-Workspace2. Create a virtual environment
cd backend
python3 -m venv venv
source venv/bin/activate # Linux / macOS
venv\Scripts\activate # Windows3. Install dependencies
pip install -r requirements.txt
cd ../frontend && npm install4. Create a .env file in the project root (same format as above)
API keys can also be entered directly in the in-app settings instead of the .env file.
Run backend and Vite dev server in two separate terminals:
# Terminal 1 – API server
cd backend && venv/bin/uvicorn app:app --host 0.0.0.0 --port 5000 --reload
# Terminal 2 – Frontend with HMR
cd frontend && npm run devOpen http://localhost:5173. The Vite dev server proxies API calls to port 5000 and provides hot module replacement.
cd frontend && npm run format # auto-format source filescd frontend && npm run build
cd ../backend && venv/bin/uvicorn app:app --host 0.0.0.0 --port 5000npm run build bundles everything into dist/. The backend detects dist/ and serves it automatically. Open http://localhost:5000.
The active provider and model are configured via the ⚙️ Settings button → Model tab. The configuration is saved in model_config.json (not tracked by git).
| Provider | Example models | Notes |
|---|---|---|
| Google Gemini | gemini-2.5-flash, gemini-2.5-pro |
Default. API key from Google AI Studio. Also used for document RAG embeddings. |
| OpenAI | gpt-4o, gpt-4o-mini |
Requires OPENAI_API_KEY. |
| Ollama (local) | qwen3:8b, llama3.2:3b, mistral:7b |
No API key needed. Set provider to OpenAI / Compatible and base URL to http://localhost:11434/v1. Use "Detect models" to list installed models. |
| LM Studio / other | any OpenAI-compatible model | Same as Ollama - set the base URL to the local server's /v1 endpoint. |
| Anthropic Claude | claude-opus-4-8, claude-sonnet-4-6 |
Requires ANTHROPIC_API_KEY. |
- Install Ollama and pull a model, e.g.
ollama pull qwen3:8b - Make sure the Ollama service is running before starting a chat:
ollama serve
- In the app: Settings → Model → Provider: OpenAI / Compatible
- Set the base URL to
http://localhost:11434/v1and click Detect models to auto-fill available models - Save - no API key or restart required
Note: Every time you start the app with Ollama as the provider,
ollama servemust be running in the background, otherwise you will get a Connection error when sending messages.
- Multi-provider LLM - switch between Gemini, OpenAI, Anthropic, or any local model via Ollama/LM Studio without restarting
- User accounts - register & login; each user has their own isolated chat history
- Streaming responses with typewriter effect
- Persistent chat sessions with sidebar for switching between conversations
- Auto-summarization - old messages are summarized automatically to keep context efficient
- Syntax highlighting - code blocks highlighted via highlight.js
- Agentic ReAct loop - the model autonomously decides when and how often to call tools; it can chain multiple tool calls in a single turn (e.g. search → read page → run code → answer) up to a configurable step limit (
MAX_AGENT_STEPS) - Web search - enable via the ➕ tools menu; the agent searches via DuckDuckGo and fetches URLs as needed - you control access, the model decides usage
- Code interpreter - enable via the ➕ tools menu; the agent can write and execute code in isolated Docker containers (no network, memory/CPU limits); supported languages: Python, JavaScript, TypeScript (Deno), Bash, Ruby, PHP, Perl, Elixir, Lua, C, C++, Java, Go, Rust, C# (Mono) - Java class must be named
Main - MCP servers - enable individual connected servers via the ➕ tools menu; connect any MCP server (folder access, GitHub, email, calendar, …) as tools for the agent over stdio, HTTP, or SSE, with built-in OAuth sign-in for remote servers that need it, see MCP Servers below
- Voice input - microphone button (Chrome / Edge only)
- Voice output - toggle via 🔇 button (powered by edge-tts)
- Document RAG - upload
.txt,.md, or.pdffiles; the bot retrieves relevant passages automatically (requires Gemini API key for embeddings) - Image input - attach up to 6 images (PNG/JPEG/GIF/WebP) per message via the 🖼️ button; sent to the model's native vision API (Gemini, OpenAI, Anthropic) and kept in the conversation history for follow-up questions
- Configurable system prompt - via the ⚙️ settings button
- Token usage indicator - ring graph next to the input bar (Gemini only)
- Light / dark theme toggle
ChatBot/
├── backend/
│ ├── app.py # FastAPI app: setup & router registration
│ ├── auth_store.py # User storage (SQLite, password hashing)
│ ├── db.py # SQLite connection & schema initialization
│ ├── history.py # Per-user session persistence & summarization
│ ├── llm.py # Provider abstraction (Gemini / OpenAI / Anthropic)
│ ├── rag.py # Document indexing & retrieval (Gemini embeddings)
│ ├── state.py # Per-user in-memory chat state
│ ├── mcp_store.py # MCP server config storage (mcp_servers.json)
│ ├── mcp_manager.py # MCP client: background event loop, connects to configured servers
│ ├── utils.py # Shared helpers (login_required dependency)
│ ├── requirements.txt # Python dependencies
│ ├── venv/ # Virtual environment (not tracked by git)
│ └── routes/
│ ├── auth.py # /login /register /logout /me
│ ├── chat.py # /chat (streaming SSE)
│ ├── config.py # /config /config/model /config/ollama-models
│ ├── docs.py # /docs /docs/upload /docs/delete
│ ├── mcp.py # /mcp/servers - add/edit/delete/list MCP servers; OAuth authorize + callback
│ ├── sessions.py # /sessions /sessions/new /sessions/<id>
│ └── voice.py # /tts /stt
├── frontend/
│ ├── index.html # HTML entry point (React root)
│ ├── vite.config.js # Vite config (React plugin, dev proxy, build output)
│ ├── tailwind.config.js # Tailwind theme tokens (colors, dark mode)
│ ├── tsconfig.json # TypeScript config
│ ├── postcss.config.js
│ ├── package.json
│ └── src/
│ ├── main.tsx # React entry point
│ ├── App.tsx # Router setup
│ ├── index.css # Global styles & Tailwind directives
│ ├── types.ts # Shared TypeScript interfaces
│ ├── globals.d.ts # Type declarations for CDN globals (marked, hljs)
│ ├── api/ # Typed fetch wrappers (auth, chats, config, docs, voice)
│ ├── context/ # AppContext - auth, sessions, config, theme
│ ├── hooks/ # useStream (SSE), useVoice (mic + TTS)
│ ├── pages/ # ChatPage, LoginPage
│ ├── components/
│ │ ├── chat/ # ChatArea, MessagePair, InputArea, HomeHero
│ │ ├── layout/ # Header (model switcher), Sidebar
│ │ ├── settings/ # SettingsModal
│ │ └── documents/ # DocsModal
│ └── utils/
│ └── markdown.ts # marked + highlight.js rendering helpers
├── dist/ # Production build output (not tracked by git)
├── docs/ # Uploaded documents (not tracked by git)
├── chatbot.db # SQLite database - users & chats (not tracked by git)
├── model_config.json # Active model/provider config (not tracked by git)
├── rag_index.json # Document embeddings (not tracked by git)
├── system_prompt.txt # Editable system prompt
├── .env # API keys & secret key (not tracked by git)
└── README.md
When web search or code interpreter is enabled, the model runs in a ReAct loop (Reasoning + Acting):
User message
└─ LLM thinks → calls tool (web_search / fetch_url / execute_code)
└─ result returned to LLM
└─ LLM thinks again → calls another tool (optional)
└─ ... repeat up to MAX_AGENT_STEPS (default: 10)
└─ LLM produces final answer
The toggle buttons in the input bar control which tools the model has access to - not whether a tool will be called. The model decides autonomously if and when a tool is needed. Example multi-step flows:
- "What's the current EUR/USD rate and how much is 1500 EUR in USD?" → web_search → execute_code → answer
- "Summarize the article at this URL and translate it to German" → fetch_url → answer
- "Write a Python script that sorts a list and show me the output" → execute_code → answer
The intermediate steps (searches, code executions) are streamed to the frontend in real time so you can follow what the agent is doing.
The ⚙️ Settings → MCP Servers tab lets you connect any Model Context Protocol server to give the agent new tools - folder access, GitHub, email, calendar, and anything else with an MCP server. Once connected, each server can be individually enabled per chat via the ➕ tools menu → MCP servers submenu - only the tools of the servers you actually check are sent to the model.
Each server picks one of three transports in the Add/Edit form:
- Local (stdio) - runs as a local subprocess (via
npxoruvx) and stays connected for the lifetime of the backend process. Requires Node.js/npm (already included in the Docker image) and/oruv(installed as a Python dependency, providesuvx). - Remote (HTTP) - connects to a server exposed over the MCP Streamable HTTP transport (just a URL).
- Remote (SSE) - connects over the older Server-Sent Events transport, for servers that haven't moved to Streamable HTTP yet.
Example: folder access (stdio) - add a server with:
- Transport: Local (stdio)
- Command:
npx - Args:
-y @modelcontextprotocol/server-filesystem /path/to/folder
Any folder passed as an arg becomes readable/writable by the agent. When running via Docker, make sure that folder is also mounted into the container (see docker-compose.yml).
Example: GitHub (stdio) - add a server with:
- Transport: Local (stdio)
- Command:
npx - Args:
-y @modelcontextprotocol/server-github - Env:
GITHUB_PERSONAL_ACCESS_TOKEN=<your token>
Servers with static secrets (tokens, API keys) should pass them via the Env field (stdio) or Headers field (remote) rather than baking them into args - they're stored in mcp_servers.json (not tracked by git, same as model_config.json).
Remote servers with OAuth - for remote (HTTP/SSE) servers that require interactive sign-in rather than a static token (e.g. Gmail, Google Calendar), check Sign in via OAuth instead of setting a header. The backend then runs the full OAuth 2.1 + PKCE + dynamic client registration flow itself: click Sign in next to the server in Settings, complete the consent screen it opens, and the backend exchanges and stores the resulting tokens - refreshed automatically on later reconnects, no manual token entry needed.
- Passwords are hashed with
werkzeug.security(scrypt + salt) - never stored in plain text. - The session cookie is signed with
SECRET_KEYvia Starlette'sSessionMiddleware. IfSECRET_KEYis missing, a known placeholder, or shorter than 16 characters, the app logs a warning and uses a random key for that run instead (everyone is logged out on restart). SetSESSION_COOKIE_SECURE=truewhen serving over HTTPS so the cookie is never sent over plain HTTP. - Admin role: the first registered account becomes the admin (on existing installs, the oldest account is promoted automatically). Only admins can change global settings: model/provider and API keys, system prompt, voice defaults, pricing, and MCP servers (stdio servers run arbitrary commands on the host). Regular users never receive API keys or MCP secrets (env, headers, args, OAuth tokens) from the API.
- Login and registration are rate-limited (5 failed logins per username from the same IP and 10 per IP within 15 minutes, 5 new accounts per IP per hour). The per-username limit is scoped to the client IP, so failed attempts from elsewhere cannot lock the real user out. Limits are kept in memory and reset on restart.
- Code interpreter containers run without network, as user
nobody, with a read-only root filesystem, all capabilities dropped,no-new-privileges, and limits on memory, CPU, processes, open files and file size. With Docker Compose, the Docker socket is mounted only into the smallexecutorservice, which accepts nothing but code and a language (authenticated viaCODE_EXECUTOR_TOKEN) and builds the hardeneddocker runitself, so a compromised app container cannot start arbitrary containers. The executor still has root-equivalent access to the host; for stronger isolation, install gVisor and setSANDBOX_RUNTIME=runsc. - Each run is limited to 30 seconds; timed-out containers are killed. At most
SANDBOX_MAX_CONCURRENTruns (default 4) execute at the same time, further requests wait up to 30 seconds for a free slot and are then rejected. The limit applies per process: with Docker Compose that is the singleexecutorservice. Without the executor (CODE_EXECUTOR_URLunset), every uvicorn worker has its own limit, so the effective maximum is workers ×SANDBOX_MAX_CONCURRENT. - Behind a reverse proxy, set
FORWARDED_ALLOW_IPSto the proxy's address so the rate limit sees real client IPs instead of the proxy. Don't set it to*while the app port is reachable without the proxy, otherwise clients can fakeX-Forwarded-Forand bypass the rate limit. - API keys and
SECRET_KEYlive in.envand are excluded from version control. - Model config (including any API key entered via the UI) is stored in
model_config.json, which is also excluded from version control. - MCP server config (including any tokens entered in the Env/Headers field, and any OAuth tokens obtained via the Sign in flow) is stored in
mcp_servers.json, also excluded from version control. MCP servers run as local subprocesses or remote connections with full access to whatever the server implementation exposes - only add servers you trust. chatbot.dbcontains user data and chat history - never commit it to version control.

