feat(skills): explain nanobot usage from bundled documentation (#6176)

* feat(skills): add nanobot documentation guide with bundled docs

* docs: prefer graphical setup and align bundled guides with runtime

* docs: lead provider setup with built-in endpoint defaults

* fix: preserve documentation packaging and lookup across install paths

* fix(skills): narrow documentation loading to relevant sections

* refactor(skills): keep documentation guidance concise

* fix(docs): complete first-use workflows and clarify runtime boundaries

* style(docs): remove manual paragraph wrapping

* docs: guide first-run users to conversational setup help

* docs: fold README installation alternatives and details

* docs: separate README alert marker from its body

* docs: clarify README onboarding and runtime boundaries
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-13 00:44:25 +08:00
1 parent 23941355a8
commit cd2a863710
61 files changed
+1729 -634

No files matched your search

+33 -17
View File
@@ -30,19 +30,7 @@ python -m pip install nanobot-ai
`Nanobot.from_config()` reuses your normal `~/.nanobot/config.json` and `~/.nanobot/workspace/`. Provider, model, tools, memory, and session behavior match the CLI unless you override them. For the difference between config and workspace, see [Concepts: Config vs Workspace](concepts.md#config-vs-workspace).
Before writing SDK code, run the same first-run checks from the main [Install and Quick Start](quick-start.md):
```bash
nanobot status
```
`nanobot status` should show the config path, workspace path, active model or preset, and provider summary. Then send one real message:
```bash
nanobot agent -m "Hello!"
```
A normal assistant reply means install, config, provider/model selection, and workspace access are all usable. Once that works, the SDK should see the same runtime.
If you have already received a normal reply in the WebUI, use that saved configuration directly. For a separate Python environment, `nanobot status` shows which config, workspace, and model the SDK will load.
## 5-Minute Quick Start
@@ -67,6 +55,17 @@ Use `async with` when possible so tool connections and background cleanup are cl
The SDK is async-first because agent runs may stream tokens, execute tools, and wait on external services. In a normal Python script, wrap your async function with `asyncio.run(...)` as shown above. In a notebook or another async app, call `await bot.run(...)` directly from your existing event loop.
The default agent workspace comes from config, not the notebook's current directory. For a notebook that should use its current folder as both file workspace and agent state, choose it explicitly:
```python
from pathlib import Path
async with Nanobot.from_config(workspace=Path.cwd()) as bot:
result = await bot.run("List the files in this workspace.")
```
This also places memory and skills in that workspace. Use a separate configured instance when notebook experiments must not share existing agent state.
### Inspect What Happened
`bot.run(...)` returns a `RunResult`, not just a string:
@@ -82,7 +81,7 @@ print(result.stop_reason) # why the run stopped
### Continue A Conversation
Use a `session_key` when you want history to carry across turns. Different session keys are isolated from each other:
Use a `session_key` when you want history to carry across turns. Different session keys keep separate conversation histories:
```python
await bot.run("My name is Alice.", session_key="user:alice")
@@ -91,7 +90,7 @@ result = await bot.run("What is my name?", session_key="user:alice")
print(result.content)
```
This is the SDK equivalent of giving each user, task, eval case, or workflow its own conversation thread.
This gives each task or workflow its own conversation thread. Keys do not isolate workspace files, tools, credentials, or long-term memory: sessions in one agent workspace share `USER.md`, `SOUL.md`, and `memory/MEMORY.md`. For separate users or tenants, use separate configured instances and appropriate process/file permissions; see [Multiple Instances](multiple-instances.md).
### Stream A Long Answer
@@ -109,7 +108,7 @@ Streaming returns structured events, so you can also observe tool calls, reasoni
## Complete Starter Script
Save this as `sdk_demo.py` after `nanobot agent -m "Hello!"` works:
Save this as `sdk_demo.py` after your configured model has returned a normal reply:
```python
import asyncio
@@ -260,7 +259,7 @@ result = await bot.run("Think deeply about this bug", model_preset="reasoning")
`model` and `model_preset` are mutually exclusive.
For first setup, prefer named presets in `config.json`. Mixing an API key from one provider with a model ID from another is the most common first-run failure. For the exact difference between `provider`, `model`, `apiKey`, and `apiBase`, see [Providers: Provider, Model, API Key, and Base URL](providers.md#provider-model-api-key-and-base-url). If a run fails before the SDK does anything interesting, confirm the same provider and model work with `nanobot agent -m "Hello!"` first.
For first setup, create named presets in **Settings → Models**; the SDK reads those saved presets from `config.json`. Mixing an API key from one provider with a model ID from another is the most common first-run failure. For the exact difference between `provider`, `model`, `apiKey`, and `apiBase`, see [Providers: Provider, Model, API Key, and Base URL](providers.md#provider-model-api-key-and-base-url). If a run fails before the SDK does anything interesting, confirm the same provider and model work with `nanobot agent -m "Hello!"` first.
### Isolate conversations with `session_key`
@@ -381,6 +380,23 @@ result = await bot.run(
print(result.content)
```
### Persist memory in a short-lived script
Saved session history and curated long-term memory are different. The SDK does not start the gateway scheduler, so creating or closing `Nanobot` does not schedule Dream. Compaction archives a conversation into `memory/history.jsonl`; it does not itself update `USER.md` or `memory/MEMORY.md`.
Before closing a script that should contribute material to Dream:
```python
async with Nanobot.from_config() as bot:
await bot.run("For release notes, use concise bullet points.", session_key="sdk:notes")
await bot.runtime.compact_session("sdk:notes")
print(bot.memory.read_history(session_key="sdk:notes"))
```
Then use `/dream` in a running WebUI or TUI connected to the same configured agent workspace, wait for completion, and inspect `/dream-log`. Scheduled Dream also processes this archive while the matching gateway runs and Dream is enabled. `await bot.run("/dream")` only returns the command acknowledgement; it is not an awaited Dream-completion API for short-lived scripts.
For application-owned durable text, `bot.memory.write(text)` writes `memory/MEMORY.md` directly and `bot.memory.read()` reads it back. Writing replaces the whole file; it does not merge preferences or create a Dream audit entry. See [Memory](memory.md) for review and correction workflows.
### Attach hooks for observability
Hooks are an advanced escape hatch. Use them when you want custom logging, metrics, tracing, or output post-processing without modifying nanobot internals: