A Component is any registered unit of functionality in Brain and must be one
of: Resource (L0), Service (L1), or Actor (L2). All Components must
self-register by calling register_component() from
lib/shared/manifest.py.
Check the Glossary for key terms such as Component, Manifest, Resource, Service, et cetera.
- Every Component has a globally unique
ComponentId. - Every Component declares
layer,system, and one or moremodule_roots. - Every L0 Resource and L1 Service exports a
health()contract. ComponentIdis schema-safe (^[a-z][a-z0-9_]{1,62}$).- Registration is global and process-local via
register_component(...). - Registry is the source of truth for identity and ownership validation.
- Services and Resources must expose
health(). - Each Component may apply its own internal timeout semantics.
- Core aggregate health enforces a global max timeout from
core.health.max_timeout_seconds; anyhealth()call exceeding that limit is unhealthy by definition.
- One global registry contains all Component types.
list_components()is the canonical complete view.- Ownership checks are enforced for L0/L1 relationships:
- on registration (non-strict owner existence; import-order tolerant)
- on
assert_valid()(strict owner existence)
An L0 Resource is Brain's interface to infrastructure with durable or real-world side effects. Each Resource governs one underlying Provider surface.
- Declared via
ResourceManifest. - Required:
id: ComponentIdlayer = 0kind in {"substrate", "adapter"}module_roots
- Optional:
owner_service_id(required in practice for owned Resources)
- L0 access is gated by owning L1 Service(s), never by L2 directly.
- Resource ownership must be explicit and unambiguous.
- Resource contracts should remain implementation-agnostic with respect to the underlying Provider where practical.
- If
owner_service_idis set, it must resolve to a registered L1 Service. - Resource IDs must match what owning Services declare in
owns_resources.
- Package should export a top-level
MANIFESTconstant that callsregister_component(ResourceManifest(...)). - Resource modules contain Substrate/Adapter implementation, not business policy.
An L1 Service is Brain business logic with authoritative public contracts.
Declared via ServiceManifest. Required:
id: ComponentIdlayer = 1system in {"state", "action", "control"}module_rootspublic_api_rootsowns_resources: FrozenSet[ComponentId]
- Services may call other Services only through their Public APIs.
- Services may not import other Services' internal implementations.
- Services gate all L0 access and enforce domain invariants/policy.
- Service ID is canonical for schema naming (
schema_name == ComponentId). - For PostgreSQL, which is a shared Substrate:
- each Service owns exactly its schema
- no cross-schema direct access
- no cross-Service foreign keys
- this means you have to do joins and RI in code; deal with it
- Service package should export
MANIFEST = register_component(ServiceManifest(...)). owns_resourcesmust list L0 Component IDs it owns.- If a Resource declares
owner_service_id, it must match the owning Serviceid. - Public API methods exposed must be decorated with
lib.shared.logging.public_api_instrumented(...)so invocation observability concerns (logging, metrics, tracing) remain consistent and composable across Services. - Typed contracts (settings, envelopes, request/response models, structured errors) should follow the Pydantic contract rules in Conventions.
- Service settings key definitions and override behavior should align with Configuration Reference.
Any Component may define an optional boot.py module for startup
orchestration. This is for cross-Component runtime coordination, not for
primary configuration loading.
- Core startup resolves configuration first.
- Boot hook orchestration runs after configuration is available.
- If any configured Component hook fails under configured retry/timeout policy, Core startup fails hard and exits with error.
dependencies: tuple[str, ...]is_ready(ctx: BootContext) -> boolboot(ctx: BootContext) -> None
dependenciescontainsComponentIdvalues for required upstream Components.is_ready(...)must be non-blocking and return readiness truthfully.boot(...)performs one-time startup work and must raise on failure.- Hooks receive runtime dependencies/settings via
BootContext; Components should not rely on mutable module globals for boot state.
Any Component may define an optional after_boot(...) function in its
component.py module for post-boot initialization that must run after all boot
hooks succeed.
after_boot(...)runs after global boot orchestration completes.after_boot(...)runs before the Core HTTP runtime starts serving.- If any
after_boot(...)hook raises, Core startup fails hard and exits with error.
- Signature:
after_boot(*, settings: BrainSettings, components: Mapping[str, object]) -> None settingsis fully resolved typed runtime configuration.componentsis the instantiated component map keyed byComponentId.
- Use this hook for post-boot initialization that requires a fully booted runtime graph.
- This hook is not a readiness gate and does not participate in boot retry/timeout policy.
- Hooks must be deterministic and raise on failure.
Capability packages are immutable runtime contracts owned by Capability Engine.
- Root location is
capabilities/. - Capability package discovery is recursive under that root.
- Intermediate directories may be used for grouping only.
- Each package directory is self-named in kebab-case and must exactly match
capability_id. - Required files in every package:
capability.jsonREADME.md
Oppackage:- manifest-only wrapper over primitive call target
- no required Python module
- Logic
Skillpackage:execute.pyentrypoint moduletest/with at least onetest_*.pyfile
- Pipeline
Skillpackage:- declarative
pipelinelist of steps - each step is either a capability ID string or an object with
capabilityplus optionalinput_mapping - no required Python module
- declarative
- Manifest schema is immutable at runtime.
capability_ididentifies the package and is the runtime invoke target.- Manifest
versionis semver and is audit metadata, not a runtime selector. - Exactly one runtime manifest version is active per
capability_id. - Registry validation is fail-closed at boot:
- invalid schema fails boot
- duplicate
capability_idfails boot, even across different grouping paths - unknown dependency or pipeline member fails boot
required_capabilitiesis allowed only on logic skills; other capability kinds must omit it.- Runtime overlays may not mutate capability manifests.
Each Component package should self-register at import time with a single
exported MANIFEST symbol:
- Service example:
services/state/<service>/__init__.py - Resource example:
resources/substrates/<resource>/__init__.py
This enables deterministic pre-flight checks and bootstrap orchestration from the global registry.
End of Component Design