Meta Context Engineering (MCE)

February 11, 2026 · View on GitHub

Note: This repository contains the artifacts and assets from our Meta Context Engineering research. Please also visit the primary repository: metaevo-ai/meta-context-engineering

Overview

We introduce Meta Context Engineering (MCE), a bi-level framework that supersedes static CE heuristics by co-evolving CE skills and context artifacts. In MCE iterations, a meta-level agent refines engineering skills via agentic crossover, a deliberative search over the history of skills, their executions, and evaluations. A base-level agent executes these skills, learns from training rollouts, and optimizes context as flexible files and code. Our experiments evaluate MCE across five disparate domains under both offline and online settings. MCE demonstrates consistent performance gains, achieving 5.6--53.8% relative improvement over state-of-the-art agentic CE methods (mean of 16.9%), while maintaining superior context and adaptation efficiency.

Project Structure

mce-assets-public/
├── mce/                          # Core MCE framework
│   ├── main.py                   # Offline training loop
│   ├── main_online.py            # Online learning mode
│   ├── eval.py                   # Evaluation module
│   ├── base_agent.py             # Base-level agent (context optimizer)
│   ├── meta_agent.py             # Meta-level agent (skill evolver)
│   ├── llm_client.py             # LLM client with OpenRouter/OpenAI support
│   ├── prompts/                  # Agent prompts
│   └── workspace_utils/          # Utilities for workspace operations
├── env/                          # Evaluation environments
│   ├── aegis2/                   # AI safety classification
│   ├── finer/                    # XBRL financial entity recognition
│   ├── symptom_diagnosis/        # Medical symptom-to-disease mapping
│   ├── uspto/                    # Chemical retrosynthesis
│   ├── crime_prediction/         # Crime prediction task
│   └── base.py                   # Base environment interface
├── assets/                       # Pre-trained assets
│   ├── context/                  # Learned context artifacts per environment
│   │   ├── aegis/mce/            # MCE-learned context for aegis
│   │   ├── finer/mce/            # MCE-learned context for finer
│   │   └── ...
│   └── skills/                   # CE skills per environment
│       ├── finer/                # Initial and optimal skills
│       └── ...
├── scripts/                      # Training and evaluation scripts
│   ├── train_*.sh                # Offline training scripts
│   ├── train_*_online.sh         # Online training scripts
│   └── eval_*_mce.sh             # Evaluation scripts
├── pyproject.toml                # Project dependencies
└── .env.template                 # Environment variables template

Installation

# Install uv
curl -fsSL https://astral.sh/uv/install.sh | sh

# Install dependencies
uv sync
uv pip install -e .

Configuration

Copy .env.template to .env and set your API keys:

cp .env.template .env

The system uses OpenRouter by default with automatic fallback to OpenAI:

# Option 1: OpenRouter (recommended)
export OPENROUTER_API_KEY="your-api-key"
export OPENROUTER_API_BASE="https://openrouter.ai/api/v1"

# Option 2: OpenAI (fallback if OpenRouter not set)
export OPENAI_API_KEY="your-api-key"
export OPENAI_API_BASE="https://api.openai.com/v1"  # Optional

# To use Claude agent SDK
export ANTHROPIC_API_KEY="your-anthropic-api-key"

# If you are using OpenRouter
export ANTHROPIC_BASE_URL=https://openrouter.ai/api
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
export ANTHROPIC_API_KEY=""

# Set default models for Claude agent SDK
export ANTHROPIC_DEFAULT_SONNET_MODEL="minimax/minimax-m2.1"
export ANTHROPIC_DEFAULT_OPUS_MODEL="minimax/minimax-m2.1"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="minimax/minimax-m2.1"

E2B Sandbox (TODO, currently not tested)

For isolated agent execution in cloud sandboxes:

export E2B_API_KEY="your-e2b-api-key"

Note: E2B sandboxes on the Hobby billing plan have a default timeout of 1 hour. For long-running tasks, you can periodically resume training from checkpoints.

Usage

Quick Start with Scripts

The scripts/ directory contains ready-to-use training and evaluation scripts for all environments:

ScriptDescription
train_aegis.shOffline training for AI safety (aegis2)
train_finer.shOffline training for XBRL tagging
train_s2d.shOffline training for symptom-to-disease
train_uspto.shOffline training for retrosynthesis
train_crime_prediction.shOffline training for crime prediction
train_*_online.shOnline learning variants
eval_*_mce.shEvaluate MCE-learned context

