Aleph
Architecture

Thinker

LLM interaction layer, PromptBuilder with 29 layers, section caching, and thinking levels.

Thinker

The Thinker is responsible for all LLM interactions and decision making. It is the brain of the Think→Act loop.

Location: src/thinker/

The sole public entry point is thinker::PromptBuilder, which wraps a PromptPipeline. The old agent_loop::PromptBuilder was removed during the Harness migration (Phase 6/7).


Components

ComponentFilePurpose
ProviderRegistrymod.rsModel routing and provider resolution
PromptBuilderprompt_builder/Construct prompts from context
PromptPipelineprompt_pipeline.rsComposable prompt assembly engine
PromptLayerprompt_layer.rsTrait for individual prompt layers
InteractionManifestinteraction.rsChannel capability awareness
SecurityContextsecurity_context.rsPolicy-driven permissions
ContextAggregatorcontext.rsReconcile interaction and security
SoulManifestsoul.rsIdentity/personality definition
IdentityResolveridentity.rsLayered identity resolution
MemoryContextProvidermemory_context_provider.rsMemory retrieval for context injection
TokenBudgetprompt_budget.rsPrompt budget enforcement

PromptBuilder

// Standard usage
let builder = PromptBuilder::new(config);
let prompt = builder.build_system_prompt(&tools);

// With soul identity
let prompt = builder.build_system_prompt_with_soul(&tools, &soul, profile);

// Sub-agent usage (replaces old prompt_sections::resolve())
let prompt = builder.build_for_agent(&agent_def, &tools, &soul);

// Mode + budget control
let result = builder.build_with_budget(&tools, &soul, profile, PromptMode::Compact, &budget);

33 Layers

The prompt system assembles prompts from 33 ordered layers. Layers are split into two zones based on caching eligibility.

Stable Zone (Priorities 50–1600)

Content rarely changes — eligible for section-level caching.

PriorityLayerNotes
50SoulLayerIdentity / personality
55AgentRoleLayerSub-agent role header + protocol blocks
75ProfileLayerWorkspace profile overlay
100RoleLayerBase assistant role
300EnvironmentLayerOS, date, working directory
400RuntimeCapabilitiesLayerPython, Node.js, FFmpeg, etc.
500ToolsLayerTool definitions (text schema)
501HydratedToolsLayerSemantic-retrieval tool definitions
550ToolUsageGrammarLayerData-driven tool usage conventions
600SecurityLayerSafety / security guidelines
700ProtocolTokensLayerJSON-RPC protocol tokens
710HeartbeatLayerSession keep-alive instructions
800OperationalGuidelinesLayerOperational rules
900CitationStandardsLayerCitation formatting
1000GenerationModelsLayerAvailable image/video/audio models
1050SkillInstructionsLayerActive skill instructions
1100SpecialActionsLayerSpecial action syntax
1200ResponseFormatLayerResponse structure
1300GuidelinesLayerGeneral guidelines
1350ThinkingGuidanceLayerStructured reasoning guidance
1400SkillModeLayerStrict skill workflow enforcement
1500CustomInstructionsLayerUser custom instructions
1600LanguageLayerResponse language

Dynamic Zone (Priorities 1700–1760)

Per-request, never cached.

PriorityLayerNotes
1700InboundContextLayerSender, channel, session metadata
1704AgentCatalogLayerAvailable sub-agent catalog
1705McpInstructionsLayerMCP server instructions
1706McpToolIndexLayerMCP tool index entries
1710VoiceModeLayerVoice-specific response instructions
1720RuntimeContextLayerCurrent time, session info
1730IdentityFilesLayerSOUL.md, IDENTITY.md workspace files
1740MemoryAugmentationLayerDual-path memory injection
1750SessionContextGuideLayerCompressed session context guidance
1760SessionResumeLayerSession resume context

Assembly Paths

Each layer declares which paths it participates in. The pipeline filters by path at assembly time.

PathDescription
BasicMinimal — config + tool list only
HydrationTools come from semantic retrieval (HydrationResult)
SoulSoul-enriched — includes identity / personality
ContextContext-aware — uses ResolvedContext
CachedPre-cached stable prefix

Prompt Modes

ModeBehavior
Full (default)All 33 layers participate
CompactExcludes 13 heavy layers (RuntimeContextLayer, EnvironmentLayer, RuntimeCapabilitiesLayer, ProtocolTokensLayer, HeartbeatLayer, OperationalGuidelinesLayer, CitationStandardsLayer, GenerationModelsLayer, SkillInstructionsLayer, SpecialActionsLayer, GuidelinesLayer, ThinkingGuidanceLayer, SkillModeLayer)
MinimalOnly 5 core layers: SoulLayer, ToolsLayer, HydratedToolsLayer, ResponseFormatLayer, LanguageLayer

Section-Level Caching

execute_cached() caches the output of every LayerStability::Stable layer after the first call. Dynamic layers always recompute. ~23 of 33 layers are Stable.

pipeline.invalidate("soul");    // Invalidate one layer by name
pipeline.invalidate_all();      // Clear all cached sections
pipeline.cache_stats();         // CacheStats { hits, misses, entries }

Thinking Levels

pub enum ThinkingLevel {
    Off,        // No extended thinking
    Minimal,    // budget_tokens: 1024
    Low,        // budget_tokens: 2048
    Medium,     // budget_tokens: 4096 (default)
    High,       // budget_tokens: 8192
    XHigh,      // budget_tokens: 16384
}

Provider Fallback

When a provider doesn't support extended thinking, Aleph falls back gracefully:

User requests: thinking = High

    ├─▶ Claude Opus → ✓ Native extended thinking

    ├─▶ GPT-4o → ✗ No support → Fallback to o1

    └─▶ Gemini → ✗ No support → Use thinkingPreface prompt

Streaming Architecture

LLM Response Stream


┌─────────────────────────────────────────┐
│ BlockStateManager                        │
│   • Track current block type             │
│   • Detect block boundaries              │
└─────────────────────────────────────────┘


┌─────────────────────────────────────────┐
│ BlockReplyChunker                        │
│   • Split into semantic chunks           │
│   • Handle code blocks, lists, etc.      │
└─────────────────────────────────────────┘


┌─────────────────────────────────────────┐
│ BlockCoalescer                           │
│   • Merge small chunks                   │
│   • Emit complete blocks                 │
└─────────────────────────────────────────┘


Event: StreamChunk { content, block_type }

See Also

On this page