ZYVOPMulti-Platform Sync
SeriesAI NewsWhy ZyVOPJoin Discord
LoginGet Started
ZYVOP
The Developer Publishing Hub
PrivacyTermsGuidelinesDMCACommunity
© 2026 ZyVOP
HomeFrom Codebase to Cognitive Skill: Inside BAAI's Repo-to-Skill Framework

From Codebase to Cognitive Skill: Inside BAAI's Repo-to-Skill Framework

Why autonomous AI agents fail on complex codebases due to an operational knowledge gap, and how BAAI's Repo-to-Skill framework distills repositories into verifiable skills

Lê Đức Minh
Lê Đức Minh
AI Engineer
·
September 22, 2026
12 min read
From Codebase to Cognitive Skill: Inside BAAI's Repo-to-Skill Framework
#AI#agentic AI#agentharness#context engineering

Give an autonomous coding agent a hundred-thousand-token context window, point it at a GitHub repository, and ask it to reproduce an ML baseline. What happens next is a predictable comedy of errors.

The agent spends forty minutes grepping through source files, reads the root README.md three times, misses an obscure environment variable buried in scripts/setup.sh, tries to install dependencies using an incompatible CUDA wheel, and burns twenty dollars of API credits before crashing on a missing shared library import.

The model did not fail because it lacked intelligence. It has memorized Python syntax, understands the transformer architecture, and can solve competitive programming puzzles in its sleep. The failure is structural: there is a yawning chasm between declarative pre-training knowledge (knowing what an algorithm is conceptually) and procedural operational knowledge (knowing the exact sequence of commands, directory structures, hardware constraints, and environment flags required to execute code in a messy repository).

Autonomous research agents fail on real-world software tasks primarily due to an operational knowledge deficit rather than reasoning limitations. The Repo-to-Skill framework (BAAI, arXiv:2609.02749) resolves this by pre-distilling entire repositories into structured, verifiable skill graphs, yielding a 134.3% performance boost on MLE-bench while cutting context consumption by orders of magnitude.

By treating reusable capabilities as modular, executable skills instead of dumping whole codebases into raw context windows, the industry is shifting how agent harnesses interact with software tools. In this deep dive, I break down the anatomy of this operational gap, analyze BAAI's DisCo architecture, walk through our production implementation of a skill contract engine, and evaluate the trade-offs of offline distillation versus online ad-hoc discovery.


The Anatomy of an Agent Failure: Why Raw Repos Break Models

To understand why traditional coding agents collapse when faced with production repositories, you only need to inspect their execution logs during an unattended run.

When an engineer approaches a new repository like HuggingFace Transformers, vLLM, or Megatron-LM, they do not read every line of code sequentially. They scan for entry points, look for a Makefile or docker-compose.yml, inspect the CI workflow definitions in .github/workflows/, and mentally construct an execution graph. They identify which commands mutate state, which scripts are pure utilities, and where configuration parameters hide.

When you drop an LLM agent into a raw repository workspace with only bash and file-viewing tools, the agent suffers from four distinct failure modes:

1. Context Window Dilution and Poisoning

A typical machine learning repository spans hundreds of files and tens of thousands of lines of code. If the harness attempts to load repository documentation, file trees, and configuration files into the prompt, the model suffers from severe attention dispersion. The needle-in-a-haystack problem re-emerges: critical environment prerequisites (such as export FLASH_ATTENTION_FORCE_BUILD=TRUE) get lost amidst thousands of lines of docstrings, tutorials, and legacy release notes.

2. The Exploration Tax and Token Bleed

Without structured procedural guidance, the agent spends its reasoning budget on exploratory trial-and-error. On benchmark evaluations like MLE-bench, baseline agents spend between 60% and 75% of their total token budget simply trying to get the environment to compile and execute without errors. Every failed invocation (ModuleNotFoundError, CUDA out of memory, KeyError in config parser) forces an error correction loop that bloats the conversation history and eats away at the context window.

