Skip to Content
Introduction

Khwan

Khwan is a hosted cognition layer for AI agents. It gives any model long-term memory, a constitutional identity, coherence checks, and continuous learning — without you running that infrastructure yourself.

It is model-agnostic (BYOM). Khwan never holds your provider key and never replaces your model. You keep calling the LLM you already use; Khwan wraps the thinking around it.

The mental model

Khwan prepares the brief and takes the notes. Your model speaks.

  • Before a turn, Khwan assembles the brief — retrieved memory, the constitution, learned lessons, and a coherence signal — into a ready-to-send system prompt.
  • You call your own model with that brief. Khwan never sees your provider key and never generates the answer — you always call your own model.
  • After, Khwan records the exchange, persists new memory, and learns — so the next brief is sharper.
from khwan import Khwan kw = Khwan(api_key="kwk_live_xxx", user_id="alice") turn = kw.prepare("remember I prefer short answers in Thai") # Khwan builds context, no LLM answer = my_own_llm(turn.messages) # your model + key kw.record(turn, answer) # Khwan persists + learns

That loop — prepareyour modelrecord — is the whole product. Khwan never generates text: there is no hosted model path, so you always call your own model.

Isolated cores

One account can hold many cores — fully separate brains, each with its own memory, identity, and learning. Point a client at one with core:

test = Khwan(api_key="kwk_live_xxx", user_id="alice", core="test") client1 = Khwan(api_key="kwk_live_xxx", user_id="alice", core="client1")

test and client1 never share memory. Omit core for the account’s default brain. Quota stays pooled at the account level. Create and manage cores in the dashboard or via the API.

What’s in a turn’s context

turn.messages is a standard [{role, content}] array. Khwan’s value is baked into the system message:

  • Constitution — the agent’s identity and hard rules.
  • Retrieved memory — relevant facts and past exchanges from this core.
  • Learned lessons — patterns distilled from prior turns.
  • Coherence — a signal (and optional gate) on whether the turn is consistent with identity and memory.

Why BYOM

  • No lock-in. Swap Claude for GPT for a local Ollama model without touching your memory or identity layer.
  • Your key, your bill, your data path. The generation call stays between you and your provider. Khwan never touches your model or your key — it only ever sees the input, the messages it built, and the answer you record.

Where to go next

Last updated on