Noureddine RAMDI / KohakuTerrarium: Modular AI agent composition with algebraic pipelines

Created Mon, 04 May 2026 10:23:02 +0000 Modified Sat, 23 May 2026 20:41:27 +0000

Kohaku-Lab/KohakuTerrarium

KohakuTerrarium tackles a common headache for AI developers: how to build complex multi-agent systems with reusable, composable parts rather than brittle, ad-hoc orchestration code. Its standout feature is a composition algebra that treats agent pipelines as first-class constructs, allowing you to stitch AI agents programmatically with operators like », &, |, *, and .iterate.

What KohakuTerrarium does and how it’s built

At its core, KohakuTerrarium is a Python framework designed around a central abstraction called a “creature.” A creature models an AI agent with six distinct modules: controller, input, output, tools, triggers, and sub-agents. This modular design lets you build agents whose behavior and interactions are neatly encapsulated and reusable.

The runtime environment is graph-based — called the Terrarium — which enables composing multiple creatures together through channels. This lets you build pipelines where agents communicate and coordinate systematically. Lifecycle management and observability are built-in, so you can track agent states and interactions over time.

The framework supports session persistence with searchable history, which means long-running agents can maintain context across restarts. It also implements non-blocking context compaction to handle long conversations without blocking the main event loop, a practical feature for production use.

KohakuTerrarium integrates with the MCP server system for multi-agent coordination and exposes multiple runtime interfaces: CLI, TUI, a web dashboard, and even a desktop runtime. This variety means you can choose the best interaction surface for your use case.

The framework ships with kt-biome, a package of ready-to-use creatures, which helps you get started without building everything from scratch.

The composition algebra: agent pipelines as first-class citizens

What really distinguishes KohakuTerrarium is its composition algebra for agents. Instead of wiring agents together manually or with brittle glue code, it treats composition as an algebraic operation. The core operators include:

  • >> for sequential composition (pipe output from one creature to input of another)
  • & for parallel composition (run creatures concurrently)
  • | for choice or fallback between creatures
  • * for repetition or looping
  • .iterate for iterative processing

This algebra lets you build complex pipelines and multi-agent workflows programmatically with clear semantics. It’s a more declarative, compositional approach versus ad-hoc orchestration that typically gets messy as systems grow.

Under the hood, this requires the runtime to manage message passing, lifecycle, and concurrency between creatures robustly. The code quality around this area is surprisingly clean, with explicit lifecycle states and error management.

The tradeoff is that the algebra adds a learning curve. You need to understand these operators to effectively compose agents, which might be unfamiliar if you’re used to simpler agent frameworks or scripting approaches.

The modular creature model also means that each agent is opinionated about its inputs, outputs, and tools. This clarity helps when debugging and extending behaviors but requires upfront design discipline.

Quick start

1. Install KohakuTerrarium

# Optional extras: pip install "kohakuterrarium[full]"

Installation & Setup

  • Requires Python 3.10 or higher.
  • Install via pip install kohakuterrarium.

Supported LLM providers

  • Codex OAuth, OpenAI/OpenRouter-style providers, native Anthropic, Google Gemini.
  • Local OpenAI-compatible servers such as Ollama, vLLM.
  • Other OpenAI-compatible cloud providers.

You configure providers and API keys with commands like kt login, kt config llm add, and kt config provider add.

Using local models

Point the LLM endpoint to your local server and set the model name in your creature configuration.

This setup shows the project’s flexibility—it’s not tied to a single LLM provider and supports both cloud and local backends.

Verdict

KohakuTerrarium is infrastructure for developers who want to build their own AI agent shapes, not a plug-and-play agent product. Its modular creature model combined with the algebraic composition of agents is an elegant, disciplined approach to multi-agent pipelines.

The tradeoff is that it requires some upfront investment to learn the composition algebra and design creatures with clear inputs, outputs, and tools. It’s not a shortcut if you just want a simple chatbot or a ready-made assistant.

That said, the session persistence with searchable history, non-blocking context compaction, and multi-runtime interfaces make it practical for real-world, long-running AI systems.

If you’re building multi-agent AI workflows that need modularity, observability, and robust lifecycle management, KohakuTerrarium is worth exploring. The code quality and architecture reflect a mature project built for composability and scalability rather than quick hacks.


→ GitHub Repo: Kohaku-Lab/KohakuTerrarium ⭐ 283 · Python