Context Engineering
repository·main·Indexed 27 days ago
https://github.com/jasontang-ai/context-engineeringA first-principles handbook and resource repository for the design and orchestration of the LLM context window. It includes a comprehensive 12-week course covering mathematical foundations, RAG systems, memory architectures (including reconstructive memory), multi-agent orchestration, and frontier research such as neural field theory, quantum semantics, and meta-recursive systems.
What's inside context-engineering
- The Context Engineering course is a comprehensive curriculum designed to take learners from foundational mathematical principles to frontier systems. It synthesizes research from a 2025 survey paper on Context Engineering for Large Language Models to provide a systematic progression of learning. The course is structured into four main phases: Foundations, System Implementations, Integration, and Frontier systems.
Overview of Advanced Cognitive Program Architecture
mainAdvanced cognitive programs are designed for sophisticated reasoning tasks using a cyclical architecture. The framework consists of three primary layers that interact in a loop:
- Planning Layer: Initiates the reasoning process by defining steps or strategies.
- Execution Layer: Carries out the tasks defined by the planning layer.
- Reflection Layer: Evaluates the outcomes of the execution and provides feedback to the planning layer to refine future actions.
This architecture enables adaptability and nuance through a continuous feedback loop between planning, execution, and reflection.
Overview of the Toy Chatbot Architecture
mainThe chatbot is structured into a layered Context Field Architecture:
- Core Layer: Basic conversation handling
- Protocol Layer: Field operations and resonance
- Memory Layer: Persistent attractor dynamics
- Meta Layer: Self-reflection and improvement
- Integration: Unified field orchestration
Overview of the Statistical Arbitrage Analysis System
mainThe project is a statistical arbitrage analysis system implemented as a Telegram bot for cryptocurrency spread trading. It uses a multi-stage pipeline to identify arbitrage opportunities through market filtering, synthetic spread creation, and rigorous statistical testing (stationarity and cointegration).
Core Components
- Bot Core (
test/main.py): Usesaiogram 3.4.1to handle user interactions and orchestration. Settings are stored insettings/*.json. - Statistical Analysis Pipeline: Includes
StationarityFilter,CointegrationTester,GrangerSettingsManager, andMarketDataFilter. - Calculation Engines: Includes
SpreadCalculator,BinanceLotCalculator, andCorrelation utilities.
- Bot Core (
Overview of Orchestration Capstone: From Components to Coherent Intelligence
mainThe Orchestration Capstone is the final module of the Context Engineering course. It focuses on transitioning from individual AI components to unified, coherent intelligent systems. The capstone is structured around three stages of mastery: Systems Architecture Mastery, Integration Virtuosity, and Adaptive Intelligence Design, with a final emphasis on Production Excellence.
The capstone architecture is divided into two primary movements:
- Movement I: Foundation Symphony (Weeks 9-10.1)
- Movement II: Emergence Concerto (Weeks 10.2-10.3)
Overview of Context Engineering Templates
mainThe
20_templatesdirectory contains reusable, composable components for implementing context engineering. Templates follow a progressive complexity model, moving from simple single-prompt 'atoms' to complex 'neural fields' that include persistence and cognitive tools.Complexity Model:
atoms(single prompt) $\rightarrow$molecules(few-shot) $\rightarrow$cells(memory/agents) $\rightarrow$organs(multi-agents) $\rightarrow$neural systems(cognitive tools/prompt programs) $\rightarrow$neural fields(fields + persistence).Understand the Context-Engineering Architecture Evolution
mainThe repository tracks its architectural evolution through versioned
STRUCTUREdocuments. Use these to understand the theoretical framework, implementation patterns, and directory organization.- v1.0 (
structure.md): Focuses on a biological metaphor (atoms → molecules → cells → organs). - v2.0 (
STRUCTURE_v2.md): Incorporates neural field theory, protocol shells, and concepts like attractors, resonance, boundaries, and emergence. - v3.0 (
STRUCTURE_v3.md): The current advanced meta-recursive architecture featuring meta-recursive frameworks, interpretability scaffolding, collaborative co-evolution, and cross-modal integration.
- v1.0 (
Understand Protocol-Driven Context Management
mainProtocol-driven context management uses structured templates to optimize token usage and prevent information truncation in AI models. Instead of unstructured text, context is organized into intentional allocations (e.g., System, History, Current, Field) to ensure critical information is preserved within the token budget.
This approach utilizes three complementary methods:
- Protocol Shells: Structured templates for organizing context.
- Pareto-lang: A declarative language for context operations.
- Fractal.json: Recursive patterns for token management.
Understand the spread analysis filtering pipeline
mainThe bot uses an 8-stage filtering system to identify high-quality arbitrage spreads:
- Data Acquisition: Loading and validating exchange data.
- Market Filters: Checking volume, liquidity, and volatility.
- Spread Creation: Forming and normalizing spreads using the formula
log((A*B)/(C*D)). - Asset Correlation: Verifying the relationship between assets.
- Fast Stationarity: Preliminary filtering for speed.
- Full Stationarity Tests: ADF, KPSS, Hurst exponent, Ljung-Box, and Granger tests.
- Cointegration: Engle-Granger and Johansen tests.
- Result: Outputting only high-quality arbitrage spreads.
Cross-modal integration principles and components
mainCross-modal integration in context engineering relies on several key conceptual components to ensure that moving between modalities (like text to image) does not result in information loss:
Integration Principles
- Unified Semantic Field: A shared space that transcends individual modalities.
- Bidirectional Translation: Moving information between forms while preserving core meaning.
- Modal-specific Strengths: Leveraging the unique properties of each modality (e.g., the precision of code vs. the nuance of text).
- Attractor Dynamics: Patterns that maintain stability and resonance across representational boundaries.
Core Protocols (The Synesthesia Model)
- Translation: Mapping between different modalities.
- Blending: Creating hybrid experiences where modalities overlap.
- Resonance: Identifying shared patterns of meaning across different inputs.
- Preservation: Ensuring the core semantics remain intact during transformation.
Understand Schema Pattern Architecture Layers
mainThe project defines a four-layered approach to robust schema architecture. When designing a data modeling system, you should organize your patterns into these layers:
- Meta-Schema Layer: Handles schema validation, management, pattern composition/inheritance, and cross-schema relationships.
- Domain Schema Layer: Focuses on business entity/concept modeling, domain-specific validation, and semantic relationships.
- Structural Pattern Layer: Provides reusable templates for common data structures, composition/aggregation, and standard validation idioms.
- Primitive Pattern Layer: Defines the fundamental building blocks like basic data types, core validation patterns, and serialization formats.
Understand Cognitive Program Structure
mainCognitive programs are structured, reusable prompt patterns that use programming concepts (variables, functions, control structures, and composition) to guide LLMs through reasoning processes.
A cognitive program follows this basic structure:
function programName(parameters) { // Processing logic return promptText; }