EngineConfiguration
What it is
- A Pydantic-based configuration loader for the ABI engine.
- Loads YAML configuration, renders it with Jinja2, and resolves
{{ secret.* }}placeholders via:- environment variables,
- an optional bootstrap
.envsecret adapter (dotenv), - and the configured secret service (with interactive prompting if needed and available).
Public API
Classes (models)
ServicesConfiguration- Aggregates service configurations with defaults for:
- object storage (default: filesystem)
- triple store (default: filesystem)
- vector store (default:
qdrant_in_memory) - secret service (default: dotenv adapter)
- bus (default:
python_queue) - key-value store (default:
python)
- Aggregates service configurations with defaults for:
ApiConfiguration- API metadata and runtime flags (e.g., CORS origins, reload).
FirstPassConfiguration- Minimal config used to load the secret service before rendering the full YAML template.
ModuleConfig- Module entry with validation:
- requires either
pathormodule enabledflag and free-formconfigdict
- requires either
- Module entry with validation:
GlobalConfig- Global mode flag:
ai_mode∈{ "cloud", "local", "airgap" }
- Global mode flag:
EngineConfiguration- Top-level configuration model containing:
api: ApiConfigurationdeploy: DeployConfiguration | Noneservices: ServicesConfigurationglobal_config: GlobalConfigmodules: List[ModuleConfig]default_agent: str(default:"naas_abi AbiAgent")
- Top-level configuration model containing:
EngineConfiguration methods
ensure_default_modules() -> None- Ensures module
naas_abi_core.modules.templatablesparqlqueryis present inmodules(bypathormodule), otherwise appends it enabled.
- Ensures module
from_yaml(yaml_path: str) -> EngineConfiguration- Reads a YAML file and delegates to
from_yaml_content.
- Reads a YAML file and delegates to
from_yaml_content(yaml_content: str) -> EngineConfiguration- Two-pass load:
- Render YAML using a bootstrap secret resolver to load the configured secret service.
- Render again using the loaded secret service, then parse into
EngineConfiguration.
- Two-pass load:
load_configuration(configuration_yaml: str | None = None) -> EngineConfiguration- Loads configuration from:
- the provided YAML string (testing),
- or
config.{ENV}.yamlifENVis set and file exists, - else
config.yaml.
- If
ENVis not set, it may be obtained from a bootstrap dotenv adapter declared inconfig.yaml.
- Loads configuration from:
Configuration/Dependencies
- YAML parsing:
yaml.safe_load - Templating:
jinja2.Template- YAML content is treated as a Jinja2 template.
- A
secretobject is injected; you can reference secrets like{{ secret.MY_KEY }}.
- Secret resolution order
- During first pass (before secret service exists):
os.environ- bootstrap dotenv adapter (if declared in YAML)
- fallback string message (no prompt)
- During second pass (secret service loaded):
os.environsecret_service.get(name)- if missing:
- prompt on TTY and persist via
secret_service.set(name, value) - raise
ValueErrorif no TTY available
- prompt on TTY and persist via
- During first pass (before secret service exists):
- Bootstrap dotenv adapter detection
- Looks for:
services.secret.secret_adapters[]entry withadapter: "dotenv" - Reads optional
config.path(default.env); must be a non-empty string.
- Looks for:
Usage
Load from standard files (config.yaml or config.{ENV}.yaml)
from naas_abi_core.engine.engine_configuration.EngineConfiguration import EngineConfiguration
config = EngineConfiguration.load_configuration()
print(config.api.title)
print([m.module or m.path for m in config.modules])
Load from an in-memory YAML string (useful for tests)
from naas_abi_core.engine.engine_configuration.EngineConfiguration import EngineConfiguration
yaml_content = """
api:
title: "ABI API"
description: "API"
logo_path: "assets/logo.png"
favicon_path: "assets/favicon.ico"
cors_origins: ["http://localhost:9879"]
reload: true
global_config:
ai_mode: "local"
services:
secret:
secret_adapters:
- adapter: "dotenv"
config: { path: ".env" }
modules:
- module: "some.module"
enabled: true
config: {}
"""
config = EngineConfiguration.load_configuration(configuration_yaml=yaml_content)
print(config.global_config.ai_mode)
Caveats
- YAML is rendered as a Jinja2 template; invalid template expressions will fail during rendering/parsing.
- If a referenced secret is missing:
- and the process has no TTY, loading can raise
ValueError(second pass).
- and the process has no TTY, loading can raise
ModuleConfigrequires eitherpathormodule; providing neither raisesValueError.EngineConfigurationautomatically appends the default modulenaas_abi_core.modules.templatablesparqlqueryif not present.