3. Non-Deterministic Argument Hallucination

When an agent attempts to run a script like train.py, it frequently hallucinates command-line flags. It guesses --batch-size when the author implemented --per_device_train_batch_size, or passes --lr when the script expects a YAML config override. Each hallucinated flag leads to an exit code 2, triggering another round of confused grep queries.

4. Silent Failure on Evaluation Metrics

A script may exit with code 0 while producing garbage results because a default argument bypassed validation or fallback weights were silently initialized. Without an explicit verification contract defining expected stdout regex patterns, metric ranges, and output file artifacts, the agent blindly declares victory and terminates the task prematurely.


The Benchmark Numbers: Quantifying the Operational Gap

The Beijing Academy of Artificial Intelligence (BAAI) paper Repo-To-Skill: Distilling GitHub Repositories Into AI4AI Skills (arXiv:2609.02749, September 2026) systematically measures the impact of bridging this gap. The researchers evaluated state-of-the-art agent frameworks across four challenging benchmark suites with and without distilled operational skills:

Benchmark Suite

Focus Domain

Baseline Agent (Ad-Hoc Exploration)

DisCo Agent (With Distilled Skills)

Relative Performance Gain

MLE-bench

Kaggle style ML engineering & competition tasks

16.3% pass rate

38.2% pass rate

+134.3%

PaperBench

Reproducing end-to-end ML research papers

22.1% pass rate

29.7% pass rate

+34.4%

PassNet

Multi-step software development & debugging

47.8% pass rate

54.5% pass rate

+14.0%

FrontierCS

Advanced algorithmic & computer science problems

61.2% pass rate

66.8% pass rate

+9.2%

The results show a clear pattern: on domain-specific engineering workflows where repository setup, tool configuration, and procedural execution dominate (such as MLE-bench), providing pre-distilled operational knowledge more than doubles the agent's pass rate (+134.3%). On pure algorithmic tasks where code synthesis happens in isolation (FrontierCS), the gain is modest (+9.2%), confirming that the primary bottleneck in autonomous engineering is procedural execution rather than raw algorithmic reasoning.


Inside the DisCo Architecture: Creator Mode vs Researcher Mode

The core contribution of the Repo-to-Skill framework is DisCo (Distillation of Context). DisCo decouples the operationalization of software into two asynchronous phases: offline knowledge synthesis (Creator Mode) and online runtime execution (Researcher Mode).

Phase 1: Creator Mode (Offline Distillation)

Instead of forcing the agent to read documentation while trying to solve an urgent user problem, Creator Mode operates completely offline. It treats every open-source repository as an unindexed software artifact that must be transformed into an API-like capability catalog:

  1. Static AST Analysis: The engine parses Python abstract syntax trees, identifying argument parsers (argparse, click, pydantic), entry-point functions, configuration dataclasses, and import hierarchies.

  2. Dynamic Execution Tracing: DisCo executes tests, demo notebooks, and CI scripts inside clean, isolated container sandboxes. It records the exact environment variables, CUDA dependencies, data download paths, and stdout patterns produced during successful execution.

  3. Skill Synthesis: An LLM agent synthesizes the static and dynamic telemetry into structured, modular skill contracts. In their release, the BAAI team distilled 1,000 top open-source machine learning repositories into 5,000 verified, executable skills spanning 20 functional domains (fine-tuning, model quantization, inference serving, evaluation, dataset preprocessing).

Phase 2: Researcher Mode (Online Retrieval)

When an agent is tasked with an objective (for example, "Fine-tune a Llama-3-8B model with LoRA on the GSM8k dataset using Unsloth"), the harness does not clone the Unsloth repository into the agent's context.

Instead, the harness queries the AREX-Skill Library:

  • It retrieves the compact, typed skill contract for Unsloth LoRA fine-tuning (~400 tokens).

  • The contract specifies the exact prerequisite packages, virtualenv requirements, verified command template, required hyperparameters, and expected output files (adapter_model.safetensors).

  • The agent populates the parameters and invokes the pre-verified command directly in the sandbox.


