AIToday

Bonsai: branching-conversation toolkit for AI chat apps

Hacker News6h ago
Bonsai: branching-conversation toolkit for AI chat apps

Key takeaway

Bonsai is an open-source toolkit that lets developers build AI chat applications with branching conversations—a feature most existing chat apps lack. Rather than forcing all exchanges into a single linear thread, Bonsai allows users to branch off to explore ideas independently, then merge summaries back or discard dead ends, while maintaining a durable wiki of distilled knowledge. The project is currently in early development and has not yet released packages.

Summaries like this, in your inbox every morning.

Sign up free →

3 Key Points

  • What happened

    Bonsai is a developer toolkit for building chat applications where conversations can branch off into independent threads, merge summaries back into the main conversation, and distill transcripts into a searchable wiki—all as explicit user actions, with full visibility into what context the AI receives at each step.

  • Why it matters

    Most AI chat apps lock users into a single linear conversation thread, forcing a choice between derailing the conversation or starting over. Bonsai lets developers give users the ability to explore tangents without losing prior context, and to build persistent, reusable knowledge from past conversations—solving a friction point in how people collaborate with AI.

  • What to watch

    The project is currently in Phase 1 scaffold with no package published yet. It includes framework-agnostic core logic plus adapters for Postgres storage, OpenAI-compatible providers, and filesystem-based wikis; the docs site is built with Astro Starlight and the codebase enforces strict boundary rules to keep the core adapter-independent.

In Depth

Bonsai is an open-source toolkit designed to let developers embed branching-conversation logic into chat-based applications. The problem it solves is structural: conventional AI chat apps force every exchange into a single, linear thread of messages. If a user wants to explore a tangent—say, "what if we tried a different approach?"—they either disrupt the main conversation or start over and lose the context they have already built up. Bonsai removes that false choice by allowing conversations to branch.

The toolkit introduces four core concepts. Tree Model makes every project start as one main branch; from any message, a user can branch off to explore an idea independently without touching the main thread. ContextPacket is a crucial transparency feature: before sending a prompt to the model, developers can inspect the exact set of messages, merged summaries, and wiki pages that will be included in the request—with no hidden retrieval step. This makes the model's input fully auditable. Merge is an explicit, user-reviewed action that lands a branch's summary back onto its parent branch. Distill converts a branch or merge transcript into durable Markdown wiki pages that future conversations can retrieve, building a reusable knowledge base instead of requiring re-explanation. The Wiki itself is a plaintext Markdown knowledge base with frontmatter, designed to be human-readable, greppable, and easily backed up outside Bonsai entirely. Retrieval provides a pluggable search interface over that wiki, with full-text search built in and support for embeddings-based search in later phases.

Bonsai is not a finished chat app but a library for developers. It is aimed at teams building chat-based products—support tools, research assistants, internal copilots—who want branching, mergeable context, and durable memory as foundational features. The toolkit provides the tree/branch/merge/distill logic and swappable adapters for data storage, LLM calls, and knowledge search, so teams do not have to build that infrastructure themselves. Crucially, branching, merging, and distilling are never automatic; all three are explicit, user-approved actions, ensuring that what the model sees is always predictable and transparent.

The codebase is organized into several packages. @bonsai/core is the framework-agnostic domain layer, defining interfaces for Storage, LLMProvider, WikiStore, and Retriever. Adapters include @bonsai/storage-postgres (Postgres storage with full-text-search retrieval), @bonsai/provider-openai (OpenAI-compatible chat and streaming), and @bonsai/wiki-fs (Markdown files on disk). An optional @bonsai/server provides a thin HTTP layer. The project enforces strict architectural boundaries: ESLint rules ban framework-specific imports (React, Next.js, Tailwind, Node filesystem/network modules, and provider SDKs) from core, and dependency-cruiser forbids core from importing adapter code. A boundary-verification test suite in CI ensures these rules hold on every push and pull request. The project is currently in Phase 1 scaffold with no packages published yet. Prerequisites are Node ≥20.11.0 and pnpm 9.15.4. Documentation is built with Astro Starlight and auto-generates API references from TypeScript source via TypeDoc. The codebase is released under the MIT license.

Context & Analysis

Bonsai addresses a fundamental friction in how people use AI chat applications: the enforced linearity of conversation history. Existing chat tools present a simple model—messages accumulate in order, and exploring a tangent either hijacks the thread or requires starting fresh—which mirrors single-threaded conversation with a human but poorly matches how people actually explore ideas collaboratively. By making branching, merging, and knowledge distillation explicit user actions rather than automatic behind-the-scenes operations, Bonsai gives developers a foundation for chat-based tools (support systems, research assistants, internal copilots) that match the exploratory, nonlinear nature of real problem-solving.

The toolkit is designed with developer ergonomics and transparency in mind. The ContextPacket feature—which lets developers inspect exactly what messages, summaries, and wiki pages will be sent to the model before a reply is generated—directly addresses a key user pain point: "why did the AI say that?" By making that answer concrete and traceable, Bonsai reduces the opacity that often frustrates users of complex AI systems. The codebase itself enforces strict architectural boundaries, banning framework-specific imports and provider dependencies from the core logic, ensuring the toolkit remains adapter-agnostic and portable across different storage backends, LLM providers, and deployment contexts.

At present, Bonsai is in early-stage development (Phase 1 scaffold) with no published packages, so adoption remains ahead. However, the modular architecture—separating core domain logic, storage adapters (Postgres), provider adapters (OpenAI-compatible), and wiki storage (filesystem)—signals an intent to support multiple deployment patterns and lower the barrier for teams building internal or customer-facing AI chat systems.

FAQ

How do branching and merging work in Bonsai?
At any point in a conversation, a user can branch off to explore a tangent independently without affecting the main thread. If the branch proves useful, the user can explicitly merge a reviewed summary back into the parent branch; if it is a dead end, it is abandoned with no impact on the main conversation.
Is Bonsai a finished chat app or a developer tool?
Bonsai is a library that developers embed into their own products—it provides the tree/branch/merge/distill logic and pluggable adapters for storage, LLM calls, and knowledge retrieval, rather than being a standalone chat application.
What does the 'Distill' feature do?
Distill turns a branch or merged transcript into a durable Markdown wiki page that later conversations can retrieve, allowing knowledge to be reused instead of re-explained each time.

Get the latest Large Language Models news every morning

AI-summarized, only the topics you pick — one digest a day via Email, Slack, or Discord.

Free · takes 30 seconds · unsubscribe anytime

Discussion

No comments yet. Be the first to share your thoughts!

Log in to join the discussion

Related Articles

Stay ahead with AI news

Get curated AI news from 200+ sources delivered daily to your inbox. Free to use.

Get Started Free

Free · takes 30 seconds · unsubscribe anytime