agentleFS
topprismdatatopprismdata/cultivating-ml-agent/skills/examples/mcts-pipeline-search/SKILL.md

mcts-pipeline-search

Skill5 starsChanged 36 days agoMITView on GitHub

Use when exploring hyperparameter combinations for ML models, when doing Top-1% push on Kaggle, when grid search is too expensive, or when needing systematic exploration of pipeline variants. Triggers for neural architecture search, ensemble weight tuning, or feature subset selection.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When grid is too large for brute force

    line 101
  2. Distinctive:

    When evaluation is super expensive (MCTS = many evals)

    line 105

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

MCTS Pipeline Search

Context

Grid/random search wastes budget exploring dead branches. MCTS (Monte Carlo Tree Search) uses UCB1 to balance exploitation (best so far) and exploration (uncertain branches). agy recommends MCTS as P2 for Top-1% scenarios: used by AIDE for ML pipeline exploration, AlphaGo for game trees.

The core insight: UCB1 prevents both "stuck on suboptimal" and "random walk", getting best of both.

Guidance

Basic Usage

from framework.src.mcts import MCTSSearch, grid_expansion

# 网格定义
grid = {
    "num_leaves": [15, 31, 63, 127],
    "learning_rate": [0.01, 0.05, 0.1],
    "n_estimators": [100, 500, 1000],
}

# 评估函数: 真实 CV 或 proxy
def evaluator(config):
    return train_and_score(config)  # 返回 0-1 score

# 扩展: 网格生成子配置
expansion = grid_expansion(grid)

# 搜索
search = MCTSSearch(evaluator, expansion, max_depth=3)
result = search.search(initial_config={"num_leaves": 31}, iterations=100)

print(f"Best: {result.best_node.config}")
print(f"Score: {result.best_score:.3f}")
print(f"Tree size: {result.tree_size}")

Custom Expansion (Beyond Grid)

def my_expansion(config):
    """对当前 config 生成邻居(参数 ±10%)"""
    neighbors = []
    for delta in [-0.1, 0.1]:
        new = dict(config)
        new["learning_rate"] = max(0.001, config["learning_rate"] * (1 + delta))
        neighbors.append(new)
    return neighbors

Pipeline Search DAG

# 探索不同模型 pipeline 组合
def pipeline_evaluator(config):
    # config 包含: model_type, features, ensemble_method
    if config["model_type"] == "lgbm":
        return train_lgbm(config)
    elif config["model_type"] == "xgb":
        return train_xgb(config)
    elif config["model_type"] == "ensemble":
        return train_ensemble(config)

def pipeline_expansion(config):
    """从当前 pipeline 探索下一个组件"""
    next_steps = []
    for model in ["lgbm", "xgb", "catboost", "ensemble"]:
        new = dict(config)
        new["model_type"] = model
        next_steps.append(new)
    return next_steps

search = MCTSSearch(pipeline_evaluator, pipeline_expansion, max_depth=5)
result = search.search({"features": "basic"}, iterations=200)

Why This Matters

Grid SearchMCTS
O(grid_size) — slowO(iterations × branching) — adaptive
Wastes time on bad branchesUCB1 prunes via visits
No learning between configsBackprop updates scores
Single shotIterative refinement

agy: "MCTS Pipeline Search suitable for Top-1% competition push; expensive but can find non-obvious winners."

When to Apply

When to Use

  • Hyperparameter search with 4+ dimensions
  • ML pipeline architecture selection
  • Ensemble weight tuning
  • Final push on leaderboard (when baseline works)
  • When grid is too large for brute force

When NOT to Use

  • Small grids (just enumerate)
  • When evaluation is super expensive (MCTS = many evals)
  • Initial baseline (start simple)
  • Real-time applications (search takes minutes-hours)

Notes

  • Iteration count: 50-200 typical; more = better but slower
  • UCB1 weight: 1.414 (sqrt(2)) default; increase for more exploration
  • Depth limit: 3-5 typical; deeper = combinatorial explosion
  • Combine with warm start: seed MCTS with known good config
  • Cache evaluations: same config = same score (memoize)
  • See also: ml-sweet-spot, optuna-integration (alternative: Bayesian)

References

  • Implementation: framework/src/mcts/
  • Inspired by: AIDE ML pipeline search, MLZero MCTS (NeurIPS 2025)
  • Alternative: Optuna (Bayesian), Hyperopt (random search)
  • Algorithm: UCB1 (Auer et al. 2002), applied to ML by AIDE

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.