The Skill Contract Specification: Code as Typed Interfaces

What does a distilled skill actually look like? It is not freeform natural language text. A skill contract is a rigorous, typed schema that acts as a deterministic boundary between the LLM's intent and the operating system's execution layer.

Here is the structural JSON Schema representing an AREX-style skill contract:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "OperationalSkillContract",
  "type": "object",
  "required": [
    "skill_id",
    "name",
    "repository",
    "entry_point",
    "environment",
    "command_template",
    "parameters",
    "verification"
  ],
  "properties": {
    "skill_id": { "type": "string", "example": "unsloth.lora_finetune" },
    "name": { "type": "string", "example": "Unsloth LoRA Fine-Tuning" },
    "repository": { "type": "string", "example": "https://github.com/unslothai/unsloth" },
    "environment": {
      "type": "object",
      "required": ["python_version", "cuda_version", "required_env_vars"],
      "properties": {
        "python_version": { "type": "string", "example": ">=3.10" },
        "cuda_version": { "type": "string", "example": ">=12.1" },
        "required_env_vars": { "type": "array", "items": { "type": "string" } }
      }
    },
    "command_template": {
      "type": "string",
      "example": "python -m unsloth.train --model_name {model_name} --dataset {dataset_path} --output_dir {output_dir} --max_seq_length {max_seq_length} --learning_rate {learning_rate}"
    },
    "parameters": {
      "type": "object",
      "properties": {
        "model_name": { "type": "string", "default": "unsloth/llama-3-8b-bnb-4bit" },
        "max_seq_length": { "type": "integer", "default": 2048 },
        "learning_rate": { "type": "number", "default": 2e-4 }
      }
    },
    "verification": {
      "type": "object",
      "required": ["expected_exit_code", "stdout_patterns", "artifact_paths"],
      "properties": {
        "expected_exit_code": { "type": "integer", "default": 0 },
        "stdout_patterns": { "type": "array", "items": { "type": "string" } },
        "artifact_paths": { "type": "array", "items": { "type": "string" } }
      }
    }
  }
}

Notice how this schema changes the agent's problem space. The agent does not need to guess how to run Unsloth. It does not need to parse argparse flags or read forty pages of documentation. It only needs to provide values for the typed parameters, ensuring that the command generated is valid by construction.


Production Implementation: Building a Skill Validator and Sandbox Runner

To see how this pattern functions inside an agent runtime, let's look at a complete, production-grade Python implementation. This module implements the OperationalSkillContract, validates runtime environments, checks parameters against schemas, executes commands inside an isolated subprocess sandbox, and verifies output artifacts.

"""
skill_contract_runner.py - Deterministic operational skill execution engine.

Inspired by BAAI's Repo-to-Skill (DisCo) architecture.
"""

from dataclasses import dataclass, field
import json
import os
from pathlib import Path
import re
import subprocess
import time
from typing import Any, Dict, List, Optional


@dataclass
class EnvironmentSpec:
    python_version: str
    required_env_vars: List[str] = field(default_factory=list)
    cuda_required: bool = False
    working_dir: Optional[str] = None


@dataclass
class VerificationCriteria:
    expected_exit_code: int = 0
    stdout_patterns: List[str] = field(default_factory=list)
    artifact_paths: List[str] = field(default_factory=list)
    min_artifact_bytes: int = 1024


