EngineConfiguration
What it is
- Pydantic-based configuration loader for the ABI engine.
- Loads YAML configuration files, supports Jinja2 templating, and resolves secrets via:
- Environment variables
- A bootstrap
.envsecret adapter (for first-pass loading) - The configured secret service (with optional interactive prompting)
Public API
Classes
-
ServicesConfiguration- Holds service configurations and provides defaults for:
- object storage, triple store, vector store, secret service, bus, key-value, email, cache.
- Holds service configurations and provides defaults for:
-
ApiConfiguration- API/UI metadata and runtime settings:
- title, description, logo/favicon paths, CORS origins, reload flag.
- API/UI metadata and runtime settings:
-
OpencodeProviderConfiguration- Provider record:
id,key,type="api",metadata.
- Provider record:
-
OpencodeConfiguration- Opencode auth file path and providers list.
-
FirstPassConfiguration- Minimal configuration used to load the secret service first.
- Contains nested
FirstPassServicesConfiguration(secret: SecretServiceConfiguration).
-
ModuleConfig- Module loading configuration:
pathormodule(one must be provided),enabled,configdict.
- Validator enforces: either
pathormoduleis required.
- Module loading configuration:
-
GlobalConfig- Global engine flags:
ai_mode:"cloud" | "local" | "airgap"skip_ontology_loading: bool
- Global engine flags:
-
EngineConfiguration- Top-level configuration model containing:
api,deploy,services,global_config,modules,default_agent,opencode.
- Top-level configuration model containing:
EngineConfiguration methods
-
ensure_default_modules() -> None- Ensures these modules are present in
modules(added if missing, enabled=True):naas_abi_core.modules.templatablesparqlquerynaas_abi_core.modules.bfonaas_abi_core.modules.cco
- Ensures these modules are present in
-
from_yaml(yaml_path: str) -> EngineConfiguration- Loads and parses a YAML file.
-
from_yaml_content(yaml_content: str) -> EngineConfiguration- Loads configuration from a YAML string.
- Two-pass process:
- Pass 1: resolve enough secrets to load the secret service.
- Pass 2: re-render YAML template with full secret service available, then parse.
-
load_configuration(configuration_yaml: str | None = None) -> EngineConfiguration- Main entry point:
- If
configuration_yamlis provided: parse it directly (useful for tests). - Otherwise:
- Determine config file:
- If
ENVis set andconfig.{ENV}.yamlexists, use it. - Else use
config.yamlif it exists. - Else raise
FileNotFoundError.
- If
- Special case: if
ENVis not set, butconfig.yamlexists and contains a dotenv secret adapter, it will attempt to readENVfrom that.env.
- Determine config file:
- If
- Main entry point:
Configuration/Dependencies
YAML templating
- YAML is rendered using Jinja2 with a
secretobject available:- Example usage in YAML:
{{ secret.SOME_KEY }}
- Example usage in YAML:
Secret resolution order
-
During first pass (before secret service is loaded):
- Environment variables
- Bootstrap dotenv adapter (if configured in YAML under
services.secret.secret_adapterswithadapter: dotenv) - If still missing, a placeholder string is rendered into the template.
-
During second pass (after secret service is loaded):
- Environment variables
- Configured secret service
- If missing and TTY is available: prompt the user and store it in the secret service
- If missing and no TTY: raises
ValueError
Bootstrap dotenv adapter detection
_load_bootstrap_dotenv_adapter_from_yaml_content()scans the YAML for:services.secret.secret_adapters:- adapter: dotenvconfig.path(defaults to.env)
- If
config.pathis present but empty/invalid, it raisesValueError.
External dependencies used
pydantic(models and validation)yaml(PyYAML)jinja2(templating)rich(interactive prompting)- Various
naas_abi_core.engine.engine_configuration.*configuration classes naas_abi_core.services.secret.SecretandISecretAdapter
Usage
Load from default config 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)
Load from an in-memory YAML string (useful for tests)
from naas_abi_core.engine.engine_configuration.EngineConfiguration import EngineConfiguration
yaml_text = """
api:
title: "ABI API"
description: "API for ABI"
logo_path: "assets/logo.png"
favicon_path: "assets/favicon.ico"
cors_origins: ["http://localhost:9879"]
reload: true
services:
secret:
secret_adapters:
- adapter: dotenv
config:
path: ".env"
global_config:
ai_mode: "local"
skip_ontology_loading: false
modules:
- module: "naas_abi_core.modules.templatablesparqlquery"
enabled: true
config: {}
"""
config = EngineConfiguration.load_configuration(configuration_yaml=yaml_text)
print([m.module for m in config.modules])
Caveats
moduleswill be automatically augmented to include default modules if missing.- If a referenced secret is missing:
- In non-interactive environments (no TTY) it may raise
ValueErrorduring loading.
- In non-interactive environments (no TTY) it may raise
- A bootstrap dotenv adapter is only used if explicitly configured under
services.secret.secret_adapterswithadapter: dotenv.