License: MIT Kotlin codecov Release

Book is an agentic framework for the JVM, Web, Desktop, and Mobile. It runs an agent loop that reasons, executes tools, and steers based on user feedback. Named for Shepard Book, the wise and mysterious shepherd of the Serenity crew, it crafts code, navigates complex mission workflows across the Cortex, and solves the unsolvable with calm precision.

Note: Book is under active development. APIs may change between releases.

Book JVM CLI โ€” terminal UI

Licensing

Book is licensed under the MIT License, with the exception of the android/gallery/ directory โ€” a fork of Google AI Edge Gallery โ€” which is licensed under the "Apache License, Version 2.0". See NOTICE.html for details.

What Book Does

"Man walks down the street in that hat and people stop him."

Core (core/)

  • Agent loop with autonomous execution cycles and user-feedback steering

  • Parallel tool execution

  • Sandboxed file operations; all filesystem access goes through one interface

  • Token optimization pipeline: six-stage pruning before every LLM call, turning O(N) token growth into O(1)

  • Session-scoped cache for deterministic tools (read_file, grep, ls) with automatic invalidation and TTL

  • Loop guards: RepeatCallDetector for non-cacheable calls, EmptyArgumentCircuitBreaker for empty-argument calls

  • Automatic context compaction when input tokens exceed 70% of the window

  • Multi-modal image support via magic-byte inspection in read_file

  • Per-turn token counting and USD cost persistence to session JSONL

  • Named, resumable, forked sessions

JVM (jvm/)

  • Terminal UI built with Mordant: live thinking output, multi-line input, slash-command and file-path completion, session picker

  • System prompts from SYSTEM.md, CLI flags, or AGENTS.md

  • Extensions: drop .bk.kts scripts into ~/.bk/tools/ or .bk/tools/ for tools, slash commands, and event handlers, no recompile needed

  • /init wizard that detects the project language and scaffolds configuration

  • Opt-in tool approval gate with diff overlays (tool_approval.bk.kts)

Protocols (features/)

  • MCP client, configured via mcp.json, run with --mode mcp

  • ACP server (--mode acp) for IDE integration such as Xcode 26.6+, with isolated per-session AgentLoop instances

Providers (core/providers/)

  • Koog-based LLM layer (:core:providers:koog): Anthropic and any OpenAI-compatible backend (OpenAI, vLLM, Ollama bridges, gateways) via a configurable base URL, with retry handling and inactivity-watchdog stream lifecycle management

  • On-device LiteRT-LM provider (:core:providers:litertlm): runs Gemma 3n, Phi-3, Llama-3 and similar models directly on Android devices with CPU/GPU/NPU backends, real-time token and thinking-delta streaming, and multi-turn tool-call parsing

Android / On-Device (android/)

  • Google AI Edge Gallery app fork (android/gallery) running Book’s AgentLoop fully on-device via the LiteRT-LM provider

  • Gallery bridge (android/gallery-bridge): embeds Book’s agent loop in Compose apps with local Android tools (Skills, MCP, JavaScript evaluation, Intent runners), eager model warmup, and real-time streaming to the UI

Architecture

Book follows Clean Architecture across three areas:

  • core: the agent framework for building domain-specific agents

  • jvm: a reference implementation, a full agent extended through KTS scripts

  • features: optional protocol implementations (MCP, ACP)

Modules:

  • :core:domain - Kotlin Multiplatform (KMP) core logic, framework-free. Packages: agentloop/ (orchestration, pruning pipeline, cache, guards), messages/, session/, tracking/, tools/, extensions/, commands/, events/

  • :core:providers:koog - KMP Koog LLM provider (KoogAgent, StreamOrchestrator, StreamFrameHandler, InactivityWatchdog)

  • :core:infrastructure - KMP sandboxed filesystem, KTS script loader, session persistence, model metadata registry

  • :jvm:cli - terminal UI, command-line parsing, dependency injection via Metro

  • :features:mcp - KMP self-contained MCP client. Public interface: McpClientFacade

  • :features:acp - KMP self-contained ACP server. Public interface: AcpServer. :jvm:cli has zero ACP/MCP SDK imports; the boundary is enforced at build time

  • :core:providers:litertlm - KMP on-device LiteRT-LM provider. Public interface: LitertLmAgent

  • :android:gallery - fork of Google AI Edge Gallery using Book’s AgentLoop as its execution engine

  • :android:gallery-bridge - bridges Gallery’s UI with Book’s domain AgentLoop and tool registry

  • :jvm:extensions - bundled .bk.kts scripts (ripgrep.bk.kts, tool_approval.bk.kts, observability samples)

Getting started

Requires JDK 21 or higher and Gradle.

Installation

Linux & macOS

./install.sh

Windows (PowerShell)

.\install.ps1

The installer builds Book, copies the wrapper script to your PATH (default ~/.local/bin), and creates ~/.bk/config for your API keys.

Versioning: the project version is derived from git tags โ€” no version file is maintained. See Versioning & Release Management.

Using Book as a library

Published artifacts (group us.nineworlds.book, artifacts named book-<module-path>) are available from Maven Central (after a maintainer runs the manual Central publish job for a tag) and from the project’s GitLab Maven package registry (every tag, automatic). While the project is private, the GitLab registry needs a personal access or deploy token; once public, the URL works with no credentials. See Maven Publishing โ†’ Consuming the published artifacts for the full setup, credential options, and which source to use.

Manual Build & Run

Linux / macOS

The jar name carries the project version (see Versioning), which resolves from the newest tag matching the spec. A robust variant that works without tags too:

./gradlew clean :jvm:cli:shadowJar
java -jar "$(ls -t jvm/cli/build/libs/cli-*.jar | grep -vE 'javadoc|sources' | head -1)"

Or let the build tell you the exact path:

./gradlew :jvm:cli:shadowJar -q && ls jvm/cli/build/libs/cli-*.jar

(The build also emits -javadoc and -sources jars; use the one without a suffix.)

Windows

.\gradlew.bat clean :jvm:cli:shadowJar
java -jar (Get-ChildItem jvm\cli\build\libs\cli-*.jar | Select-Object -First 1 -ExcludeProperty *javadoc*,*sources*).FullName

Book needs OPENAI_API_KEY or ANTHROPIC_API_KEY. For local models and gateways, set OPENAI_BASE_URL (default https://api.openai.com/v1).

Common commands:

bk                              # interactive TUI
bk "Refactor this code"         # TUI with an initial prompt
bk --prompt "Summarise this"    # headless, one prompt, output on stdout
bk --continue                   # resume the most recent session
bk sessions list                # list sessions for this directory
bk --mode acp                   # ACP server for IDEs
bk --mode mcp                   # load MCP servers from mcp.json

New here, captain? Read the Quick Start or Getting Started. Full usage, configuration, and system prompt docs are under docs/user/.

Documentation

The documentation index routes you to the right page by task. Highlights:

The docs site is generated with:

./gradlew clean :documentation:buildDocsSite

Output lands in documentation/build/dist/.

Contributing

Read the contribution guidelines. Complex changes follow the phased spec-driven protocol in prompts/plans/sdd_implementation_v1.md.

License

MIT. See the LICENSE file.


"Book is the shepherd for your digital missions aboard Serenity. We have done the impossible, and that makes us mighty."