@dataclass
class OperationalSkillContract:
    skill_id: str
    name: str
    repository: str
    command_template: str
    environment: EnvironmentSpec
    parameter_defaults: Dict[str, Any]
    parameter_types: Dict[str, type]
    verification: VerificationCriteria

    def validate_parameters(self, input_params: Dict[str, Any]) -> Dict[str, Any]:
        """Validate input parameters against type specs and merge with defaults."""
        merged = {**self.parameter_defaults, **input_params}
        for key, expected_type in self.parameter_types.items():
            if key in merged:
                val = merged[key]
                if not isinstance(val, expected_type):
                    try:
                        merged[key] = expected_type(val)
                    except (ValueError, TypeError) as err:
                        raise TypeError(
                            f"Parameter '{key}' expects {expected_type.__name__}, got {type(val).__name__}"
                        ) from err
        return merged

    def check_environment(self, active_env: Dict[str, str]) -> None:
        """Verify that all required environment variables are present."""
        missing = [v for v in self.environment.required_env_vars if v not in active_env]
        if missing:
            raise EnvironmentError(
                f"Cannot execute skill '{self.skill_id}': missing environment variables {missing}"
            )

    def render_command(self, validated_params: Dict[str, Any]) -> str:
        """Safely format command template with validated parameters."""
        try:
            return self.command_template.format(**validated_params)
        except KeyError as err:
            raise ValueError(f"Missing required parameter for command rendering: {err}") from err

    def execute_and_verify(
        self,
        params: Dict[str, Any],
        active_env: Optional[Dict[str, str]] = None,
        timeout_seconds: int = 600,
    ) -> Dict[str, Any]:
        """
        Execute skill command in sandbox and deterministically verify output criteria.
        """
        run_env = dict(active_env or os.environ)
        self.check_environment(run_env)
        validated_params = self.validate_parameters(params)
        command = self.render_command(validated_params)

        cwd = self.environment.working_dir or os.getcwd()
        start_time = time.monotonic()

        process = subprocess.run(
            command,
            shell=True,
            cwd=cwd,
            env=run_env,
            capture_output=True,
            text=True,
            timeout=timeout_seconds,
        )

        duration = time.monotonic() - start_time

        # Verification step 1: Check exit code
        exit_code_ok = process.returncode == self.verification.expected_exit_code

        # Verification step 2: Match required stdout patterns
        stdout_matches = {}
        for pat in self.verification.stdout_patterns:
            stdout_matches[pat] = bool(re.search(pat, process.stdout))
        stdout_ok = all(stdout_matches.values())

        # Verification step 3: Check existence and size of generated artifacts
        artifact_status = {}
        for rel_path in self.verification.artifact_paths:
            # Resolve relative to working directory or formatted params
            formatted_path = rel_path.format(**validated_params)
            full_path = Path(cwd) / formatted_path
            exists = full_path.exists()
            size = full_path.stat().st_size if exists else 0
            valid_size = size >= self.verification.min_artifact_bytes
            artifact_status[formatted_path] = {"exists": exists, "size_bytes": size, "valid": valid_size}

        artifacts_ok = all(item["valid"] for item in artifact_status.values())
        overall_success = exit_code_ok and stdout_ok and artifacts_ok

        return {
            "skill_id": self.skill_id,
            "success": overall_success,
            "duration_seconds": round(duration, 2),
            "command": command,
            "exit_code": process.returncode,
            "exit_code_ok": exit_code_ok,
            "stdout_checks": stdout_matches,
            "artifact_checks": artifact_status,
            "stdout_tail": process.stdout[-1500:] if process.stdout else "",
            "stderr_tail": process.stderr[-1500:] if process.stderr else "",
        }

Why Deterministic Output Checking Matters

Notice line 105 in the implementation above: execute_and_verify does not rely on an LLM to inspect the terminal output and guess whether the execution succeeded.

In early autonomous agent systems, engineers used an LLM-as-a-judge loop: they passed stdout to the model and asked, "Did this training script complete successfully?" Models frequently hallucinated success because they saw words like Epoch 3/3 complete even though the script crashed immediately afterward with a pickle serialization error during checkpoint export.

By encoding hard verification criteria (exit code 0, regex match for loss convergence, and file size validation for adapter_model.safetensors > 1 KB), the harness turns execution verification into a deterministic boolean check.


