| tags |
|
|---|
The optional hooks.py file in a plugin root provides config lifecycle hooks — functions that intercept plugin configuration reads and saves. This is how plugins transform, validate, or coerce settings between the UI and persistent storage.
Called when plugin settings are loaded. Receives the current config dict and returns the config that should be used.
Use cases:
- Inject computed defaults
- Coerce legacy config formats
- Merge environment variables into settings
Called before plugin settings are persisted. Receives the settings dict and returns what should be saved.
Use cases:
- Strip transient UI-only fields
- Validate and sanitize values
- Transform between internal and storage formats
from __future__ import annotations
from plugins._skills.helpers.runtime import coerce_config
def get_plugin_config(default=None, **kwargs):
return coerce_config(default)
def save_plugin_config(settings=None, **kwargs):
return coerce_config(settings)def save_plugin_config(result=None, settings=None, **kwargs):
if settings and isinstance(settings, dict):
for section in ("chat_model", "utility_model", "embedding_model"):
if section in settings and isinstance(settings[section], dict):
settings[section].pop("_kwargs_text", None)
settings[section].pop("api_key", None)
return settingsBoth hooks receive arbitrary keyword arguments. The framework passes:
| KWarg | Description |
|---|---|
default |
Current config dict (for get_plugin_config) |
settings |
New settings dict from UI (for save_plugin_config) |
result |
Previous hook result (for chaining) |
- You need to transform config between storage and runtime formats
- You need to strip UI-only fields before persisting
- You need to merge environment variables or external state
- You need to validate settings beyond what the UI schema provides
- Simple static defaults → use
default_config.yaml - One-time init logic → use
initialize.py - Lifecycle hooks → use
extensions/python/<point>/
- Plugin Architecture — Plugin system overview and structure
- Extension Points — Alternative lifecycle hook mechanism
- Settings — Plugin settings resolution chain