Instance Configuration Management#
LangBot's instance-level configuration lives in data/config.yaml and is managed through the ConfigManager class. It is the single source of truth for system-wide settings (API ports, database, concurrency, storage, plugins, etc.) β distinct from pipeline-level configuration stored in the database or adapter/plugin-specific config.
Boot Sequence#
LoadConfigStage is the first stage in the boot pipeline , running before logging, key generation, or any service initialization. The full stage order is:
LoadConfigStageβ loadsdata/config.yaml, applies env overrides, resolves instance IDGenKeysStageβ generates JWT secret/recovery key if absentSetupLoggerStageβ initializes persistent loggingBuildAppStageβ constructs all application componentsShowNotesStageβ displays startup messages
How Config Is Loaded#
LoadConfigStage.run() calls config.load_yaml_config('data/config.yaml', 'config.yaml', completion=False), which is a convenience wrapper re-exported from bootutils/config.py . The real implementation is load_yaml_config in src/langbot/pkg/config/manager.py, which:
- Creates a
YAMLConfigFileinstance backed bydata/config.yaml. - Instantiates a
ConfigManagerand callsload_config()to read the file intoConfigManager.data(an in-memorydict). - Returns the
ConfigManagerinstance, which is stored onap.instance_config.
The loaded object is accessed everywhere as ap.instance_config.data[<key>] β for example, ap.instance_config.data['api']['port'] to read the HTTP port.
Environment Variable Overrides#
After loading the YAML file, _apply_env_overrides_to_config() is applied to ap.instance_config.data. Rules:
- Variable names must be all-uppercase and contain
__(double underscore) as the hierarchy separator. __maps to nested YAML keys:CONCURRENCY__PIPELINEβconcurrency.pipeline.- Scalar types are coerced to match the existing value type (bool, int, float, or string) .
- List values accept comma-separated strings:
SYSTEM__DISABLED_ADAPTERS="aiocqhttp,dingtalk". - Dict-type keys are skipped .
- Keys not present in the YAML are created as strings .
After overrides are applied, the config is written back to disk via ap.instance_config.dump_config(), which calls yaml.dump() with allow_unicode=True and 4-space indentation .
Instance ID Resolution#
LoadConfigStage resolves the instance ID with the following priority:
system.instance_idinconfig.yaml(settable viaSYSTEM__INSTANCE_IDenv var)data/labels/instance_id.json(file-based persistence)- Auto-generated
instance_<uuid>, saved todata/labels/instance_id.json
The resolved value is stored in constants.instance_id . constants.edition is read from system.edition (default: "community") .
ConfigManager Class#
ConfigManager (src/langbot/pkg/config/manager.py) is a thin wrapper over a ConfigFile implementation:
| Attribute | Purpose |
|---|---|
data | In-memory dict of config values |
schema | Optional JSON Schema Draft 7 for validation |
file | ConfigFile instance handling I/O |
doc_link | Optional documentation URL |
Key methods: load_config(completion=True) fills missing keys from a template; dump_config() / dump_config_sync() persist data back to disk .
The completion=False flag used during instance config loading means no automatic template backfill β the file is loaded as-is without merging defaults.
data/config.yaml Top-Level Sections#
The canonical template is at src/langbot/templates/config.yaml :
| Section | Purpose |
|---|---|
api | HTTP service port, webhook prefix, global API key |
command | Bot command enable/disable, prefix, privilege |
concurrency | Pipeline and session concurrency limits |
proxy | HTTP/HTTPS proxy settings |
system | Instance ID, edition, JWT config, outbound IPs, task retention |
database | Backend selection (SQLite / PostgreSQL) |
vdb | Vector database (Chroma, Qdrant, Milvus, pgvector, Valkey, SeekDB) |
storage | File storage backend (local / S3) and cleanup schedule |
plugin | Plugin runtime WebSocket URL, marketplace, binary storage limits |
monitoring | Record auto-cleanup retention and batch settings |
box | Sandbox runtime (Docker / nsjail / e2b) and limits |
space | External space service URLs for OAuth and model gateway |
Key Source Files#
| File | Role |
|---|---|
src/langbot/pkg/core/stages/load_config.py | Boot stage: orchestrates loading, env overrides, instance ID resolution |
src/langbot/pkg/config/manager.py | ConfigManager class + load_yaml_config / load_json_config factories |
src/langbot/pkg/config/impls/yaml.py | YAML-backed ConfigFile implementation |
src/langbot/pkg/core/bootutils/config.py | Re-exports loader functions for use inside boot stages |
src/langbot/pkg/core/app.py | Application object; ap.instance_config field declaration |
src/langbot/templates/config.yaml | Default config template |