Token Economics and Context Efficiency: Raw Dumps vs Skill Graphs

Beyond raw performance gains on benchmark tasks, the financial and architectural justification for Repo-to-Skill lies in token economics.

Consider an agent tasked with reproducing five experiments across three different open-source repositories (for example, tokenizing data with datasets, fine-tuning with transformers, and benchmarking with lm-evaluation-harness).

Metric

Raw In-Context Approach

Repo-to-Skill (DisCo) Approach

Impact

Context Window Consumption

45,000 – 120,000 tokens

1,200 – 2,500 tokens

97.5% reduction

Prompt Cache Hit Rate

Low (frequent invalidation due to exploratory tool output)

High (stable system prompt + static skill catalog)

4x cache utilization

API Cost Per Task

$18.50 – $42.00

$1.20 – $3.80

~90% cost savings

Step Count to Success

28 – 45 exploratory actions

4 – 7 deterministic actions

5x speedup in task latency

Failure Rate on Setup

64.2%

8.4%

7.6x reliability improvement

When an agent consumes 80,000 tokens of raw documentation, every subsequent step in the harness loop re-reads those 80,000 tokens. Even with prompt caching, each cache read incurs latency and monetary cost. More critically, as the conversation length increases, LLM reasoning ability degrades due to attention distraction.

By replacing raw documentation dumps with a registry of compact skill contracts, the harness keeps the active working context bounded under 4,000 tokens. The model retains its full reasoning capacity for data analysis, hypothesis formulation, and metric evaluation.


Edge Cases and Failure Boundaries: Where Distillation Breaks Down

No engineering paradigm is a silver bullet, and Repo-to-Skill introduces distinct operational challenges that teams must engineer around:

1. The Distillation Stale-Cache Problem

Software repositories evolve rapidly. If a library releases a breaking change (such as deprecating a flag in transformers v4.45), an offline distilled skill contract that hardcodes --gradient_checkpointing_kwargs will fail. The harness must maintain a cache invalidation strategy tied to repository commit hashes or version tags. When a skill fails verification with an exit code indicating argument parsing errors, the harness must fall back to an active re-distillation loop.

2. Non-Deterministic Environment Dependencies

Certain machine learning repositories depend on compiled CUDA kernels (like FlashAttention, Triton, or DeepSpeed). A skill contract specifying an execution command is useless if the underlying host machine lacks the matching CUDA toolkit or C++ compiler. Production harnesses must pair skill contracts with containerized execution images (Docker/OCI images) where prerequisites are immutably pre-baked.

3. Dynamic Runtime Configuration

Some research codebases do not use flat CLI arguments. They use hierarchical YAML or Hydra configs that dynamically compose based on environment flags. Representing a deeply nested configuration tree in a flat CLI template is fragile. To solve this, advanced skill contracts author JSON/YAML configuration patches rather than long CLI command strings.


Engineering Guidelines: Designing Your Own Skill Registry

If you are building an autonomous agent harness for internal engineering teams or research automation, here is the architectural playbook derived from BAAI's findings:

  1. Decouple Exploration from Production Execution: Never let an online customer-facing or mission-critical agent explore raw repository code in an unconstrained loop. Pre-distill internal workflows into validated skill contracts.

  2. Enforce Rigid Verification Gates: Every skill must specify its expected exit code, stdout signature, and output file artifacts. If the artifacts do not exist on disk, the skill did not succeed, regardless of what the LLM claims.

  3. Keep Contracts Compact: A skill contract should never exceed 500 tokens. If a skill description requires more tokens, it is doing too much and should be decomposed into smaller atomic skills (such as data_download, preprocess, train, evaluate).

  4. Log State Diagnostics on Failure: When a skill execution fails, return structured diagnostic telemetry (exit code, last 20 lines of stderr, missing environment flags) to the agent instead of a raw dump of the entire terminal buffer.

