{"slug": "bonsai-a-toolkit-for-building-ai-chat-apps-with-branchable-conversations", "title": "Bonsai – a toolkit for building AI chat apps with branchable conversations", "summary": "Bonsai is a toolkit for building AI chat apps with branchable conversations, allowing users to explore tangents without derailing the original thread. The library, which is not a finished app but a developer embeddable tool, provides tree/branch/merge/distill logic plus swappable adapters for storage, LLM calls, and knowledge search. Bonsai requires Node >=20.11.0 and is currently in Phase 1 scaffold with no packages published yet.", "body_md": "**Bonsai is a toolkit for building chat apps where conversations with an AI don't have to stay a single, linear thread.**\n\nMost AI chat apps force every conversation down one straight line: you ask, it answers, you ask again, and the whole history piles up in order. If you want to explore a tangent — \"what if we tried a different approach?\" — you either derail the conversation or start over from scratch and lose the context you'd already built up.\n\nBonsai lets a conversation branch. From any point in a chat, you can branch off to explore an idea, without disturbing the original thread. If the branch turns out useful, you can merge a summary of it back into the main conversation. If it's a dead end, you just abandon it — nothing about it leaks back in. And when a conversation (or a branch) produces something worth keeping long-term, you can distill it into a wiki page that future conversations can draw on, instead of re-explaining it every time.\n\nCrucially, Bonsai never does any of this automatically behind your back. Branching, merging, and distilling are all actions your app's user explicitly takes — and at every step, Bonsai can show you exactly what information was assembled and sent to the model for a given reply, so \"why did the AI say that?\" always has a concrete answer.\n\nBonsai is **not** a finished chat app you install and open in a browser — it's a library that developers embed *into* their own product. If you're building a chat-based app (a support tool, a research assistant, an internal copilot) and want branching, mergeable context, and durable memory as building blocks, Bonsai gives you the underlying pieces — the tree/branch/merge/distill logic, plus swappable adapters for where you store data, which LLM you call, and how you search past knowledge — so you don't have to build that plumbing yourself.\n\n**Tree Model**— every project starts as one`main`\n\nbranch; branching off at any message creates a new branch that can be explored independently.**ContextPacket**— before (or instead of) sending a prompt to the model, you can inspect the exact packet of messages, merges, and wiki pages that would be included — no hidden retrieval step.**Merge**— land a reviewed summary of a branch back onto its parent branch, as an explicit, user-approved action.** Distill**— turn a branch or merge's transcript into a durable Markdown wiki page that later conversations can retrieve.** Wiki**— the durable, human-readable knowledge base distill writes into: plain Markdown files with frontmatter, easy to read, grep, or back up outside of Bonsai entirely.**Retrieval**— a pluggable interface for searching that wiki (full-text search out of the box; embeddings-based search can be swapped in later).\n\nRead the [Concepts](/Joaoha/Bonsai/blob/main/docs/src/content/docs/concepts) pages or the [docs site](/Joaoha/Bonsai/blob/main/docs) for the full explanation of each, or the [Quickstart](/Joaoha/Bonsai/blob/main/docs/src/content/docs/quickstart.mdx) for a working example.\n\nA Bonsai project, built on `@bonsai/core`\n\n: the branch graph on the right shows `main`\n\nwith three branches (`i-like-dogs`\n\n, `i-like-hotdogs`\n\n, `i-loke-motorb...`\n\n) explored independently, two of them already merged back with a reviewed summary and a one-click \"Distill to Wiki\" action, while the chat on the left only ever sees `main`\n\n's own history plus what was explicitly merged into it:\n\nPhase 1 scaffold. No package is published yet.\n\n```\npackages/\n  core/              # @bonsai/core — framework-agnostic domain (Storage/LLMProvider/WikiStore/Retriever interfaces)\n  storage-postgres/  # @bonsai/storage-postgres — Postgres migrations + repositories + FTS retriever\n  provider-openai/   # @bonsai/provider-openai — OpenAI-compatible chat/streaming provider\n  wiki-fs/           # @bonsai/wiki-fs — Markdown-on-disk WikiStore\n  server/            # @bonsai/server — thin optional HTTP layer\nexamples/            # example embedders (added in later phases)\n```\n\n- Node\n`>=20.11.0`\n\n- pnpm\n`9.15.4`\n\n(pinned via`packageManager`\n\n)\n\n```\npnpm install              # install workspace dependencies\npnpm typecheck            # tsc -b across all packages via project references\npnpm build                # build all packages that define a build script\npnpm test                 # run tests across the workspace\npnpm lint                 # ESLint (incl. `no-restricted-imports` boundary rules on packages/core)\npnpm depcruise            # dependency-cruiser — forbid core -> adapter imports\npnpm boundary:verify      # positive test: fixture must be rejected by lint + depcruise\npnpm publint              # publint --strict per package (release gate)\npnpm attw                 # arethetypeswrong per package (release gate, ESM-only profile)\npnpm release:gate         # build + publint + attw (run before publishing)\npnpm changeset            # add a changeset entry for a release\npnpm changeset:status     # show pending changesets\npnpm docs:dev             # run the docs site locally (Astro Starlight)\npnpm docs:build           # build the static docs site under docs/dist\npnpm docs:preview         # preview a built docs site\n```\n\nPublic documentation lives under [ docs/](/Joaoha/Bonsai/blob/main/docs) as its own pnpm workspace package (\n\n`@bonsai/docs`\n\n, private), built with Astro Starlight. The API Reference is auto-generated from each package's `src/index.ts`\n\nvia TypeDoc + `starlight-typedoc`\n\n. Landing page, quickstart, concept pages, and recipes are verified against the current `@bonsai/*`\n\nAPI surface.`@bonsai/core`\n\nis framework- and adapter-agnostic by contract. Two layers defend that boundary:\n\n**ESLint**(scoped to`no-restricted-imports`\n\n`packages/core/**`\n\n) bans`react`\n\n,`react-dom`\n\n,`next/*`\n\n,`tailwindcss`\n\n,`pg`\n\n/`postgres`\n\n/`sqlite*`\n\n,`fs`\n\n/`node:fs`\n\n,`net`\n\n, node http clients, and provider SDKs.**dependency-cruiser** forbids`packages/core → packages/{storage-*, provider-*, wiki-fs, server}`\n\n(both by resolved path and by`@bonsai/*`\n\nmodule name).\n\n`pnpm boundary:verify`\n\nruns both tools against intentional violation fixtures under `packages/core/src/__fixtures__/`\n\nand fails if either tool accepts them. CI runs it on every push/PR.", "url": "https://wpnews.pro/news/bonsai-a-toolkit-for-building-ai-chat-apps-with-branchable-conversations", "canonical_source": "https://github.com/Joaoha/Bonsai", "published_at": "2026-07-24 23:52:26+00:00", "updated_at": "2026-07-25 00:22:20.704809+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "large-language-models", "generative-ai"], "entities": ["Bonsai", "@bonsai/core", "Node"], "alternates": {"html": "https://wpnews.pro/news/bonsai-a-toolkit-for-building-ai-chat-apps-with-branchable-conversations", "markdown": "https://wpnews.pro/news/bonsai-a-toolkit-for-building-ai-chat-apps-with-branchable-conversations.md", "text": "https://wpnews.pro/news/bonsai-a-toolkit-for-building-ai-chat-apps-with-branchable-conversations.txt", "jsonld": "https://wpnews.pro/news/bonsai-a-toolkit-for-building-ai-chat-apps-with-branchable-conversations.jsonld"}}