docs: improve readability and remove internal technical details from user docs (#6725)

* docs: improve readability and remove internal technical details from user docs

* docs: expand user-doc cleanup to remote instances, deployment, providers, MCP presets, my-tool, and add concept diagrams

* docs: streamline root README and SECURITY guide for readability

* docs: move Why nanobot before Start Here and highlight lightweight footprint and WebUI
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-19 16:48:17 +08:00
1 parent 2ca8b72eea
commit 607de63fb4
20 files changed
+1002 -2426

No files matched your search

+80 -124
View File
@@ -1,99 +1,75 @@
# Concepts
Use this page when you want to understand nanobot before changing advanced settings. It explains the moving parts without requiring you to read the source first.
This page explains how nanobot's main pieces fit together in plain language, so you can configure models, workspaces, memory, and automations with confidence.
If you want source-file ownership and extension points, read [`architecture.md`](./architecture.md) after this page.
For source-code structure and contributor details, see [Architecture](./architecture.md).
## Runtime Shape
## Main Building Blocks
nanobot has one small core loop and several ways to enter it:
```mermaid
flowchart LR
U["WebUI / Terminal / Chat Apps"] --> G["Gateway"]
G --> A["Agent"]
A --> P["AI Provider"]
A --> T["Tools (Files, Shell, Web, MCP)"]
A --> M["Workspace & Memory"]
```
| Part | What it does |
|---|---|
| Agent | Takes an incoming message, chooses the conversation and model, uses enabled tools when needed, and prepares a reply |
| Providers | LLM backends such as OpenRouter, Anthropic, OpenAI, Bedrock, Ollama, vLLM, and other OpenAI-compatible APIs |
| Channels | User-facing transports such as CLI, WebUI/WebSocket, Telegram, Discord, Slack, Feishu, WeChat, Email, Mattermost, and others |
| Tools | Capabilities the model may call, including files, shell, web search/fetch, MCP, cron, image generation, and subagents |
| Memory | Workspace files and session history that keep useful context across turns |
| Gateway | Long-running process that connects enabled channels and serves the health endpoint |
| Agent | Reads your message and conversation context, runs enabled tools when needed, and writes the reply |
| Providers | AI services or local servers (OpenRouter, Anthropic, OpenAI, Bedrock, Ollama, vLLM, and more) |
| Channels | Ways to talk to nanobot: WebUI, terminal (CLI/TUI), Telegram, Discord, Slack, Feishu, WeChat, Email, Mattermost, Linear, and others |
| Tools | Capabilities the agent can use, such as files, shell commands, web search, MCP servers, image generation, automations, and subagents |
| Memory | Saved conversation history and long-term workspace notes that carry context forward |
| Gateway | The background service that keeps the WebUI, chat apps, and automations running |
To test nanobot once, run `nanobot agent -m "Hello!"`; it prints a reply in your terminal. To keep nanobot running, start `nanobot gateway`. It receives messages from enabled chat apps or the WebUI and sends replies back to the same conversation.
To send a single test message, run `nanobot agent -m "Hello!"`. For everyday use with the WebUI, chat apps, or scheduled tasks, nanobot runs the gateway in the background.
## Config vs Workspace
The default instance lives under `~/.nanobot/`:
By default, everything lives under `~/.nanobot/`:
| Path | Meaning |
| Path | What it stores |
|---|---|
| `~/.nanobot/config.json` | Instance configuration: providers, model defaults, channels, tools, gateway, API, and runtime options |
| `~/.nanobot/workspace/` | Agent workspace: memory, heartbeat tasks, cron jobs, skills, and generated artifacts |
| `~/.nanobot/sessions/<workspace-id>/` | Session history stored outside the agent-accessible workspace; the opaque ID follows workspace moves |
| `~/.nanobot/config.json` | Settings: providers, model presets, channels, tools, and security options |
| `~/.nanobot/workspace/` | Agent state: long-term memory, skills, `HEARTBEAT.md`, automations, and generated files |
| `~/.nanobot/sessions/` | Saved conversation history (stored separately from the workspace) |
You can override both with command flags:
```bash
nanobot onboard --config ./bot-a/config.json --workspace ./bot-a/workspace
nanobot agent --config ./bot-a/config.json --workspace ./bot-a/workspace -m "Hello"
nanobot gateway --config ./bot-a/config.json --workspace ./bot-a/workspace
```
The config file controls what nanobot may use. The workspace is where nanobot keeps state for that instance.
The **config file** controls what nanobot is allowed to use. The **workspace** holds the agent's durable state. You can point commands at a different config or workspace with `--config` and `--workspace` (or `--home`; see [Multiple Instances](./multiple-instances.md)).
### Agent Workspace and Project Workspace
The configured workspace is the **agent workspace**. A WebUI chat can also select a different **project workspace** for repository-specific work without moving the agent's identity or durable state.
Your configured workspace is the **agent workspace**. In the WebUI, you can also pick a different **project workspace** (such as a code repository) for a specific topic without changing your agent's identity or memory:
| Resource | Owner when a project is selected |
| What | Comes from |
|---|---|
| Project instructions | `AGENTS.md` from the selected project; there is no fallback to the agent workspace's `AGENTS.md` |
| Agent profile | `SOUL.md` and `USER.md` from the agent workspace; project-local files with those names are ignored |
| Memory and custom skills | `memory/` and `skills/` from the agent workspace |
| Relative file paths and shell working directory | The selected project workspace |
| Project instructions (`AGENTS.md`) | The selected project folder |
| Agent personality and user profile (`SOUL.md`, `USER.md`) | The agent workspace |
| Long-term memory and custom skills (`memory/`, `skills/`) | The agent workspace |
| Relative file paths and shell commands | The selected project folder |
When no separate project is selected, one directory normally serves both roles. Selecting a project changes the working context for that chat; it does not create a second agent or relocate the configured agent workspace.
When you do not pick a separate project, both roles use the same directory. Picking a project changes where the agent works for that topic; it does not create a separate agent or separate memory.
## Config Format
## Entry Points: CLI, WebUI, and Gateway
`config.json` accepts both camelCase and snake_case keys. The docs use camelCase because nanobot writes config back to disk with camelCase aliases, for example `apiKey`, `modelPresets`, `intervalS`, and `maxToolResultChars`.
Most examples are partial snippets. Merge them into the existing file created by `nanobot onboard`; do not replace the whole file unless you want to reset the instance.
## One Agent Turn
A normal turn follows this flow:
1. The CLI, WebUI, or a connected chat app receives your message.
2. nanobot uses the conversation's history and the files available to that chat to prepare the request.
3. Your selected AI service generates a response. If it needs an enabled tool, nanobot runs that tool and returns the result to the model.
4. nanobot saves the reply in the conversation and shows or sends it through the same app or channel.
That flow is the same whether the message starts in the CLI, WebUI, Telegram, Discord, or another channel.
## CLI, Gateway, API, and WebUI
| Entry point | Command | Use it for |
| Entry point | Command | Best for |
|---|---|---|
| CLI one-shot | `nanobot agent -m "..."` | First-run checks, scripts, and quick local questions |
| CLI interactive | `nanobot agent` | Terminal chat with persistent session history |
| Gateway | `nanobot gateway` | Chat apps, WebUI, heartbeat, Dream, and long-running service mode |
| WebUI | `nanobot webui` | Prepare the local WebUI, start the gateway, and open the browser workbench |
| One-shot CLI | `nanobot agent -m "..."` | Quick checks, scripts, and troubleshooting |
| Interactive CLI / TUI | `nanobot` (or `nanobot agent`) | Terminal chat with saved session history |
| WebUI | `nanobot webui` | Everyday browser workbench (starts the gateway automatically) |
| Gateway | `nanobot gateway` | Headless servers, chat apps, and background automations |
The WebUI launcher is the normal browser entry point. Underneath, the gateway keeps the WebSocket channel and other long-running services alive. The gateway health endpoint is on `gateway.port` (`18790` by default); the browser WebUI is served on `8765` by default, not by the health endpoint.
The WebUI runs on port `8765` by default (`http://127.0.0.1:8765`). The gateway health check runs on port `18790` (`http://127.0.0.1:18790/health`).
## Provider and Model Selection
## Providers and Model Presets
Choose and configure the primary model in **Settings → Models**, then select its preset in the chat composer. The config-file example below is an alternative for deployment-managed settings.
Configure your providers and models in **Settings → Models**, then pick a preset from the chat composer.
The active model should normally come from a named `modelPresets` entry selected by `agents.defaults.modelPreset`. Direct `agents.defaults.provider` and `agents.defaults.model` still form the implicit `default` preset for older or minimal configs. The active provider is resolved in this order:
1. If the active preset provider or implicit default provider is not `"auto"`, nanobot uses that provider.
2. If provider is `"auto"`, nanobot tries to infer the provider from the model name, configured API keys, local provider base URLs, or gateway providers.
3. OAuth providers such as OpenAI Codex and GitHub Copilot require explicit login and explicit provider/model selection inside the active preset.
Pin the provider inside the preset when setting up for the first time. It is easier to debug:
A **model preset** pairs a provider with a model ID (and optional settings). Pinning the provider explicitly inside each preset is the easiest way to avoid setup mistakes. OAuth providers (such as OpenAI Codex, xAI Grok, and GitHub Copilot) require signing in first and selecting that provider in your preset.
<details>
<summary>Manual configuration</summary>
<summary>Manual configuration example</summary>
```json
{
@@ -113,88 +89,68 @@ Pin the provider inside the preset when setting up for the first time. It is eas
</details>
See [`providers.md`](./providers.md) for practical examples and [`configuration.md#providers`](./configuration.md#providers) for the full provider reference.
See [Providers and Models](./providers.md) and the [Provider Cookbook](./provider-cookbook.md) for provider-specific setup.
## Channels and Sessions
## Sessions, Memory, and Dream
By default, each channel and chat has its own session and conversation history. The WebUI also supports multiple chats and workspace-scoped metadata for project workspaces.
nanobot separates short-term chat history from long-term memory:
## Memory, Sessions, and Dream
- **Sessions** keep the messages of each conversation. By default, each WebUI topic and each chat-app thread has its own session.
- **Long-term memory** lives in your agent workspace (`SOUL.md`, `USER.md`, `memory/MEMORY.md`, and optional `memory/wiki/` pages).
- **Dream** is a periodic background job that reviews summarized conversations and updates your long-term memory so important preferences and facts carry across topics.
nanobot uses two related stores:
See [Memory](./memory.md) for how memory works and how to inspect or restore it.
| Store | Location | Purpose |
|---|---|---|
| Sessions | `<config-dir>/sessions/<workspace-id>/sessions.sqlite3` | Recent conversation turns replayed into context |
| Memory | `<workspace>/memory/MEMORY.md` and `<workspace>/memory/history.jsonl` | Long-term facts and consolidated history |
## Apps, Plugins, and Skills
Dream is a periodic consolidation job. It reads accumulated history and updates workspace memory so useful context can survive beyond short session replay.
You can extend nanobot from the **Apps** and **Skills** pages in the WebUI:
The configured workspace contains a `.nanobot/workspace-id` file. It contains only an opaque random identifier—never conversation content or credentials. Keep it with workspace backups: it lets nanobot find the same external session namespace after the workspace is renamed, moved, or restored. A live copy opened alongside the original receives a new ID so the two workspaces do not share conversations accidentally.
See [`memory.md`](./memory.md) for the detailed design.
## Apps and Agent Plugins
Agent Plugins are installable packages that help you add and manage capabilities in nanobot. A package can include one or more of these:
| Part | Role |
| Concept | What it does |
|---|---|
| Agent Plugin | Installable package that can bundle skills, MCP servers, or both |
| Skill | Workflow guidance loaded progressively or invoked with `$skill-name` |
| MCP server | Runtime tools exposed to the agent |
| CLI App | Locally managed executable whose adapter is packaged and activated like a plugin |
| Apps | WebUI surface for reviewing and managing these capabilities |
| Agent Plugin | An installable package that bundles skills, MCP servers, or both |
| Skill | Reusable instructions loaded when relevant or invoked with `$skill-name` |
| MCP server | External tools exposed to the agent over Model Context Protocol |
| CLI App | A local command-line tool adapter managed from **Apps** |
Native providers, channels, built-in tools, standalone workspace skills, and directly configured MCP servers keep their existing extension paths. See [`webui.md#apps`](./webui.md#apps) for the user-facing flow and [`configuration.md#agent-plugins-v1`](./configuration.md#agent-plugins-v1) for the package contract.
See [WebUI Apps](./webui.md#apps) and [Skills](./webui.md#skills) to manage them.
## Tools and Safety
nanobot can use built-in tools and tools enabled through Apps. Common tool groups include:
nanobot includes built-in tools for files, shell commands, web search/fetch, image generation, automations, and subagents, plus any tools added through **Apps**.
- file read/write/edit and patching;
- shell execution with configurable sandboxing;
- web search and web fetch with SSRF checks;
- MCP servers;
- cron reminders, local triggers, and heartbeat tasks;
- image generation;
- subagents and runtime self-inspection.
Security-sensitive controls live in [`configuration.md#security`](./configuration.md#security). For production or shared chat apps, also configure channel access controls such as `allowFrom`, pairing, or WebSocket tokens.
- In the WebUI, use **Restricted** mode to keep file and shell work inside the selected workspace.
- For chat apps, use pairing or `allowFrom` allowlists so only people you approve can talk to your bot.
- For tighter restrictions, sandboxing, and network rules, see [Configuration: Security](./configuration.md#security).
## Subagents
Nanobot can delegate parts of a request to subagents while remaining responsible for the final answer. In the conversation that started the work, you can ask it to check progress, send follow-up instructions, wait for results, or cancel a task. Cancelling one task leaves the others running. A delivered instruction means the subagent received it, not that it has acted on it yet.
nanobot can delegate parts of a complex request to subagents while staying responsible for your final answer. Inside the same conversation, you can ask it to check progress, send follow-up instructions, wait for results, or cancel a specific subtask.
Background tasks return their results to the conversation that started them. Single-turn CLI and SDK calls wait for results when background delivery is unavailable. Tasks that reach their iteration limit are marked incomplete; cancelled, failed, and incomplete tasks retain available partial results.
- Background subtasks report back to the conversation that started them.
- `/stop` stops the current session and its subagents without affecting other sessions (it does not undo file changes already made).
- Subagents belong to their parent conversation: deleting that conversation stops and removes them, and forking does not copy them.
- If the gateway restarts while a subtask is running, unfinished subtasks are marked interrupted with any partial results saved; ask nanobot to start a new task if you want to continue.
- Subagents are not available in WebUI temporary chats.
Use `/stop` to stop the current session and its subagents. Other sessions are unaffected. Some operations may take time to stop, and cancellation does not undo file changes or other actions already taken.
See [Delegated work](./webui.md#delegated-work) for viewing subtasks in the WebUI.
Subagents belong to their original conversation. They do not appear as separate topics or in general conversation searches. Deleting the conversation stops its subagents and removes their saved history; forking it does not copy them.
## Automations and Background Jobs
Saved task history and results remain available after a gateway restart. Unfinished tasks are marked interrupted, with saved partial results when available. Nanobot does not automatically resume them or resend completion notifications; ask it to start a new task to continue the work.
While the gateway is running, nanobot can act on its own in three ways:
See [Delegated work in the WebUI](./webui.md#delegated-work) for progress and task details. WebUI temporary chats do not support subagents. SDK calls with `ephemeral=True` wait for delegated results without saving the temporary conversation or its subagent history.
- **Scheduled automations:** Tasks you ask nanobot to run at a specific time or on a schedule, replying back in the same chat.
- **Local triggers:** Created with `/trigger <name>` so a local script or webhook can wake nanobot in that chat with `nanobot trigger <id> "<message>"`.
- **Heartbeat:** A quiet periodic check driven by `<workspace>/HEARTBEAT.md` that only messages you when something needs attention.
## Background Jobs
When `nanobot gateway` starts, it runs workspace-scoped automations and registers system jobs:
- `dream`, when `agents.defaults.dream.enabled` is true;
- `heartbeat`, when `gateway.heartbeat.enabled` is true.
Heartbeat reads `<workspace>/HEARTBEAT.md`. If the file has tasks under `## Active Tasks`, nanobot executes them and sends only useful/actionable results to the most recently active chat target. Routine "nothing changed" results are suppressed.
User-created reminders use the same cron service but are not the same as the protected heartbeat system job. They run as scheduled turns in their origin chat/session and normally deliver the result back to that channel.
Local triggers are also session-bound, but they do not have their own schedule. Create one from the target chat with `/trigger <name>`, then call `nanobot trigger <id> "<message>"` when a local script or external service wants nanobot to respond in that session. Webhook servers, third-party auth, and event-to-message formatting stay outside nanobot. Trigger deliveries are stored in the workspace until the linked agent turn finishes successfully. If the target session is busy, the trigger waits until that session is idle instead of being injected into the active turn. The message is recorded as an automation turn in that session. Delivery is at-least-once, so external systems should tolerate repeated trigger messages; a delivery that reaches the agent but fails is marked failed rather than retried forever.
See [Automations](./automations.md) for the full guide.
## Where to Go Next
| Need | Read |
|---|---|
| First working install | [`quick-start.md`](./quick-start.md) |
| Provider/model setup | [`providers.md`](./providers.md) |
| Chat app setup | [`chat-apps.md`](./chat-apps.md) |
| Complete config reference | [`configuration.md`](./configuration.md) |
| Runtime debugging | [`troubleshooting.md`](./troubleshooting.md) |
| First working install | [Install and Quick Start](./quick-start.md) |
| Browser workbench | [WebUI](./webui.md) |
| Provider and model setup | [Providers and Models](./providers.md) |
| Chat app setup | [Chat Apps](./chat-apps.md) |
| Complete config reference | [Configuration](./configuration.md) |
| Runtime debugging | [Troubleshooting](./troubleshooting.md) |