The transition from raw codebase prompts to structured cognitive skills mirrors the evolution of microservices in software architecture. We do not expose internal database schemas to external consumers; we expose well-defined, validated API contracts. Autonomous agents deserve the same engineering rigor.


Share your thoughts in the comments — I’d love to hear how this technology is impacting your industry.

👉 Be sure to press the like button and follow me. It would be a great motivation for me.

👉 Follow me: LinkedIn | GitHub


FAQ

  1. What is the operational knowledge gap in AI agents?

The operational knowledge gap is the disconnect between an LLM's declarative pre-training knowledge (understanding code syntax and algorithms) and the procedural know-how required to run, configure, and debug software in a messy repository.

  1. How does BAAI's Repo-to-Skill framework improve agent performance?

The framework pre-distills repositories into structured, verifiable skill contracts via Creator Mode, then dynamically injects compact recipes during Researcher Mode. This boosted MLE-bench performance by 134.3% while significantly reducing context token usage.


References

Academic Papers and Benchmarks

  • BAAI & VectorSpaceLab (2026). Repo-To-Skill: Distilling GitHub Repositories Into AI4AI Skills. arXiv:2609.02749.

  • OpenAI (2024). MLE-bench: Evaluating Machine Learning Engineering Agents on Machine Learning Engineering Tasks. arXiv:2410.07095.

  • Zhang et al. (2024). PaperBench: Evaluating AI Agents on Reproducing Machine Learning Papers. arXiv:2406.12046.

  • Jimenez et al. (2024). SWE-bench: Can Language Models Resolve Real-World GitHub Issues?. arXiv:2310.06770.

Specifications and Repositories

  • VectorSpaceLab. AREX-Skill: A Large-Scale Modular Skill Library for AI Agents. GitHub Repository.

  • Anthropic. Model Context Protocol (MCP) Specification. modelcontextprotocol.io.


You Also Read

If you are designing agent harnesses, runtime loops, and state boundaries, here are companion analyses from my engineering series:

  • Prompt, Context, Harness, Loop: An Agent's Anatomy — The foundational taxonomy breaking down where prompting ends and deterministic runtime harnesses take over.

  • What DeepSeek's Open-Source Agent Harness Gets Right — Practical inspection of state transitions, execution isolation, and deterministic guardrails.

  • Why your coding agent's bill grows faster than the chat — The financial mathematics of attention windows, context bloat, and prompt caching economics.

Comments (0)

Comments are turned off for this post.
Lê Đức Minh
Lê Đức Minh

AI Engineer

Just Another Dev Guy

Subscribe to Lê Đức Minh's Newsletter

Direct email dispatches when new stories are published. Zero algorithms.

Like
Love
Clap
Fire
Party
Wow

More from Lê Đức Minh

View profile

Dynamic Reasoning Budgets: Halving Inference Costs on Test-Time Compute Models

Dynamic reasoning budgets route simple tasks to a zero‑thought path and reserve capped reasoning for complex queries, cutting token use and latency by half.

5 minSep 16

The Harness is the Moat: Building a Deterministic Agent Runtime with Context Pruning

Learn how a deterministic harness prunes context, uses a ledger and transactional tool calls to keep LLM agents reliable over many turns.

6 minSep 16

What DeepSeek's Open-Source Agent Harness Gets Right

A few weeks ago, my dad and I spent an afternoon at the kitchen table trying to figure out what an "AI agent" actually is.

8 minSep 16

I Tested 3 LLMs on Vietnamese Idioms. They Got It Backwards.

State‑of‑the‑art LLMs, even Vietnamese‑specialized ones, score below 50 % on the VIVID benchmark of 1,636 authentic Vietnamese idioms and fail completely on a hand‑picked set of six complex idioms. Th

6 minSep 5

AI Reads Vietnamese Slang as Angry. 3 Models Don't.

Benchmark reveals Llama-3.1-8B mislabels Vietnamese slang as angry, losing 20 F1 points, while three other LLMs correctly interpret social media comments.

6 minSep 5