docs(sdk): document Nanobot teardown

This commit is contained in:
Xubin Ren 2026-06-06 15:29:13 +08:00
parent 57fa37dcfe
commit 73353785a0

View File

@ -11,8 +11,8 @@ from nanobot import Nanobot
async def main() -> None:
bot = Nanobot.from_config()
result = await bot.run("What time is it in Tokyo?")
async with Nanobot.from_config() as bot:
result = await bot.run("What time is it in Tokyo?")
print(result.content)
@ -21,6 +21,8 @@ asyncio.run(main())
`Nanobot.from_config()` reuses your normal `~/.nanobot/config.json`, so the SDK follows the same provider, model, tools, and workspace defaults as the CLI unless you override them.
Use `async with` when possible so MCP connections and background cleanup work are closed before the event loop exits. If you manage the instance manually, call `await bot.aclose()` in a `finally` block.
## Common Patterns
### Use a specific config or workspace
@ -83,6 +85,15 @@ Run the agent once and return a `RunResult`.
| `session_key` | `str` | `"sdk:default"` | Session identifier for conversation isolation. Different keys get independent history. |
| `hooks` | `list[AgentHook] \| None` | `None` | Lifecycle hooks for this run only. |
### `await bot.aclose()`
Release resources held by the SDK instance, including MCP connections. The async context manager calls this automatically:
```python
async with Nanobot.from_config() as bot:
result = await bot.run("Summarize this repo")
```
### `RunResult`
| Field | Type | Description |