AIKernel.NET
version: 0.0.2 / status: Refactor / edition: Draft / published: 2026-05-16 / updated: 2026-05-16

Execution Contract Architecture

Defines phase boundaries for Structure -> Generation -> Polish and the contracts that carry data across them.

1. Purpose

In conventional LLM application stacks (such as LangChain), a single prompt often combines "think", "write", and "polish" in one pass. This frequently causes expression concerns (style, ornamentation) to distort reasoning structure.

AIKernel separates these concerns into physical phases and places explicit contracts at each boundary to deliver:

  • Physical isolation of reasoning output vs expression output: prevents attention pollution where surface quality contaminates logical correctness.
  • Prevention of phase leakage: removes non-deterministic behavior such as "reason while writing."
  • Better auditability: makes it explicit where logic was finalized and where expression was applied.

2. Phase Definition and Flow

2.1 Structure Phase

  • Responsibility: produce only logical skeleton and solution data structure from input.
  • Constraint: decorative natural-language output is prohibited; only schema-conformant structured artifacts are allowed.
  • Contract: IThoughtProcess

2.2 Generation Phase

  • Responsibility: materialize approved Structure output into target format (Markdown, HTML, plain text, etc.).
  • Constraint: no independent reasoning is allowed; generation must remain a translation of approved structure.
  • Contract: IExecutionOutput

2.3 Polish Phase

  • Responsibility: apply tone/style normalization, forbidden-term checks, and formatting adjustments.
  • Constraint: reasoning content and factual meaning must not be changed.
  • Contract: IOutputPolisher

3. Core Contracts (Interface Definitions)

AIKernel.Core centers on the following abstractions.

  • IThoughtProcess
  • ThoughtArtifact Execute(OrchestrationContext context)
  • Contract for deriving reasoning conclusions; outputs must pass schema validation.
  • IExecutionOutput
  • RawOutput Materialize(ThoughtArtifact artifact, ExpressionContext context)
  • Contract for converting logical structure into expression form.
  • IOutputPolisher
  • FinalResult Polish(RawOutput raw)
  • Contract for final quality shaping and compliance polish.
  • ExecutionResult
  • Immutable container that holds phase outputs, model metadata, and signature metadata.

4. Boundary Rules

  • Unidirectional principle: data flow is always Structure -> Generation -> Polish; reverse flow and phase skipping are prohibited.
  • State isolation: Generation must not directly access raw OrchestrationContext; it must consume ThoughtArtifact.
  • No inference in Polish: if Polish uses an LLM, sampling parameters must be low-temperature and prompts must not induce additional reasoning.

5. Fail-Closed Rule

AIKernel prioritizes safe stop over uncertain continuation.

  • Schema Validation Failure: if Structure output violates declared JSON Schema, stop immediately and do not execute Generation.
  • Integrity Breach: if inter-phase hash/signature validation fails (tamper detection), stop execution.
  • Mandatory Field Missing: if required fields (for example ReasoningPath, Conclusion) are absent, mark as Fail even when output appears plausible.

6. Implementation Guidance (C# / .NET)

// DI-based composition image for the execution pipeline\npublic class ExecutionPipeline\n{\n    private readonly IThoughtProcess _planner;\n    private readonly IExecutionOutput _generator;\n    private readonly IOutputPolisher _polisher;\n\n    public async Task<ExecutionResult> RunAsync(InputData data)\n    {\n        // 1. Structure: finalize reasoning\n        var artifact = await _planner.ExecuteAsync(data);\n\n        // 2. Generation: convert to expression\n        var raw = await _generator.MaterializeAsync(artifact);\n\n        // 3. Polish: final adjustments\n        return await _polisher.PolishAsync(raw);\n    }\n}

Changelog

  • v0.0.0 / v0.0.0.0: Initial draft
  • v0.0.1 (2026-05-06): Version upgrade aligned with documentation guidelines
Source: architecture/8.EXECUTION_CONTRACT_ARCHITECTURE.md