AIKernel Development Guidelines 0.1.0
This document is the official comprehensive development guideline for AIKernel.NET. It explains the design discipline that strictly separates contracts (interfaces), semantics (Result/Option/Either), and execution (DAG pipelines), and integrates that discipline with Interface Led Architecture (ILA) and the Provider-Observer-Operator (POO) model. It is written at a level that implementers, designers, reviewers, and documentation contributors can use directly without losing any required review element.
Overview
Purpose
- Define the design principles and implementation discipline required to keep
- Use ILA to confine implementation variance behind contracts, and use POO to
- Treat preserving Contracts and Skeletons as the first priority of any change.
AIKernel robust as an "AI OS".
clarify responsibilities.
Audience
- Core developers, provider implementers, runtime implementers, tool authors,
and documentation maintainers.
Terminology (Essentials)
- Interface / Contract: The public API and behavioral promise. This is the
- Skeleton: The DAG that defines execution order. It is executed by an
- Invariant: A condition that must not be broken during execution. It is the
- Provider: An implementation unit for external capabilities such as LLM,
- Observer: A unit responsible for monitoring, auditing, telemetry, and
- Operator: The executor of a pipeline or DAG. It behaves as a pure
center of ILA.
Operator.
basis of fail-closed behavior.
file system, network, and compute.
governance.
functional executor.
Overall View of ILA
Definition and Purpose of ILA
ILA (Interface Led Architecture) is an architectural principle that guarantees the following.
- Design interfaces first: Every behavior is defined as an interface.
- Freeze contracts: If contracts do not fluctuate, probabilistic
- Make skeletons explicit: Define the execution DAG clearly, and let an
- Define invariants: Document the conditions that must not be broken at
implementation behavior remains confined inside structure.
Operator execute it.
runtime.
Effects
- Implementation diffs and uncertainty introduced by AI generation can be
- Testing, auditing, and version management become easier.
- Safety and reproducibility improve.
absorbed by contracts.
Components of ILA
- Interface (Contract): Public API, types, error specification, and
- Unit: A set of semantically related interfaces.
- Skeleton: A DAG connecting units.
- Adapter: An implementation that satisfies an interface and is placed on
- Invariant: A runtime condition required by a contract.
- Governance: Auditing, validation, and metrics performed by Observers.
non-functional requirements.
the Provider side.
Provider Observer Operator Model (POO)
Responsibility Breakdown
Provider
- The boundary with the external world, including LLMs, file systems, networks,
- Encapsulates implementations that are probabilistic or side-effecting.
- Follows contracts and returns results through
Result<T>and related - Implements interfaces as an Adapter.
GPUs, Python runtimes, and similar capabilities.
primitives.
Observer
- Handles execution monitoring, auditing, and policy application.
- Performs telemetry, HashChain recording, logging, PDP (Policy Decision Point),
- Detects contract violations and invariant breaks, and generates alerts or
and replay validation.
replay data.
Operator
- A pure executor of pipelines and DAGs. It evaluates
ResultStepvalues in - Does not throw exceptions. All branches are represented by monads.
- Calls Providers, but does not enter Provider internal state.
- Executes Skeletons and follows Contracts.
order.
Mapping Between POO and ILA
- Interface is the shared contract between Providers and Operators.
- Unit is composed from Provider and Operator combinations.
- Skeleton is the Operator DAG. Observers monitor Skeleton execution.
- Invariant is protected jointly by Observers and Operators.
Observers audit it.
Detailed Guidelines
The following sections expand the original ten principles from the perspectives of ILA and POO. Each section includes purpose, rules, implementation examples, and a checklist.
1 Canonical Modules and Responsibility Boundaries
Purpose
- Clarify module boundaries and restrict dependencies to a DAG.
Rules
- Canonical modules are: **Core, Control, Providers, Wasm Runtime, Tools/CLI,
- Canonical modules interact only through interfaces. Direct implementation
- Dependencies between canonical modules must form a DAG. Cycles are strictly
and Demo**.
dependency is prohibited.
prohibited.
POO Mapping
- Core: Operator and Observer responsibilities. It is the fixed point for
- Providers: Provider. It contains Adapters for external capabilities.
- Control: Observer. It contains rule engines.
- Wasm Runtime: Operator. It forms an execution boundary.
- Tools/CLI: Provider in user land and Observer for operation logs.
- Demo: Reference Skeleton for Operators.
Contracts and Invariants.
Implementation Examples
- Core exposes an interface such as
IAIKernelCore, and the implementation - Providers implement
IProvider<TCapability>and receive Core
delegates to a thin Adapter.
IExecutionContext.
Checklist
- [ ] Are module references a DAG?
- [ ] Are public APIs defined as interfaces?
- [ ] Does implementation avoid crossing interface boundaries through direct
references?
2 DAG Principle
Purpose
- Keep execution semantics deterministic.
Rules
- Execution is defined as a DAG. Nodes are
ResultStepvalues and edges are - Branching is represented by monads. Use
Match; avoid manual branching. - DAG definitions are documented as Skeletons.
data dependencies.
POO Mapping
- The Operator executes the Skeleton. Providers supply capabilities outside the
nodes. Observers monitor DAG execution.
Implementation Examples
- Pipeline definitions are written in DSL and stored in ROM (read-only
- At runtime,
PipelineExecutortopologically sorts the DAG and evaluates
metadata).
ResultStep values.
Checklist
- [ ] Is the pipeline represented as a DAG?
- [ ] Does
ResultStepexecution minimize side effects? - [ ] Are all branches represented by monads?
3 Exceptionless Fail-Closed Principle
Purpose
- Prevent internal inconsistency from propagating outside the module.
Rules
- Do not use
throwinside Core internals. Internal code returns failures try/catchis used only at external-world boundaries such as Provider- Observers detect exceptions and failures, then produce logs and replay data.
through Result<T> and related primitives.
invocation layers, and converts exceptions into Result.
POO Mapping
- Operators do not throw exceptions. Providers absorb exceptions and return
Result. Observers audit the results.
Implementation Examples
- Provider HTTP calls convert timeouts and HTTP errors into
- Core functions return
Result<T>, and callers handle them withMatch.
Result<ProviderResponse>.
Checklist
- [ ] Is
throwabsent from Core internal execution paths? - [ ] Does the Provider layer convert exceptions into
Result? - [ ] Does the Observer record failure events?
4 Unified Monad Semantics
Purpose
- Handle branching and context propagation consistently.
Rules
- The supported monads are limited to
Result<T>,Option<T>, - Always use
Match. Manual state access such as.IsFailureand.Value! - Compose contexts with LINQ (
Select/SelectMany).
Either<L,R>, and ResultStep.
is prohibited.
POO Mapping
- The Operator executes purely with monads. Providers return results at monadic
boundaries. Observers observe monad states.
Implementation Examples
PipelineExecutorcomposes each step result with LINQ and propagates failureResultStep.Match(success => ..., failure => ...)is the standard pattern.
early.
Checklist
- [ ] Is branching represented by monads?
- [ ] Is manual state access absent?
- [ ] Is LINQ composition used where appropriate?
5 Interface and Adapter Separation
Purpose
- Absorb implementation differences through contracts and prevent breaking
changes.
Rules
- Every public API is defined by an interface. Implementations delegate to thin
- Interfaces represent Unit boundaries. Breaking interface changes must pass
- Adapters are confined to Providers. Core references only interfaces.
Adapters.
governance.
POO Mapping
- Providers implement Adapters. Operators use Providers through interfaces.
Observers inspect interface compliance.
Implementation Examples
- Define
ITextGenerationProvider, then implement OpenAI Adapter, LocalModel - Core injects and uses
ITextGenerationProvider.
Adapter, and Mock Adapter.
Checklist
- [ ] Are public APIs defined as interfaces?
- [ ] Does implementation avoid referencing beyond interface boundaries?
- [ ] Does the Adapter confine Provider side effects?
6 Versioning Rules
Purpose
- Preserve contract stability and dependency consistency.
Rules
- Canonical module
Versionis0.1.0.AssemblyVersionandFileVersion - Local development builds use
0.1.0-devX. Increment dev numbers according - NuGet references use exact ranges, for example
[0.1.0-dev42]. - Breaking changes go through the governance process. Observers perform version
are 0.1.0.0.
to dependency order.
compatibility checks.
POO Mapping
- Observers perform contract audits and version compatibility checks. Providers
follow Contracts. Operators execute Contracts.
Implementation Examples
- CI executes version compatibility tests and rejects merges when breaking
changes are detected.
Checklist
- [ ] Is
AssemblyVersionset to0.1.0.0? - [ ] Do NuGet references use exact ranges?
- [ ] Are breaking changes approved by governance?
7 Testing Principle
Purpose
- Automate contract preservation and guarantee execution reproducibility.
Rules
- Every canonical module must pass all tests in Release build.
- Test categories are Contract Tests (Operator), **Integration Tests
- Tests act as CI gates. Changes with failing tests cannot be merged.
(Provider), Replay Tests (Observer), and End-to-End Tests (Skeleton)**.
POO Mapping
- Operators have Contract Tests. Providers have Integration Tests. Observers
have Replay Tests.
Implementation Examples
- Contract Tests validate interface behavior with mocks.
- Integration Tests validate real Providers with isolated external
- Replay Tests replay logs recorded by Observers and verify identical results.
dependencies.
Checklist
- [ ] Are tests green for all canonical modules in CI?
- [ ] Do Contract Tests cover interface specifications?
- [ ] Do Replay Tests use Observer logs?
8 DRY KISS Pure Functions
Purpose
- Keep Core complexity low and improve verifiability.
Rules
- Core is based on side-effect-free pure functions. State is returned as
- Remove duplicated code and preserve single responsibility.
- Split complex logic into small pure functions.
context through monads.
POO Mapping
- This discipline preserves Operator purity. Providers confine side effects.
Observers observe side effects.
Implementation Examples
- Step logic is represented as
Func<Input, Result<Output>>. - State is gathered in
ExecutionContext, and changes propagate through
Result.
Checklist
- [ ] Are Core functions pure?
- [ ] Are side effects confined to Providers?
- [ ] Has duplication been removed?
9 Documentation Updates
Purpose
- Canonicalize design knowledge as ROM and make onboarding and audits easier.
Rules
- Code changes must update related documentation. Targets include Core user
- Contracts, Skeletons, and Invariants are made explicit in documentation.
guide, Providers guide, Wasm runtime guide, Tools CLI guide, and Demo guide.
Observers audit documentation diffs.
POO Mapping
- Observers manage the knowledge base (ROM) and externalize Contracts and
Skeletons.
Implementation Examples
- Place
architecture.md,contracts.md, andpipelines.mdunder - Require a "documentation updated" checklist item in PR templates.
docs/design/.
Checklist
- [ ] Does the change include related documentation updates?
- [ ] Are Contracts and Skeletons documented?
- [ ] Is Observer-based documentation diff checking integrated into CI?
10 Demo as Lightweight Reference Implementation
Purpose
- Show the smallest executable Skeleton example and make learning and
validation easier.
Rules
- Demo has minimal dependencies and focuses on showing Core Contracts and
- Demo does not use production Providers. It uses Mock Providers to show
- Demo is documented as an Operator execution example.
Skeletons.
behavior.
POO Mapping
- Demo is the reference Skeleton for Operators. It includes minimal Observer
logs. Providers are mocked.
Implementation Examples
- Place pipeline definitions, Mock Provider, and simple Observer under
- README documents execution steps and expected results.
demo/minimal.
Checklist
- [ ] Does Demo run with minimal dependencies?
- [ ] Does Demo clearly show the Skeleton?
- [ ] Are Demo logs collected by an Observer?
Practical Patterns and Anti-Patterns
Practical Patterns
- Adapter Pattern for Providers
- Define an interface, and each Provider implements an Adapter. The Adapter
- Pipeline as Data Structure
- Store pipelines as DSL/ROM and let the Executor interpret and execute them.
- Contract Tests First
- Define interfaces first, then write Contract Tests before implementation.
- Observer Replay
- Store execution logs with HashChain and validate reproducibility through
performs external API conversion and exception absorption.
Replay Tests.
Anti-Patterns
- Calling external APIs directly from Core
- If Core depends on Provider implementation, the Contract is broken.
- Throwing exceptions internally
- Internal
throwbreaks fail-closed behavior. - Manual state access
- Code that frequently uses
.IsFailureor.Value!is a common source of - Unapproved breaking interface changes
- Changes that break Contract compatibility must pass governance.
bugs.
Testing Strategy and CI Pipeline
Test Categories
- Contract Tests: Unit tests validating interface specifications and
- Integration Tests: Tests validating Provider implementations with real
- Replay Tests: Tests replaying Observer-recorded logs and verifying
- End to End Tests: Comprehensive Skeleton validation, including minimal E2E
Operator purity.
external dependencies isolated in the test environment.
identical results.
through Demo.
CI Gate
- Required checks: Release build, Contract Tests green, Integration smoke
- Version checks: NuGet exact range checks and AssemblyVersion checks.
- Observer Hooks: CI sends execution metadata to Observers and records it in
tests green, Replay Tests green, lint, and docs-updated flag.
HashChain.
Documentation Structure and Template
Recommended Directory Structure
docs/\n architecture.md\n contracts.md\n pipelines.md\n providers.md\n wasm_runtime.md\n tools_cli.md\n demo.md\n contributing.md
Required PR Template Items
- Change summary (What)
- Impacted scope (Which Units)
- Contract change existence (Yes/No)
- Test results (CI URL)
- Documentation update (Yes/No)
- Reviewer (Observer team)
Operational Governance
- Contract Change Process
- Breaking changes require an RFC and approval from the Observer team and Core
- Incident Handling
- When an Observer detects an invariant break, it automatically triggers
- Telemetry and Privacy
- Telemetry is minimal. Personal information is not collected. Observer logs
owners. Approval logs are recorded in HashChain.
fail-closed behavior and creates an incident ticket.
are access controlled.
Appendix
Mapping Table
| Principle | Provider | Observer | Operator |
|---|---|---|---|
| Canonical boundaries | Yes | Yes | Yes |
| DAG | Yes | ||
| Exceptionless | Yes (external absorption) | Yes (monitoring) | Yes (internal prohibition) |
| Monads | Yes | ||
| Interface/Adapter | Yes | Yes (interface-only reference) | |
| Versioning | Yes | Yes | |
| Testing | Yes (Integration) | Yes (Replay) | Yes (Contract) |
| DRY/KISS/Pure | Yes | ||
| Documentation | Yes | Yes | |
| Demo | Yes |
Execution Flow Diagram (Mermaid)
flowchart LR\n subgraph OperatorLayer\n DSL --> ROM\n ROM --> Pipeline\n Pipeline --> Executor\n Executor -->|ResultStep| StepA\n Executor -->|ResultStep| StepB\n end\n\n subgraph ProviderLayer\n StepA -->|calls| ProviderA\n StepB -->|calls| ProviderB\n end\n\n subgraph ObserverLayer\n Executor -->|telemetry| Observer\n ProviderA -->|telemetry| Observer\n ProviderB -->|telemetry| Observer\n end
Implementation Checklist (for PRs)
- [ ] Interface is defined
- [ ] Contract Tests are added or updated
- [ ] Provider Adapter confines side effects
- [ ] Operator does not throw exceptions
- [ ] Observer log points are added
- [ ] Documentation is updated
- [ ] CI is green
FAQ (Short)
Q: How should a Provider handle probabilistic output?
A: The Provider wraps the result in Result<T>, and the Operator handles that Result with Match. Probabilistic behavior is absorbed inside the Adapter.
Q: How should a breaking interface change proceed?
A: Create an RFC and obtain approval from Observers and Core owners. CI-based compatibility checks are mandatory.
Closing
This guideline fully integrates the AIKernel philosophy (contract purity, DAG, monads, fail-closed) with the ILA methodology and the Provider-Observer-Operator responsibility separation. Implementers should use this document as the baseline for design, implementation, and review.
guidelines/AIKERNEL_DEVELOPMENT_GUIDELINES.md