Skip to content

What zhin Is ​

In one line: zhin is a runtime that lets an AI live in IM groups for the long run — it talks like a person, follows the rules, keeps costs in check, and works on any platform.

This page ties the designs spread across the ADRs into one picture. To write a plugin, start with Plugin Model; for how messages move, see Message Flow. This page explains why things are the way they are.

The picture ​

            ┌──────────────────── Platforms (QQ / OneBot / Discord / …) ────────────────────┐
            │                                                                              │
  Adapter ── declares a capability profile (what it can do, per conversation kind)        │
            ── implements ports (how to do it) ── maps raw events to canonical events      │
            ▼                                                                              │
  zhin runtime ─ the spec: capability catalog · segment assembler · message/event          │
                 contracts · audit · hard gate · control plane                             │
            ▼                                                                              │
  Plugins / Agent ─ decide, from this turn's combined capabilities, what to say,          │
                    which tools to offer and which actions are possible ──────────────────┘

The rule: zhin provides the spec; adapters inject capabilities by that spec; plugins build features from the combined capabilities. Core code never says "if this is platform X"; every difference comes from what the adapter declares (ADR 0044).

Four goals and what supports them ​

1. Humanlike — how it behaves in a group ​

DesignWhat it doesSource
Ambient listeningReads the group without being @'d and decides whether to speak; may stay quiet even when @'dambient engagement
Headers only when neededName / role / title appear on someone's first message and when they change; a short header otherwise0041
State changes in historyJoins, leaves, card changes and promotions are part of the conversation0041
Quotes understood inlineA quoted message in context gets reply_to; otherwise an inline excerpt — no extra tool call0043
Continuous input mergeSeveral people @'ing at once get one reply that addresses each; danmaku picks one0038
Restrained reactionsStickers and emoji reactions have cooldowns and randomnessreaction pacing
Persona vs rulesSOUL.md holds personality and tone; general rules live in the system promptbootstrap scopes (0042)

2. Controlled — you can always rein it in ​

DesignWhat it doesSource
Decision auditEvery wake, block, allow, tool call and outbound is recorded and replayable per turn0036
Control planeEmergency stop, mute, read-only, mention-only; instance and conversation levels with revisions0036
Dangerous-action hard gateKick, mute, announce, editing host config… need a fresh human approval; bypass and remembered grants don't count0036, #1030
Group operationsWelcome, approved announcements, quiet-field cooling, schedule reminders, moderation cooldown0037
Approved-once rulesOnce an owner approves a violation ladder, mutes run automatically; kicks still need approval each time0039
Controlled self-changeDraft → trial → human approval → apply/restart → report back; one rollback, then emergency stop0040

Principle: the model may propose; loosening limits and dangerous actions need a person, and you can always see who approved what.

3. Affordable — cheap enough to stay ​

DesignWhat it doesSource
Segment assemblerSystem → environment → role rules → platform → scene; the first four are byte-stable across sessions0041
Stable prefix + cache breakpointScene goes last, so even a new session's first message hits the cache0042
Tool tiers, call-to-loadGroup chats keep only chat essentials loaded; calling by name auto-loads; the tool list only appends0042
History stores conversationPer-turn context (time, rules, tool index…) is never stored; the window is a token budget0043
Old tool results trimmedFinished turns keep the first 200 chars of each result0043
Fewer roundsPer-scene iteration limits, spin detection, parallel calls0042
Real ledgerzhin usage report and the Console "Token usage" page by model / session / time, with cache hits0043, Console

Goal: cost grows linearly with groups and messages, not with accumulated history.

4. Platform-neutral — composed capabilities, not hard-coded branches ​

DesignWhat it doesSource
Capability profileAdapters declare seven groups (messaging, scene, actions, events, feedback, delivery, prompt) per conversation kind0044
Dynamic narrowingCurrent facts (bot role, mute, passive window) can only narrow, never widen0044
Generated platform notesThe prompt's platform section is generated from capabilities; adapters may add their own text0044
Shared event mappingOneBot / NapCat / icqq share one raw → canonical event mapping0044
Tools follow capabilitiesTools declare requiresCapabilities; if the bot isn't admin, the mute tool doesn't appear0044

What happens to one message ​

  1. Ingress: the adapter turns a platform message into a canonical one; the trusted ingress adds sender roles and scene facts (group name, owner, admins, bot role — two-level cache).
  2. Capabilities: the profile is merged for the conversation kind, then narrowed by current facts.
  3. Admission: merge window, control plane (stop / mute / mention-only) and the session gate decide whether and when the model runs.
  4. Assembly: the system prompt is assembled from segments (stable prefix + scene); history is cut to the token budget and holds only conversation; the current message carries this turn's context.
  5. Reasoning and tools: the model only sees tools allowed by both capabilities and permissions; dangerous tools go through the hard gate.
  6. Outbound: the structured reply is rendered, degraded and delivered per platform capabilities; reactions are paced; everything is audited.

ADR index ​

ADRTopic
0034Activity feedback service
0035Comment-reply adapter contract
0036Controlled landing phase 0: audit, control plane, hard gate
0037Phase 1: group operations
0038Continuous input merge (busy groups, danmaku)
0039Dynamic group-ops rules
0040Controlled self-change
0041Prompt segments and message headers
0042First-turn token budget
0043Conversation-only history, token-budget window, quotes
0044Adapter capability profile
0045Current-message runtime context after the body (prompt cache)
0046Personal Sessions, model catalog and scope policy

ADRs are written in Chinese.

  • Writing a plugin: Plugin Model → ADR 0044 §5 (how plugins use capabilities).
  • Writing an adapter: Adapters → ADR 0044 (profile, ports, event mapping).
  • Tuning persona and group experience: SOUL.md / AGENTS.md and scope annotations (0042 §5) → 0041 headers.
  • Control and rollout: 0036 → 0037 → 0039 → 0040.
  • Watching cost: zhin usage report, Console "Token usage" → 0042, 0043.