# openai/chatkit-python architecture

> Architecture diagram of the GitHub repository openai/chatkit-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openai/chatkit-python
- Repository: https://github.com/openai/chatkit-python

## Overview

- **Project shape:** This is a Python package, `chatkit`, that provides the core runtime and abstractions for building chat-centric applications. The repository is organized as a library first, with docs, tests, and release automation around it.

- **Public API boundary:** `chatkit/__init__.py` likely exposes the supported surface area, while the implementation is split into focused modules: `agents`, `actions`, `store`, `widgets`, `server`, `types`, `errors`, `icons`, and `logger`. For an architecture diagram, treat `__init__` as the stable entry point and the other modules as internal subsystems.

- **Conversation orchestration:** `agents.py` is the central coordination layer. It appears to manage how user messages, model responses, actions/tools, and streamed events are stitched together into a conversation flow. This is the most likely “runtime brain” of the system.

- **Action/tool execution boundary:** `actions.py` represents app-defined operations that the agent can invoke. The docs include concepts for actions and tools, which suggests a clear boundary between model-driven decisions and imperative code executed in the host application.

- **Persistence and thread state:** `store.py` is the persistence layer for chat threads and related data. The docs reference threads, browsing past threads, and keeping the app in sync, so the store is a key boundary between transient conversation processing and durable application state.

- **Rich UI and structured output:** `widgets.py` handles widget definitions and serialization for interactive or structured content inside chat messages. The `tests/assets/widgets/*.widget` and matching JSON fixtures imply a schema-driven widget system, not just plain text output.

- **Domain model and contracts:** `types.py` and `errors.py` define the package’s shared data shapes and failure modes. These are the glue between agent logic, store persistence, server responses, and widget rendering, so they matter as diagram boundaries even if they’re not runtime services.

- **Serving layer:** `server.py` is the external interface layer. It likely exposes the chatkit runtime to clients over an HTTP or application server boundary, translating between client requests, stream events, and the internal agent/store model.

- **Presentation helpers:** `icons.py` and `logger.py` are supporting infrastructure. Icons are probably used by widgets or UI payloads, while logging is cross-cutting observability for agent execution, server requests, and persistence operations.

- **Documentation reflects the system flow:** The docs are organized around concepts like entities, threads, thread-stream events, tools, and widgets, plus guides for drafting messages, feedback, syncing state, and streaming images. That strongly suggests the core architecture is an evented chat pipeline: client input enters the server, the agent orchestrates model/tool calls, output is streamed as events, and the store keeps thread history in sync.

- **Testing strategy:** The tests are organized around the main subsystems (`agents`, `server`, `store`, `widgets`, `icons`) with helper mocks for stores and widgets. That indicates the package’s important seams are the agent/store/widget contracts and the server boundary, not a large set of unrelated features.

- **Tooling and distribution:** `pyproject.toml`, `uv.lock`, MkDocs config, and GitHub workflows for CI/docs/release show a standard Python library lifecycle: validate with tests, publish generated documentation, and package releases. No third-party infrastructure is visible in the repository tree itself, so the architecture is primarily in-process library code plus a serving boundary.

