Chat

The chat is an AI assistant that answers questions about your databases, writes files and plots, and can submit long queries to the query scheduler’s queue for your approval. You ask it in the web UI’s Chat window; this page covers setting it up and running it.

The assistant works in a sandbox container whose only network peer is a gateway container. The gateway holds the model’s credential, so the sandbox never sees it, and reaches the model and the databases’ MCP servers for it. What the sandbox runs and what it can reach is in Broker, web UI and chat.

Back ends

Back end What it uses What setup asks
claude-code Claude Code on your own Claude subscription login The token: run claude setup-token on a machine where you are logged in to Claude Code and paste what it prints. This uses YOUR subscription, under the vendor’s terms for it.
openai-compatible An endpoint that speaks the OpenAI API, such as OpenRouter The endpoint’s address (default https://openrouter.ai/api/v1), the model name, and the endpoint’s API key

The address must be https://host[:port]/path: https only, and no user name, query, fragment, .. or %. The model name is 1 to 200 visible ASCII characters without spaces.

Set up and start

1. Have a database the chat can read. The chat reads a database only through its MCP server on the database’s read-only user. Set the database up with authentication and a read-only user, then its MCP server, then start it.

python sdp.py db setup                      # authentication and a read-only user
python sdp.py db setup-mcp                  # the MCP servers
python sdp.py db start                      # databases, MCP servers, scheduler

2. Set up the chat. It asks the back end, the secret and the work folder’s cap, and builds the images sdp-gateway and sdp-sandbox.

python sdp.py chat setup

3. Start it.

python sdp.py chat start                    # gateway and sandbox; attaches the databases

4. Start the web UI, or restart it. The Chat window is in the web UI; start it once the chat runs (stop and start it when it already ran).

python sdp.py webui start

What chat setup asks

  1. The back end (1: claude-code, 2: openai-compatible).
  2. For openai-compatible: the address and the model name.
  3. The secret (the token or the API key), asked once and without echo, as python sdp.py broker passwd asks its password. White space around it is dropped; it is refused when it is empty, longer than 4096 characters, or holds anything but visible ASCII characters (a space inside included).
  4. The soft cap of the chats’ work folder in GiB (a whole number from 1 to 10000, default 10).

On a second setup the earlier answers are the defaults. When a credential is already stored, setup first asks whether to replace it; the default keeps it and asks no secret. When you choose another back end than the saved one, that question is not asked and a new secret is required, because the stored one belongs to the other back end; the same holds when the settings are missing, cannot be read or name no back end, because then the stored secret’s back end is not known.

A refused address, model name or cap is asked again; a refused secret ends the setup with nothing saved. Setup refuses a deployment folder whose path holds a comma or a line break. At its start it removes a leftover temporary file (a regular file only) of the credential (model.token.<8 hex>.tmp, left by an interrupted write) from credential/.

Then it writes the settings and the credential and builds the two images (see The chat’s images). It ends with a summary (the back end, the address and model, the cap), names the command that starts the chat, and says that the Chat window is in the web UI (started, or restarted, with python sdp.py webui start once the chat runs). The secret and its length are never printed, logged, passed on a command line or put in an environment.

What it stores

Everything is under .sdp/chat/ in the deployment folder:

Path Mode What it holds
.sdp/chat/ 0700 The chat’s state
.sdp/chat/config.json 0600 The back end; for openai-compatible the address (upstream) and the model (model); the work folder’s cap (work_cap_gib); the Claude Code version of the sandbox image (claude_code_version)
.sdp/chat/credential/ 0700 The credential’s folder
.sdp/chat/credential/model.token 0600 The secret, and nothing else: a file only you can read
.sdp/chat/work/ 0700 The chats: one folder per chat, made by the runner (see A chat’s files); the sandbox’s /work
.sdp/chat/socket/ 0700 The sandbox’s /run/sdp-chat, which holds the runner’s socket runner.sock (0600) while the chat runs
.sdp/chat/gateway/ 0700 The gateway’s config (config.json, 0600), written by chat start and removed by chat stop; it holds no secret

The modes are set explicitly, whatever your umask. Each folder must be a real folder that belongs to you: a symbolic link or a folder of another user in its place is refused and left as it is. The settings and the secret are written to a temporary file made with mode 0600 and then renamed, so a file is never half written.

What chat start does

It refuses, with the command to run:

  • when the chat is not set up (the settings, the token file and both images must be there);
  • when Docker runs rootless or remaps user ids (the sandbox’s files would land on this machine owned by another user, and the gateway could not read your token);
  • when the chat already runs (stop it first);
  • when a container sdp-gateway or sdp-sandbox, or a network sdp-chat or sdp-chat-up, belongs to another deployment;
  • when Docker refuses or ignores the isolated gateway mode of the chat’s network: it then says that a newer Docker is needed (it never falls back to a plain internal network).

A container or network left by an earlier start that does not run is removed.

Which databases the chat reads. For each of postgres-mcp, mongo-mcp and starrocks-mcp, the running container of this deployment is attached only when its MCP server is on the database’s read-only user: its read-only user key (POSTGRES_MCP_USER, MCP_MONGODB_USER, STARROCKS_MCP_USER) has a value. Docker is asked only whether that key is set; nothing of the container’s environment, which holds passwords, is read or printed. A database is left out when its MCP server does not run, or is not on a read-only user. When no database can be attached, start refuses, names each database with its reason, says how to fix it (set the database up with authentication and a read-only user with python sdp.py db setup, its MCP server with python sdp.py db setup-mcp, and start it with python sdp.py db start), and makes nothing.

Then it makes the chat’s two networks, the gateway and the sandbox (the steps are in What chat start makes). When a step fails, start removes what it made (containers, networks, attachments, the gateway’s config) and says what failed. It ends with a summary: the back end, which databases the chat can read, for each one left out why, whether the query queue is attached (or one line saying why the assistant cannot use it), and that the Chat window is in the web UI (started, or restarted, with python sdp.py webui start). The token is never read, printed or passed by the command: the gateway reads it from its mounted file.

What you can ask

Ask about the data in your databases. Each question is one turn of the assistant, run in the chat’s own folder:

  • The databases. It reads each attached database through that database’s MCP server, read-only.
  • The shell and files. It can run shell commands and read and write files in the chat’s folder (with claude-code: the tools Bash, Read, Write, Edit, Glob and Grep; with openai-compatible: run_shell).
  • Plots. It saves plots as PNG files in its folder and names them in its answer; the Chat window shows them.
  • No internet. It cannot reach the internet.
  • Memory. The assistant remembers the chat: each later question continues the same conversation. A new chat starts from nothing.

The sandbox image has Python 3.13 with pandas, numpy, matplotlib and pyarrow. How each back end runs a turn is in What the sandbox runs.

The limits

Limit Value
Time of one turn 30 minutes; then the turn is ended (SDP_CHAT_TURN_SECONDS in the sandbox changes it)
Turns at once 2 in the sandbox, 1 per chat
Soft cap Before each turn the work folder is measured (without following a link); over the cap set at setup, the turn is refused until chats are deleted
Chats 200
A message 1 to 32,000 characters
A chat’s log 16 MiB (and one line per 32 bytes of that); then the chat is full and takes no more messages

A stopped turn, and one past its time limit, is ended with all its processes. With openai-compatible, a turn makes at most 40 model calls, and the end of a turn reports its time and number of model calls but no cost.

Files and plots

What the assistant writes lands in the chat’s folder, which you can download from the Chat window (see Files and plots) or find on this machine.

A chat’s files

A chat’s files are in .sdp/chat/work/<chat id>/ (a chat id is c_ and 12 hexadecimal digits):

Path What it holds
files/ The assistant’s working folder, where it writes its plots and other files
home/ The back end’s home: Claude Code’s session files and its mcp.json, or the agent’s openai-session.json
events.jsonl The chat’s log: your messages, the assistant’s text, each tool call and its result cut to 2,000 characters, each file that is new or changed in files/ after a turn, and the end of each turn with its cost, for Claude Code
meta.json When it was made, its title (the first message cut to 80 characters), its session id and its number of turns
backend.log The last turn’s error output of Claude Code or of the agent (at most 1 MiB)

The chats persist on this machine across chat stop and chat start. A deleted chat leaves the list at once and its files are removed in the background. chat unsetup removes all chats only when you say so.

The query queue

When the deployment’s query scheduler runs, the assistant can also submit long or heavy queries to its queue. A person approves each one in the Queue window of the web UI before it runs, and the assistant cannot approve it:

  1. The assistant submits a query and tells you the job id and that the query waits for your approval, then ends its turn instead of waiting.
  2. You approve it (or reject it) in the web UI’s Queue window, where it is labelled “Submitted by the chat’s assistant”. Its queries are never auto-accepted, whatever the target’s setting.
  3. In a later turn the assistant checks where the query stands, and fetches the parts of a finished result into the chat’s folder, where they show as the turn’s files. It can also withdraw one of its own queries while it is pending.

Only the assistant’s own queries are visible to it. The Chats page shows whether the queue is attached (the line “Query queue”).

When the queue is attached. chat start attaches it when the scheduler runs (its jobs container) and data/jobs/control is a real folder of yours without access for the group or others (the scheduler makes it). Otherwise start says so in one line, The assistant cannot use the query queue: <why>., and starts the chat without it: when the scheduler does not run, or the control folder is missing, open to others, a link or not yours, or JOBS_PORT is not a port number. A link or anything but a regular file of yours in the place of data/jobs/control/assistant.secret also starts the chat without the queue. How the queue is reached is in The assistant’s query queue.

The queue uses the port of the deployment’s settings (JOBS_PORT of .env, 8050 when it is not set): if the scheduler’s own configuration was edited by hand to another port, the assistant’s queue requests fail (the page’s published port is then wrong as well).

chat status says whether the queue is attached now (and shows it dropped when the scheduler’s container was replaced since the start); chat stop detaches the scheduler and removes the gateway’s copy of the secret; chat unsetup removes that copy with .sdp/chat/gateway/ and leaves data/jobs/control/assistant.secret, which belongs to the scheduler’s folder.

When a database drops out

A database is attached to the running container its MCP server had at start. When that container is replaced (by python sdp.py db stop and db start, a new db setup-mcp, or anything else that makes Compose create it anew), the new container is not attached and the chat can no longer read that database; chat status shows it as dropped. To bring it back:

python sdp.py chat stop
python sdp.py chat start

A database started after the chat is likewise attached only by a new start.

Stop, status and unsetup

  • python sdp.py chat stop stops and removes both containers, detaches every container from the chat’s two networks (whatever its state: a container left attached to a removed network could no longer start; one that is already gone is no error), and removes both networks, the gateway’s config and its copy of the scheduler’s secret. The exit code is 0 when the chat ran, 1 when nothing ran (what an earlier start left is removed then too) or something could not be removed. It refuses, and stops nothing, when a container or network of the chat’s names belongs to another deployment.
  • python sdp.py chat status says whether the gateway and the sandbox run, the back end, which databases the chat can read now (read from the members of sdp-chat-up by their compose service label, so a database whose container was replaced since the start shows as dropped, with the commands that bring it back), whether the query queue is attached now, and the work folder’s size: the sum of the sizes of its files, measured from this machine without following a link, against the soft cap set at setup. The walk stops after 1,000,000 entries and then says “more than”. Status says when the folder is over the soft cap; the runner refuses to start a new turn then. The exit code is 0 when both containers run, 1 otherwise.
  • python sdp.py chat unsetup says what it removes (the images sdp-gateway and sdp-sandbox, and .sdp/chat/config.json, .sdp/chat/credential/, .sdp/chat/socket/ and .sdp/chat/gateway/) and asks to confirm (default no). It then refuses, removing nothing, while a container of the chat exists for this deployment (stop it first with python sdp.py chat stop), and also when Docker cannot be asked. Then it asks separately whether to also delete all chats and their files (.sdp/chat/work/, default no). Leftover temporary files of an interrupted setup beside config.json go too, and .sdp/chat/ itself goes when nothing is left in it; when something else stayed in it, one line says how many entries stayed. Nothing is removed through a symbolic link (see How chat unsetup removes); what could not be removed is counted, and the command then exits with 1. A piece that is already gone is not an error.

Commands

Command What it does
python sdp.py chat setup Asks the back end, the address and model (openai-compatible), the secret (without echo; on a second setup only when you replace it) and the work folder’s soft cap; writes .sdp/chat/; builds the images sdp-gateway and sdp-sandbox. Exit code 0, or 1 with one line.
python sdp.py chat start Starts the gateway and the sandbox and attaches each database whose running MCP server is on a read-only user; refuses, saying why for each database, when none can be attached. Exit code 0, or 1 with the reason (what it made is removed).
python sdp.py chat stop Stops and removes both containers and networks and detaches the databases. Exit code 0, or 1 when nothing ran.
python sdp.py chat status Whether each container runs, the back end, the databases the chat can read now and those dropped since the start, the work folder’s size against its soft cap. Exit code 0 when both containers run.
python sdp.py chat unsetup After a confirmation, removes the two images, the settings and the credential; after a second one, also all chats and their files. Refused while the chat’s containers exist.