Run any script directly:

bash scripts/train_finer.sh
bash scripts/eval_finer_mce.sh

Offline Training (mce.main)

Offline training uses a bi-level loop where meta-agent evolves skills and base-agent optimizes context:

uv run python -m mce.main \
    --workspace "workspace/finer" \
    --env "finer" \
    --train-data "env/finer/data/train.jsonl" \
    --val-data "env/finer/data/val.jsonl" \
    --model "deepseek/deepseek-chat-v3.1" \
    --iterations 5 \
    --start-iter 1 \
    --train-limit 200 \
    --val-limit 100 \
    --log-dir "logs/finer" \
    --train-batch-size 50

Offline Training Arguments

ArgumentDescriptionDefault
--workspacePath to workspace directory (required)-
--envEnvironment name: finer, aegis2, symptom_diagnosis, uspto, crime_prediction (required)-
--train-dataPath to training data JSONL file-
--val-dataPath to validation data JSONL file-
--modelLLM model for evaluation (OpenRouter format)deepseek/deepseek-chat-v3.1
--iterationsNumber of MCE iterations1
--start-iterStarting iteration number (for resuming)1
--train-limitNumber of training samples per iteration50
--val-limitNumber of validation samples20
--train-batch-sizeBatch size for sub-iterations50
--log-dirDirectory for log fileslogs
--evolve-retrievalEnable retrieval function evolutionFalse
--skill-pathPath to pre-evolved skill (skips meta-agent)None
--no-meta-agentSkip meta-agent entirely (no skills)False
--use-e2bRun agents in E2B sandboxFalse

Online Learning (mce.main_online)

Online mode learns directly from test data without a separate training/validation split:

uv run python mce/main_online.py \
    --workspace "workspace/finer_online" \
    --env "finer" \
    --test-data "env/finer/data/test.jsonl" \
    --test-limit 100 \
    --train-batch-size 5 \
    --data-accumulation-limit 0 \
    --model "deepseek/deepseek-chat-v3.1" \
    --log-dir "logs/finer_online"

Online Learning Arguments

ArgumentDescriptionDefault
--workspacePath to workspace directory (required)-
--envEnvironment name (required)-
--test-dataPath to test data JSONL file (required)-
--test-limitTotal test samples to process100
--train-batch-sizeSamples per batch20
--data-accumulation-limitMax accumulated samples (0 = unlimited)0
--modelLLM model for evaluationdeepseek/deepseek-chat-v3.1
--skill-pathPath to initial skill directoryNone
--log-dirDirectory for log fileslogs
--continue-trainingResume from last completed sub-iterationFalse
--use-e2bRun agents in E2B sandboxFalse

Evaluation (mce.eval)

Evaluate learned context on test data:

uv run python -m mce.eval \
    --iter_dir "assets/context/finer/mce/context-l" \
    --env "finer" \
    --data "env/finer/data/test.jsonl" \
    --limit 500 \
    --model "deepseek/deepseek-chat-v3.1" \
    --save-results-to "results/finer_mce"

Evaluation Arguments

ArgumentDescriptionDefault
--iter_dirPath to context directory with retrieve_context.py-
--envEnvironment name (required)-
--dataPath to test data JSONL file (required)-
--limitNumber of samples to evaluate500
--modelLLM model for evaluationdeepseek/deepseek-chat-v3.1
--save-results-toDirectory to save results (required)-

Using Pre-trained Context

The assets/context/ directory contains MCE-learned context for each environment. To evaluate:

bash scripts/eval_finer_mce.sh
bash scripts/eval_aegis_mce.sh
bash scripts/eval_symptom_mce.sh
bash scripts/eval_crime_prediction_mce.sh
bash scripts/eval_uspto_mce.sh

Citation

If you find this work useful, please kindly give it a star and cite:

@misc{ye2026mce,
    title={Meta Context Engineering via Agentic Skill Evolution},
    author={Haoran Ye and Xuning He and Vincent Arak and Haonan Dong and Guojie Song},
    year={2026},
    eprint={2601.21557},
    archivePrefix={arXiv},
    primaryClass={cs.AI},
    url={https://arxiv.org/abs/2601.21557},
    note={Code available at \url{https://github.com/metaevo-ai/meta-context-engineering}},
}

License

MIT License