Main entry points: [`chatkit/agents.py`](https://github.com/openai/chatkit-python/blob/main/chatkit/agents.py) (Agents), [`chatkit/store.py`](https://github.com/openai/chatkit-python/blob/main/chatkit/store.py) (Store), [`chatkit/__init__.py`](https://github.com/openai/chatkit-python/blob/main/chatkit/__init__.py) (chatkit), [`chatkit/types.py`](https://github.com/openai/chatkit-python/blob/main/chatkit/types.py) (Types)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core library"]
  node_chatkit_init["chatkit<br/>public API<br/>[__init__.py]"]
  node_agents{{"Agents<br/>orchestrator<br/>[agents.py]"}}
  node_actions["Actions<br/>tool boundary<br/>[actions.py]"]
  node_store[("Store<br/>persistence<br/>[store.py]")]
  node_widgets["Widgets<br/>structured UI<br/>[widgets.py]"]
  node_types["Types<br/>contracts<br/>[types.py]"]
  node_errors["Errors<br/>failure model<br/>[errors.py]"]
  node_icons["Icons<br/>presentation assets<br/>[icons.py]"]
  node_logger["Logger<br/>observability<br/>[logger.py]"]
end

subgraph group_boundary["External boundary"]
  node_server["Server<br/>serving layer<br/>[server.py]"]
  node_version["Version<br/>release metadata<br/>[version.py]"]
  node_ci["CI/CD<br/>automation<br/>[workflows]"]
  node_build["Build<br/>packaging<br/>[pyproject.toml]"]
end

subgraph group_support["Supporting assets"]
  node_docs["Docs<br/>documentation"]
  node_tests["Tests<br/>verification"]
end

node_chatkit_init -->|"exports"| node_agents
node_chatkit_init -->|"exports"| node_actions
node_chatkit_init -->|"exports"| node_store
node_chatkit_init -->|"exports"| node_widgets
node_chatkit_init -->|"exports"| node_types
node_agents -->|"invokes"| node_actions
node_agents -->|"reads/writes"| node_store
node_agents -->|"uses"| node_types
node_agents -->|"raises"| node_errors
node_agents -->|"emits"| node_widgets
node_server -->|"drives"| node_agents
node_server -->|"syncs"| node_store
node_server -->|"serializes"| node_types
node_widgets -->|"uses"| node_types
node_widgets -->|"renders"| node_icons
node_actions -->|"defines"| node_types
node_store -->|"persists"| node_types
node_store -->|"raises"| node_errors
node_logger -.->|"observes"| node_agents
node_logger -.->|"observes"| node_server
node_docs -.->|"describes"| node_agents
node_docs -.->|"describes"| node_store
node_tests -.->|"verifies"| node_agents
node_tests -.->|"verifies"| node_server
node_tests -.->|"verifies"| node_store
node_tests -.->|"verifies"| node_widgets
node_ci -.->|"runs"| node_tests
node_ci -.->|"publishes"| node_docs
node_build -.->|"packages"| node_chatkit_init
node_build -.->|"versioned by"| node_version

click node_chatkit_init "https://github.com/openai/chatkit-python/blob/main/chatkit/__init__.py"
click node_agents "https://github.com/openai/chatkit-python/blob/main/chatkit/agents.py"
click node_actions "https://github.com/openai/chatkit-python/blob/main/chatkit/actions.py"
click node_store "https://github.com/openai/chatkit-python/blob/main/chatkit/store.py"
click node_widgets "https://github.com/openai/chatkit-python/blob/main/chatkit/widgets.py"
click node_types "https://github.com/openai/chatkit-python/blob/main/chatkit/types.py"
click node_errors "https://github.com/openai/chatkit-python/blob/main/chatkit/errors.py"
click node_icons "https://github.com/openai/chatkit-python/blob/main/chatkit/icons.py"
click node_logger "https://github.com/openai/chatkit-python/blob/main/chatkit/logger.py"
click node_server "https://github.com/openai/chatkit-python/blob/main/chatkit/server.py"
click node_version "https://github.com/openai/chatkit-python/blob/main/chatkit/version.py"
click node_docs "https://github.com/openai/chatkit-python/tree/main/docs"
click node_tests "https://github.com/openai/chatkit-python/tree/main/tests"
click node_ci "https://github.com/openai/chatkit-python/blob/main/.github/workflows"
click node_build "https://github.com/openai/chatkit-python/blob/main/pyproject.toml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_chatkit_init,node_agents,node_actions,node_store,node_widgets,node_types,node_errors,node_icons,node_logger toneBlue
class node_server,node_version,node_ci,node_build toneAmber
class node_docs,node_tests toneMint
```

## Components

### Core library

Public API and internal runtime subsystems for chat-centric applications.

- [chatkit](https://github.com/openai/chatkit-python/blob/main/chatkit/__init__.py): public API · Stable package entry point that re-exports the supported surface. · `chatkit/__init__.py`
- [Agents](https://github.com/openai/chatkit-python/blob/main/chatkit/agents.py): orchestrator · Coordinates conversation flow, model calls, actions, and streamed events. · `chatkit/agents.py`
- [Actions](https://github.com/openai/chatkit-python/blob/main/chatkit/actions.py): tool boundary · Defines app-invoked operations the agent can select and execute. · `chatkit/actions.py`
- [Store](https://github.com/openai/chatkit-python/blob/main/chatkit/store.py): persistence · Persists threads and conversation state across requests and sessions. · `chatkit/store.py`
- [Widgets](https://github.com/openai/chatkit-python/blob/main/chatkit/widgets.py): structured UI · Schemas and serialization for interactive rich message content. · `chatkit/widgets.py`
- [Types](https://github.com/openai/chatkit-python/blob/main/chatkit/types.py): contracts · Shared data models and payload shapes used across the package. · `chatkit/types.py`
- [Errors](https://github.com/openai/chatkit-python/blob/main/chatkit/errors.py): failure model · Package-specific exceptions and failure semantics. · `chatkit/errors.py`
- [Icons](https://github.com/openai/chatkit-python/blob/main/chatkit/icons.py): presentation assets · Icon assets used by widgets or UI payloads. · `chatkit/icons.py`
- [Logger](https://github.com/openai/chatkit-python/blob/main/chatkit/logger.py): observability · Cross-cutting logging support for runtime and server operations. · `chatkit/logger.py`

### External boundary

Serving and packaging surfaces that connect the library to clients and release workflows.

- [Server](https://github.com/openai/chatkit-python/blob/main/chatkit/server.py): serving layer · External interface that exposes chatkit runtime to clients. · `chatkit/server.py`
- [Version](https://github.com/openai/chatkit-python/blob/main/chatkit/version.py): release metadata · Package version metadata used for distribution. · `chatkit/version.py`
- [CI/CD](https://github.com/openai/chatkit-python/blob/main/.github/workflows): automation · Workflow automation for testing, documentation, and release publishing. · `.github/workflows`
- [Build](https://github.com/openai/chatkit-python/blob/main/pyproject.toml): packaging · Project configuration for dependency management and library packaging. · `pyproject.toml`

### Supporting assets

Documentation, tests, and fixtures that validate and explain the runtime.

- [Docs](https://github.com/openai/chatkit-python/tree/main/docs): documentation · Concept guides and API references describing the evented chat pipeline. · `docs`
- [Tests](https://github.com/openai/chatkit-python/tree/main/tests): verification · Subsystem-focused tests and fixtures covering agent, server, store, and widgets behavior. · `tests`

## Connections

- chatkit → Agents: exports · Public API surfaces the conversation runtime.
- chatkit → Actions: exports · Public API surfaces tool/action definitions.
- chatkit → Store: exports · Public API surfaces persistence abstractions.
- chatkit → Widgets: exports · Public API surfaces widget schemas and serializers.
- chatkit → Types: exports · Public API surfaces shared contracts.
- Agents → Actions: invokes · Agent selects and executes app-defined actions.
- Agents → Store: reads/writes · Agent coordinates conversation state persistence.
- Agents → Types: uses · Agent exchanges shared message and event types.
- Agents → Errors: raises · Agent reports domain failures through package errors.
- Agents → Widgets: emits · Agent can produce structured widget content.
- Server → Agents: drives · Server turns client requests into agent execution.
- Server → Store: syncs · Server keeps client-visible threads aligned with persisted state.
- Server → Types: serializes · Server translates between request/response payloads and internal contracts.
- Widgets → Types: uses · Widget schemas are built on shared data contracts.
- Widgets → Icons: renders · Widgets may reference icon assets in output payloads.
- Actions → Types: defines · Actions are described with package-level contracts.
- Store → Types: persists · Stored records use the shared domain model.
- Store → Errors: raises · Persistence failures surface as package errors.
- Logger → Agents: observes · Logging supports runtime orchestration.
- Logger → Server: observes · Logging supports request handling and streaming.
- Docs → Agents: describes · Documentation explains the orchestration and event flow.
- Docs → Store: describes · Documentation covers threads, browsing, and sync semantics.
- Tests → Agents: verifies · Tests cover orchestration behavior and streaming flow.
- Tests → Server: verifies · Tests cover the external server boundary.
- Tests → Store: verifies · Tests cover persistence behavior.
- Tests → Widgets: verifies · Tests cover widget serialization and schema behavior.
- CI/CD → Tests: runs · CI executes the test suite.
- CI/CD → Docs: publishes · CI builds and publishes documentation.
- Build → chatkit: packages · Project configuration defines the library distribution.
- Build → Version: versioned by · Release metadata is packaged with the library.
