Hugging Face Papers ↗ · 2026-11-23
Context-Grounded Skill Internalization for Vision-Language Agents
Media reports Hugging Face Papers Source language: Chinese
CGSI detects and masks unsupported skill references before fine-tuning, cutting context misalignment by 72.5–94.6% on ALFWorld, WebShop and ARC-AGI-1 with Qwen3.5 models.
Full text
Context-Grounded Skill Internalization for Vision-Language Agents
Jinlin Liu Yumeng He Qihan Huang Kevin Qinghong Lin Affiliation: Ant Group The University of Hong Kong Shanghai Jiao Tong University University of Oxford*Project lead. †Corresponding authors. Han Peng
Abstract
Skill internalization offers a way for agents to learn useful behaviors from skills and use them without explicit guidance in context at inference time. A common approach is to generate demonstration trajectories with the skill in context and then fine-tune the same model on its own trajectories with the skill removed. However, this leads to the problem that the model may learn to reference the removed skill, which we named as context misalignment (CoMi). In this work, we first analyze agent behaviors related to CoMi under this common pipeline. Across ALFWorld [33], WebShop [44], and ARC-AGI-1 [8], skill-removed fine-tuning consistently results in CoMi: 12.2–46.0% of test trajectories reference the removed skill. To address this problem, we develop Context-Grounded Skill Internalization (CGSI). CGSI uses a sentence detector to identify unsupported references and then masks or rewrites the selected sentences before fine-tuning. Experimental results demonstrate the effectiveness of CGSI and reveal two key findings. (i) Compared with directly fine-tuning with the skill removed, CGSI reduces CoMi at test time by 72.5–94.6% while preserving task success. (ii) Compared with existing reinforcement learning-based skill-internalization baselines, CGSI achieves comparable performance with substantially less training time. CGSI also significantly reduces processing costs compared with large-scale trajectory auditing and correction.
1 Introduction

Figure 1: Context misalignment. (1) A successful ARC response, sampled with the skill, references guidance that is present. (2) SFT trains on the same response with the skill removed, so the referenced guidance is absent.
AI agents are increasingly used for real-world work, such as resolving software issues and operating graphical interfaces [21, 41, 47, 48]. Such work often requires specialized procedures and domain knowledge that a general-purpose model may lack. Agent products such as Claude Code supply this knowledge through skills, which package instructions, scripts, and resources and are loaded into the agent’s context when a task needs them [49, 43, 23]. Skills are therefore a test-time augmentation, and their benefit lasts as long as the skill stays in the context. Skill internalization removes the test-time dependence on the skill by moving the skill’s guidance into the model weights, so that the agent exhibits the behavior the skill introduced without loading the skill into its context [25, 40].
A common way to internalize a skill is to generate demonstration trajectories with the skill in context using the model itself, and then fine-tune the same model on them with the skill removed. Llama 2-Chat follows this recipe for safety. It generates responses under a safety preprompt and is fine-tuned on its own responses without the preprompt [36]. SELF-ALIGN fine-tunes LLaMA on its own principle-guided responses with the principles removed [35], and agent training applies the same recipe to retrieved hints and reflection skills [18, 9]. This recipe is a supervised fine-tuning (SFT) form of context distillation [2, 34]. It changes the training input but keeps the supervision target, so the model learns to reproduce what it wrote with the skill. However, a target written with the skill can depend on it. Demonstration trajectories can contain statements that reference the skill, and these statements remain training targets after the skill is removed. Figure 1 shows an example from ARC [8]. A skill-guided agent plans to execute and verify its inferred rule with a script, solve.py, and explains, “The solve.py file doesn’t exist. According to the task guidance, I need to create it.” The trajectory carries two things into training, a useful strategy and a reference to the skill that supplied it. Once the skill is removed from the SFT input, training rewards the model for referencing guidance it cannot see. We call this context misalignment (CoMi), in which an output references a source absent from its visible context.
We conduct a comprehensive analysis of this problem. After skill removal, CoMi appears in 18.3–75.4% of successful teacher trajectories across ALFWorld [33], WebShop [44], and ARC-AGI-1 [8]. This behavior can be carried over to the trained models. After fine-tuning on these trajectories with the skill removed, the models exhibit CoMi in 12.2–46.0% of test trajectories.
To solve this, we introduce Context-Grounded Skill Internalization (CGSI). The core of CGSI is a sentence detector that identifies sentences containing unsupported references after skill removal. We then rewrite or mask the loss on these sentences before fine-tuning without the skill.
We evaluate CGSI on ALFWorld [33], WebShop [44], and ARC-AGI-1 [8] with the vision-language models (VLMs) Qwen3.5-4B and Qwen3.5-9B [28]. Under full-parameter SFT, its masking version reduces CoMi by 72.5–94.6% relative to direct fine-tuning while preserving task success. For example, with Qwen3.5-4B on WebShop, CoMi falls from 46.0% to 3.4% without loss of task success. CGSI also substantially reduces the cost of trajectory auditing and correction. On ARC, its rewriting version reduces the API cost of processing 2,281 trajectories from about $1,378 to $165. With Qwen3.5-4B on ALFWorld, CGSI reaches 85.0% success in 1.25 training hours, compared with 81.0% for Skill0 [25] in 19.1 hours.
Our contributions are:
•
To the best of our knowledge, we are the first to define and systematically study context misalignment (CoMi) in skill internalization. We show that CoMi is common in successful demonstration trajectories and can be carried into trained models.
•
To solve this, we propose CGSI to correct training supervision that loses context support after skill removal, using a sentence detector to select sentences for loss masking or rewriting before fine-tuning.
•
Experiments demonstrate the improvement. CGSI reduces CoMi by 72.5–94.6% at a low cost while preserving the task success of the fine-tuned model.

Figure 2: CGSI: detector training and context-aligned SFT. (a) Detector training (top): Step 1 obtains paired sentence labels from VLM audits; Step 2 extracts sentence-level features from a frozen backbone, combining log-probability differences between the two contexts with hidden-state representations; Step 3 fits a logistic classifier to these features and labels. The resulting detector is calibrated and frozen. (b) Context-aligned SFT (bottom): Skill-guided demonstration trajectories are scored by the frozen detector. Selected sentences are loss-masked or rewritten, and the model is trained without the skill.
2 Related Work
Agent training.
By interleaving reasoning with tool calls and environment feedback [45], agents complete multi-step tasks in simulated homes [33], online stores [44], software projects [41], and open-world games [39]. Beyond prompting, these agents are improved by post-training, which learns from demonstrations, human preferences [27], or a teacher’s outputs [13, 1]. For agents, SFT on interaction trajectories improves performance on the trained tasks [4] , while reinforcement learning (RL) methods such as GRPO optimize the policy directly using task-outcome rewards [31].
Agent skills.
Skills package reusable procedures, knowledge, and experience that an agent can draw on across tasks [50, 39]. Since such skills must be provided at test time, recent work attempts to move them into the model weights. SFT-based internalization generates trajectories with the guidance and fine-tunes on them without it [18, 9, 46]; the same idea underlies context distillation [2, 34, 36, 35] and, more broadly, learning with privileged information [38, 24, 15, 5]. Other approaches use RL or self-distillation. Skill0 progressively withdraws skills during RL [25]. DGO optimizes the policy using trajectories collected with guidance from an experience bank [3]. Self-distillation methods give the teacher privileged context, such as skills [40] or reference solutions [51]. Recent work has also begun to address context-dependent traces in training trajectories. Harness-Zero masks reviewer-perspective reasoning by keyword matching [46], and DGO rewrites experience-dependent trajectories [3]. Both treat these traces as a data-cleaning step within their own pipelines. We study CoMi as a distinct problem and measure it in both demonstration trajectories and trained models.
Hallucination and faithfulness.
Hallucination research asks whether generated statements are supported by the source or the available evidence [26, 29], as unsupported statements undermine the reliability of model outputs and the trust users place in them [20, 17]. Faithfulness research asks whether stated reasoning reflects how the model actually reached its answer [19]; chain-of-thought can be unfaithful to the factors that drove an answer [37, 22], misleading users about why a model behaves as it does. An agent with CoMi references guidance absent from its visible context and misstates the basis for its actions. This makes the agent harder to audit, because users and overseers rely on its stated reasoning and referenced sources to verify and monitor its behavior [11, 6]. Moreover, CoMi may hurt instruction following, since a model that recalls rules absent from its context can keep acting on them when its visible instructions ask for something different [30].
3 Context Misalignment under Skill Removal
3.1 Interaction and training context
An agent receives a prompt pp containing the system instructions, tool specification, and task. At turn kk, it produces reasoning and an action as y(k)y^{(k)}; the environment returns observation oko_{k}. Let τ=(o0,y(1),o1,…,y(K),oK)\tau=(o_{0},y^{(1)},o_{1},\ldots,y^{(K)},o_{K}) and let τ<k\tau_{<k} be its history before turn kk, serialized according to the agent’s interaction protocol. A skill ss adds procedural guidance to the prompt. The two contexts differ only in ss:
ck+=(p,s,τ<k),ck−=(p,τ<k).c_{k}^{+}=(p,s,\tau_{<k}),\qquad c_{k}^{-}=(p,\tau_{<k}). (1)
A frozen sampling policy generates y(k)∼πθ0(⋅∣ck+)y^{(k)}\sim\pi_{\theta_{0}}(\cdot\mid c_{k}^{+}), and successful trajectories form the SFT set 𝒟\mathcal{D}. At test time, the agent receives only ck−c_{k}^{-}.
3.2 Context misalignment and paired labels
A statement is context-misaligned when it explicitly references guidance or another source that does not appear, literally or in equivalent form, in its visible context. “I should open the container” is a plan; “According to the provided guide, I should open the container” also references a source, and becomes CoMi when no guide is visible. CoMi concerns references only: a wrong action is not CoMi.
Split reasoning into sentences uk,j=y(k)ℓk,j:rk,ju_{k,j}=y^{(k)}_{\ell_{k,j}:r_{k,j}}, where ℓk,j\ell_{k,j} and rk,jr_{k,j} are the start and end character offsets of sentence jj in turn kk. An auditor 𝒜(u,c)∈{0,1}\mathcal{A}(u;c)\in\{0,1\} marks unsupported references in a sentence under context cc. For the same output and history, the paired label is
bk,j=𝒜(uk,j,ck−)[1−𝒜(uk,j,ck+)].b_{k,j}=\mathcal{A}(u_{k,j};c_{k}^{-})\,[1-\mathcal{A}(u_{k,j};c_{k}^{+})]. (2)
Thus bk,j=1b_{k,j}=1 marks references that are supported with the skill and unsupported after its removal; references already unsupported under ck+c_{k}^{+} are excluded, so the label isolates the effect of removal. We implement 𝒜\mathcal{A} with two independent calls to a frozen VLM auditor, Kimi-K2.7-Code, and resolve disagreements with a third call. For sentences with several references, we check the individual fragments before mapping them to sentences. At deployment, the agent receives no skill; we therefore audit its test outputs only in the skill-free context. Supp. B details the audit and its validation.
3.3 SFT objectives with and without the skill
We consider two SFT settings: SFT (skill kept) retains the skill in the training input, whereas SFT (skill dropped) removes it. Let yt(k)y_{t}^{(k)} be a target token, y<t(k)y_{<t}^{(k)} its within-turn prefix, and T=∑kTkT=\sum_{k}T_{k} the number of model target tokens in a trajectory. Observations enter as context. For context choice cc and token weights ww, write
ℒ(θ;c,w)=−1T∑k=1K∑t=1Tkwk,tlogπθ(yt(k)∣ck,y<t(k)).\mathcal{L}(\theta;c,w)=-\frac{1}{T}\sum_{k=1}^{K}\sum_{t=1}^{T_{k}}w_{k,t}\log\pi_{\theta}(y_{t}^{(k)}\mid c_{k},y_{<t}^{(k)}). (3)
The corresponding objectives are ℒKeep=ℒ(θ,c+,𝟏)\mathcal{L}_{\rm Keep}=\mathcal{L}(\theta;c^{+},\mathbf{1}) and ℒDrop=ℒ(θ,c−,𝟏)\mathcal{L}_{\rm Drop}=\mathcal{L}(\theta;c^{-},\mathbf{1}).
3.4 Misalignment in successful demonstration trajectories
Table 1: CoMi introduced by skill removal in successful teacher trajectories: CoMi (%), with positive / total trajectories in parentheses. A positive trajectory contains at least one reference that loses context support.
Model ALFWorld WebShop ARC-AGI-1
4B 33.97 (412 / 1,213) 64.79 (322 / 497) 43.95 (552 / 1,256)
9B 40.28 (518 / 1,286) 18.34 (104 / 567) 75.45 (1,721 / 2,281)
Table 1 shows that successful demonstration trajectories frequently contain references that lose support after skill removal, from 18.3% on WebShop-9B to 75.4% on ARC-9B. Model size does not predict the rate: the 9B teacher produces fewer such references than 4B on WebShop (18.3% versus 64.8%) but more on ALFWorld and ARC. A natural fix is to ask the teacher not to mention the skill. This makes the problem worse: on 1,000 ALFWorld tasks, removal-induced CoMi rises from 38.9% to 51.9%. Some outputs now reference the prohibition itself: “The system instructions say not to mention the skill or its contents in thinking.” This reference is supported during rollout but loses its source when the skill-related instructions are removed before SFT; prompt-level prevention is analyzed in Supp. F.
4 Context-Grounded Skill Internalization
VLM auditing is expensive: on ARC, scanning a successful demonstration trajectory costs at least 1.13–1.14M tokens on average, and auditing the 2,281 ARC-9B training demonstration trajectories with a VLM costs about $1,200 at list price. CGSI places the audit between skill-guided generation and skill-free SFT and performs it with a detector using two signals: how much a sentence depends on the skill, and what it says. The detector is developed once (Fig. 2(a), Steps 1–3) and then reused frozen in context-aligned SFT (Fig. 2(b)).
4.1 Likelihood differences reveal skill dependence
A sentence that references the skill should be easier to predict when the skill is visible, and harder once it is removed. Using the initial agent model q=πθ0q=\pi_{\theta_{0}}, kept frozen, we compare each target token under the two contexts with an identical output prefix:
Δk,t=logq(yt(k)∣ck+,y<t(k))−logq(yt(k)∣ck−,y<t(k)).\begin{split}\Delta_{k,t}={}&\log q(y_{t}^{(k)}\mid c_{k}^{+},y_{<t}^{(k)})\\ &-\log q(y_{t}^{(k)}\mid c_{k}^{-},y_{<t}^{(k)}).\end{split} (4)
Let Ik,jI_{k,j} be the set of positions tt of the target tokens in turn kk that fall within sentence uk,ju_{k,j}; we summarize the sentence’s overall and local dependence as
gk,jmean\displaystyle g^{\rm mean}_{k,j} =1|Ik,j|∑t∈Ik,jΔk,t,\displaystyle=\frac{1}{|I_{k,j}|}\sum_{t\in I_{k,j}}\Delta_{k,t}, (5)
gk,jpeak4\displaystyle g^{\rm peak4}_{k,j} =maxW∈𝒲k,j1|W|∑t∈WΔk,t,\displaystyle=\max_{W\in\mathcal{W}_{k,j}}\frac{1}{|W|}\sum_{t\in W}\Delta_{k,t},
where 𝒲k,j\mathcal{W}_{k,j} contains consecutive windows of min(4,|Ik,j|)\min(4,|I_{k,j}|) tokens. The peak feature captures a short dependent phrase, such as “according to the skill,” inside a longer sentence.
4.2 Hidden states distinguish references from plans
Skill dependence alone does not identify CoMi, because the skill also makes valid plans more likely. “I should check the container” and “According to the skill, I should check the container” may both have positive gaps, yet only the second references the skill. To capture what a sentence says, we pool last-layer hidden states 𝐡k,t−\mathbf{h}^{-}_{k,t} under the skill-free context:
𝐡¯k,j\displaystyle\bar{\mathbf{h}}_{k,j} =1|Ik,j|∑t∈Ik,j𝐡−k,t,𝐞k,j=𝐡¯k,j‖𝐡¯k,j‖2,\displaystyle=\frac{1}{|I_{k,j}|}\sum_{t\in I_{k,j}}\mathbf{h}^{-}_{k,t},\qquad\mathbf{e}_{k,j}=\frac{\bar{\mathbf{h}}_{k,j}}{\|\bar{\mathbf{h}}_{k,j}\|_{2}}, (6)
𝐳k,j\displaystyle\mathbf{z}_{k,j} =Std([𝐞k,j,gk,jmean,gk,jpeak4]).\displaystyle=\operatorname{Std}\big([\mathbf{e}_{k,j},g^{\rm mean}_{k,j},g^{\rm peak4}_{k,j}]\big).
The hidden state represents what the sentence says, and the gaps how its likelihood depends on the skill.
4.3 Fitting and calibrating a sentence auditor
After splitting development trajectories by task into fitting, calibration, and held-out sets, a logistic model learns from paired labels bb:
fϕ(𝐳)=𝐯⊤𝐳+β,Pϕ(b=1∣𝐳)=σ(fϕ(𝐳)),f_{\phi}(\mathbf{z})=\mathbf{v}^{\top}\mathbf{z}+\beta,\qquad P_{\phi}(b=1\mid\mathbf{z})=\sigma(f_{\phi}(\mathbf{z})), (7)
using class-balanced cross-entropy and ℓ2\ell_{2} regularization:
ℒdet=1|𝒟fit|∑(𝐳,b)∈𝒟fitBCEbal(b,σ(fϕ(𝐳)))+λ2‖𝐯‖22.\mathcal{L}_{\rm det}=\frac{1}{|\mathcal{D}_{\rm fit}|}\sum_{(\mathbf{z},b)\in\mathcal{D}_{\rm fit}}\mathrm{BCE}_{\rm bal}\big(b,\sigma(f_{\phi}(\mathbf{z}))\big)+\frac{\lambda}{2}\|\mathbf{v}\|_{2}^{2}. (8)
A sentence is selected when its score reaches a threshold η\eta, which we set on the calibration split separately for each benchmark and model. We then freeze ϕ\phi and η\eta and predict b^k,j=𝟏{fϕ(𝐳k,j)≥η}\hat{b}_{k,j}=\mathbf{1}\{f_{\phi}(\mathbf{z}_{k,j})\geq\eta\} on new demonstration trajectories. Thresholds are in Supp. D.
4.4 Masking selected supervision
Masking stops training the model to produce the selected sentences: a target token is masked when it lies entirely inside a selected sentence. Let m^k,t∈{0,1}\hat{m}_{k,t}\in\{0,1\} be 1 if target token tt of turn kk is masked and 0 otherwise. CGSI (Mask) sets the token weights in Eq. 3 to wk,t=1−m^k,tw_{k,t}=1-\hat{m}_{k,t}:
ℒMask=ℒ(θ,c−,𝟏−m^).\mathcal{L}_{\rm Mask}=\mathcal{L}(\theta;c^{-},\mathbf{1}-\hat{m}). (9)
Masking changes only which tokens are supervised: the normalizer TT still counts all target tokens, so the remaining tokens keep their loss scale, and the selected text stays in the teacher-forced prefix, so later reasoning and actions are conditioned exactly as before. Removing the supervision entirely matters: a softer variant that only down-weights the selected sentences leaves more CoMi, as shown in Supp. D.
4.5 Rewriting selected text
CGSI (Rewrite) uses a VLM to rewrite each selected fragment so that it holds without the skill. We then train on the rewritten trajectories without the skill. Rewriting keeps supervision on the corrected text but needs VLM calls; Supp. C gives details.
4.6 A generate–audit–correct–train framework
These steps form a four-stage framework (Fig. 2(b)): a frozen sampling policy generates demonstration trajectories with the skill; the detector marks the sentences that lose support under the skill-free training context; the selected sentences are masked or rewritten; and the model is trained on the corrected demonstration trajectories without the skill. In contrast, the VLM Audit baselines VLM Audit (Rewrite) and VLM Audit (Mask) use a full VLM audit to select sentences for rewriting or loss masking, respectively. The full algorithm is in Supp. C.
5 Experiments
Table 2: Capability and context alignment after SFT. Success rate (sr) and deployment CoMi in %; WebShop score in [0,100][0,100]. All methods train on the same skill-guided trajectories. SFT (skill kept) trains with the skill; the others train without it. CGSI variants use sentences selected by our detector; the VLM Audit baselines use sentences flagged by a full VLM audit. No method receives the skill at test time. Silver-gray text: CoMi; muted red: CoMi ≥10%\geq 10\%. Bold black: best skill-free sr and score within each group.
ALFWorld WebShop ARC-AGI-1
Pick (59) Clean (58) Heat (39) Cool (46) Look (31) Pick2 (41) All (274) 500 tasks 400 tasks
Method sr ↑\uparrow CoMi ↓\downarrow sr ↑\uparrow CoMi ↓\downarrow sr ↑\uparrow CoMi ↓\downarrow sr ↑\uparrow CoMi ↓\downarrow sr ↑\uparrow CoMi ↓\downarrow sr ↑\uparrow CoMi ↓\downarrow sr ↑\uparrow CoMi ↓\downarrow sr ↑\uparrow Score↑\uparrow CoMi ↓\downarrow sr ↑\uparrow CoMi ↓\downarrow
Full-parameter ⋅\cdot Qwen3.5-4B
Base 86.4 1.7 22.4 1.7 5.1 2.6 10.9 0.0 38.7 3.2 61.0 0.0 39.4 1.5 6.8 14.0 0.6 2.00 0.00
SFT (skill kept) 89.8 0.0 81.0 6.9 59.0 0.0 54.3 2.2 83.9 0.0 85.4 0.0 76.3 1.8 35.4 46.1 1.4 5.25 0.00
SFT (skill dropped) 93.2 5.1 93.1 25.9 53.8 15.4 80.4 15.2 90.3 16.1 85.4 19.5 83.9 16.1 39.2 51.4 46.0 13.25 15.75
VLM Audit (Rewrite) 83.1 3.4 94.8 1.7 51.3 0.0 78.3 0.0 87.1 0.0 73.2 2.4 79.2 1.5 34.8 44.3 4.6 11.50 1.00
VLM Audit (Mask) 93.2 1.7 91.4 0.0 38.5 2.6 84.8 0.0 93.5 0.0 70.7 2.4 80.3 1.1 38.4 49.5 6.4 11.50 1.00
CGSI (Rewrite) 94.9 1.7 94.8 3.4 61.5 0.0 78.3 0.0 87.1 3.2 87.8 2.4 85.4 1.8 37.4 49.4 13.2 9.75 1.25
CGSI (Mask) 94.9 1.7 94.8 6.9 59.0 5.1 87.0 2.2 83.9 0.0 80.5 9.8 85.0 4.4 41.6 53.7 3.4 16.75 1.25
Full-parameter ⋅\cdot Qwen3.5-9B
Base 79.7 0.0 43.1 0.0 10.3 0.0 8.7 2.2 64.5 0.0 78.0 0.0 48.2 0.4 6.6 18.9 0.0 7.00 0.00
SFT (skill kept) 98.3 1.7 63.8 5.2 43.6 0.0 54.3 4.3 93.5 0.0 95.1 0.0 74.8 2.2 43.0 63.0 0.2 20.00 0.00
SFT (skill dropped) 100.0 25.4 87.9 60.3 38.5 41.0 73.9 19.6 87.1 22.6 100.0 26.8 82.8 33.9 46.8 65.6 12.2 27.50 37.25
VLM Audit (Rewrite) 96.6 5.1 79.3 1.7 41.0 0.0 69.6 0.0 90.3 0.0 95.1 0.0 79.6 1.5 54.8 71.6 1.2 29.50 4.75
VLM Audit (Mask) 96.6 3.4 87.9 8.6 56.4 15.4 73.9 4.3 87.1 3.2 92.7 4.9 83.6 6.6 48.8 65.9 1.6 30.00 7.50
CGSI (Rewrite) 98.3 0.0 86.2 6.9 43.6 7.7 76.1 0.0 96.8 0.0 95.1 0.0 83.6 2.6 49.2 70.8 0.8 29.50 6.00
CGSI (Mask) 98.3 0.0 81.0 6.9 61.5 2.6 76.1 0.0 96.8 0.0 100.0 0.0 85.8 1.8 47.0 67.8 1.0 29.50 10.25
LoRA (rank 16) ⋅\cdot Qwen3.5-4B
SFT (skill kept) 83.1 0.0 39.7 1.7 5.1 0.0 34.8 0.0 67.7 0.0 75.6 0.0 51.8 0.4 11.0 20.7 0.2 2.25 0.00
SFT (skill dropped) 91.5 5.1 86.2 36.2 51.3 17.9 84.8 8.7 83.9 12.9 75.6 14.6 80.3 16.4 36.6 47.1 79.8 13.25 11.50
VLM Audit (Rewrite) 96.6 0.0 87.9 0.0 33.3 2.6 89.1 2.2 83.9 0.0 87.8 2.4 81.8 1.1 39.8 53.1 13.0 13.75 1.25
CGSI (Rewrite) 88.1 0.0 89.7 0.0 33.3 0.0 76.1 0.0 87.1 0.0 73.2 0.0 76.3 0.0 37.4 49.0 16.2 14.00 2.25
CGSI (Mask) 93.2 1.7 91.4 3.4 35.9 0.0 89.1 2.2 90.3 0.0 68.3 0.0 79.9 1.5 38.6 52.2 14.6 12.25 1.50
LoRA (rank 16) ⋅\cdot Qwen3.5-9B
SFT (skill kept) 93.2 0.0 41.4 1.7 28.2 2.6 28.3 0.0 87.1 0.0 85.4 0.0 60.2 0.7 13.4 34.4 0.2 6.25 0.00
SFT (skill dropped) 100.0 18.6 81.0 58.6 43.6 33.3 80.4 21.7 96.8 6.5 97.6 22.0 83.9 28.8 42.2 60.4 14.6 29.25 43.50
VLM Audit (Rewrite) 100.0 3.4 84.5 5.2 41.0 0.0 76.1 0.0 93.5 3.2 92.7 0.0 82.5 2.2 40.2 58.6 1.2 36.00 5.00
CGSI (Rewrite) 98.3 0.0 81.0 3.4 41.0 0.0 80.4 0.0 96.8 0.0 97.6 0.0 83.2 0.7 43.6 59.2 2.0 36.25 6.50
CGSI (Mask) 96.6 1.7 86.2 25.9 33.3 5.1 80.4 0.0 96.8 3.2 90.2 0.0 81.8 6.9 42.4 59.1 1.6 32.50 12.25
5.1 Setup
Environments and data.
ALFWorld [33] covers six types of household tasks, with 274 test tasks; in WebShop [44], the agent searches for and buys a product that matches a shopping instruction, with 500 test tasks; and ARC-AGI-1 [8] requires inferring a grid transformation from a few examples, with 400 evaluation tasks. We run ARC as a multimodal agent task in which the agent sees the grids as an image and can write and run code. The skills provide household procedures, shopping strategies, and grid-transformation guidance, respectively. Each model generates skill-guided demonstration trajectories on 1,920 training tasks for ALFWorld and for WebShop and on 6,360 ARC tasks; for a given model and benchmark, all methods train on the same successful demonstration trajectories. Detectors are developed on separate pools of 673–680 tasks per benchmark. Details are in Supp. H.
Training and evaluation.
We train with full-parameter SFT and rank-16 LoRA [16] for three epochs. Unless otherwise specified, all SFT methods use the same skill-guided demonstration trajectories and are evaluated without the skill. Base is the untrained model. SFT (skill kept) retains the skill in the training input, whereas SFT (skill dropped) removes it. CGSI (Mask) and CGSI (Rewrite) mask or rewrite the sentences selected by our detector; they are the two variants of CGSI. VLM Audit (Rewrite) and VLM Audit (Mask) rewrite or mask the sentences selected by a full VLM audit. We also compare with Skill0, Skill-SD, and OPSD on ALFWorld-4B (Tab. 4). Kimi-K2.7-Code performs auditing and rewriting. Each model is evaluated with one rollout per test task.
Success rate (sr) is the percentage of test tasks completed: a WebShop task counts as successful only if it receives the full score of 100, and an ARC task only if every predicted grid matches exactly. For trained models, CoMi is the percentage of test trajectories with at least one unsupported reference, audited without the skill. Humans agree with 255 of 260 sampled audit positives. To check for misses in long trajectories, GPT-6.1 Sol independently re-audits 1,245 Kimi-negative test trajectories. Humans adjudicate the disagreements and confirm five misses. Training settings and metric definitions are in Supp. E and A.
Compute.
All experiments in this paper run on NVIDIA H800 GPUs (8 per node), using about 5,832 H800 GPU-hours in total; external VLM calls use about 40.44B tokens in total, about $43,421 at official API prices.
5.2 Capability and alignment after SFT
The SFT baselines trade off task success and CoMi.
In Tab. 2, under full-parameter SFT, SFT (skill kept) improves on Base by 27–37 success points on ALFWorld and WebShop. SFT (skill dropped) further improves success by 3.8–8.0 points across all six settings, but raises CoMi from 0–2.2% to 12.2–46.0%. For SFT (skill dropped), CoMi at test time tends to be higher when it is more common in the training demonstrations. The highest test-time rates are on WebShop-4B and ARC-9B (46.0% and 37.25%), which also have the highest rates in the training demonstrations. WebShop-9B has the lowest rate in both. Skill-guided generation also contributes much of the success. On ALFWorld-4B, SFT on 773 successful rollouts sampled without the skill reaches 54.7%, whereas SFT (skill kept) and SFT (skill dropped) trained on as many skill-guided demonstration trajectories reach 71.5% and 82.5%. This skill-free control is detailed in Supp. E.
CGSI reduces CoMi while preserving task success.
Under full-parameter SFT, CGSI (Mask) achieves task success statistically indistinguishable from that of SFT (skill dropped) in all six settings, while reducing CoMi by 72.5–94.6%, for example 3.4% instead of 46.0% on WebShop-4B. The highest remaining CoMi rate is 10.25% on ARC-9B, where detector recall is lowest. Masking the sentences selected by the full VLM audit yields a CoMi rate of 7.50% in this setting. On the 4B demonstration trajectories, CGSI (Mask) zeroes the loss on only 0.08–1.21% of target tokens, yet substantially reduces CoMi at test time. Masking randomly chosen reasoning sentences that cover a similar share of target tokens (1.07% on WebShop-4B) leaves CoMi at 49.4% . Therefore, the reduction in CoMi comes from targeting sentences containing CoMi, not from training on fewer tokens. Rewriting also lowers CoMi, with success close to that of SFT (skill dropped). Supp. D and I give the random control and examples.
CGSI achieves similar results at lower API cost.
Under full-parameter SFT, CGSI (Mask) achieves comparable task success to VLM Audit (Mask), with no significant decrease in any setting . Neither method consistently yields lower CoMi. For rewriting, CGSI (Rewrite) also achieves task success close to VLM Audit (Rewrite), with similar CoMi in most settings. On ARC-9B, both reach 29.50% success, with 6.00% and 4.75% CoMi, respectively. Both CGSI variants avoid the full VLM scan. After detector development, CGSI (Mask) makes no API calls, and CGSI (Rewrite) uses the VLM only for rewriting, reducing API token usage by 91.0–96.1% across the three 9B settings (Sec. 5.5).
5.3 Full-parameter versus LoRA adaptation
Restricting the update widens the gap between the two SFT baselines. Under LoRA, SFT (skill dropped) exceeds SFT (skill kept) by 11.0–28.8 success points, compared with 3.8–8.0 under full-parameter SFT. The larger success gap mainly reflects weaker results when the skill is retained during training: SFT (skill dropped)with LoRA stays within 4.6 points of its full-parameter result, whereas SFT (skill kept)with LoRA gains little over Base on WebShop-4B and ARC, between −0.75-0.75 and +4.2+4.2 points. This may be because LoRA limits generalization, so models trained with the skill transfer poorly to skill-free test inputs. Under LoRA, CGSI (Mask) exceeds SFT (skill kept) by 10.0–29.0 success points and reduces CoMi by 72–91% relative to SFT (skill dropped).
Table 3: Sentence-level detection quality on successful SFT demonstration trajectories, measured against VLM audit labels (%). Word: F1 of word matching on the same sentences.
4B 9B
Env. P↑\uparrow R↑\uparrow F1↑\uparrow Word↑\uparrow P↑\uparrow R↑\uparrow F1↑\uparrow Word↑\uparrow
ALFWorld 81.20 82.90 82.04 49.82 81.21 95.74 87.88 65.60
WebShop 78.95 93.75 85.71 5.64 85.81 93.01 89.26 5.42
ARC-AGI-1 53.80 76.73 63.25 53.27 81.66 70.02 75.39 59.88
Table 4: Skill internalization on ALFWorld with Qwen3.5-4B. Success rate (sr) and CoMi over all 274 tasks (%). Time: training hours, including SFT for the last two rows and excluding data processing. Details are in Supp. E and G.
Method sr ↑\uparrow CoMi ↓\downarrow Time ↓\downarrow
Inference baselines
Base 39.42 1.46 –
Base + skill 67.52 – –
Online training
GRPO [31] 91.97 0.00 5.65
Skill-SD [40] 88.32 0.00 9.26
OPSD [51] 0.00 – 3.46
Skill0 [25] 81.02 2.92 19.14
Offline SFT
SFT (skill dropped) 83.94 16.06 1.26
CGSI (Mask) 85.04 4.38 1.25
CGSI (Rewrite) 85.40 1.82 1.25
SFT followed by RL
CGSI (Mask) + GRPO 96.35 1.82 5.93
CGSI (Rewrite) + GRPO 95.62 0.36 6.03
5.4 Sentence-level detection quality
Table 3 compares the detectors with VLM audit labels on the demonstration trajectories they correct: they detect most removal-induced CoMi on ALFWorld and WebShop (recall 82.9–95.7%) at 78.9–85.8% precision. Word matching has lower F1 than the detector in all six settings, by 10.0–83.8 points, because whether guide or instruction marks an unsupported reference depends on context. Our feature ablations on 4B find that hidden states are the most important feature, and hidden states alone can sometimes reach precision and recall comparable to the full detector’s, as on WebShop. However, masking the sentences selected by a hidden-only detector is less successful than CGSI (Mask) in all three 4B environments, significantly on ARC (10.00% versus 16.75%). The feature ablations are Supp. D.
Figure 3: CoMi before and after RL. Open and filled circles indicate before and after RL. In each panel, rows from top to bottom are SFT (skill dropped), VLM Audit (Rewrite), CGSI (Rewrite), and CGSI (Mask).
5.5 Data-processing cost
We use Qwen3.5-9B results as examples. Table 5 reports the API tokens per successful demonstration trajectory across the three benchmarks. The detector reduces the cost of locating CoMi by replacing a full VLM scan with local feature extraction and classification. CGSI (Rewrite) then uses the VLM only for the rewriting stage, whereas CGSI (Mask) also avoids rewriting. On ALFWorld and WebShop, CGSI (Rewrite) uses 94.6% and 96.1% fewer API tokens than VLM Audit (Rewrite), respectively. For all 2,281 ARC demonstration trajectories, the recorded API usage corresponds to $1,378 for VLM Audit (Rewrite), $165 for CGSI (Rewrite), and zero for CGSI (Mask), excluding detector development. The one-time VLM labeling cost for the 680-task ARC detector-development set is $464. Including this cost, CGSI (Mask) still has a lower API budget than VLM Audit (Rewrite). The frozen detector can be reused on further demonstration trajectories. Supp. G reports local compute and detailed token accounting.
Table 5: Data-processing cost for Qwen3.5-9B: recorded external API tokens (thousands) per successful demonstration trajectory. Detector-development costs are excluded.
VLM Audit CGSI
Benchmark Rewrite Mask Rewrite Mask
ALFWorld 182.6 174.1 9.9 0
WebShop 160.4 153.8 6.3 0
ARC-AGI-1 1,245.5 1,134.7 112.3 0
5.6 Efficient skill internalization with SFT
Table 4 compares our SFT approach with methods that internalize skills online. OPSD [51] performs on-policy self-distillation, in which the model samples trajectories without the skill and the same model, given the skill, provides token-level targets on them. Prior work reports that such self-distillation can be unstable or degrade during training [40, 42], and in our run OPSD collapses to zero success. We therefore also compare with Skill-SD [40], which stabilizes this distillation by adding a GRPO task-reward objective. Skill0 [25] trains with GRPO while a curriculum gradually removes the skills from the agent’s context.
SFT alone is efficient: CGSI (Mask) and CGSI (Rewrite) reach 85.04% and 85.40% success, above Base with skills (67.52%) and Skill0 (81.02%), in about 1.25 hours of training. Skill-SD reaches 88.32%, 3.3 points above CGSI (Mask), but takes 9.26 hours, about seven times longer. This SFT stage also gives RL a stronger starting point: after 60 skill-free GRPO updates, CGSI (Mask) and CGSI (Rewrite) reach 96.35% and 95.62% success, 4.38 and 3.65 points above GRPO from Base, with final CoMi of 1.82% and 0.36%. SFT followed by RL thus reaches the highest success here, with less training time than Skill-SD and Skill0.
5.7 Does subsequent RL remove CoMi?
If task-reward RL removed CoMi by itself, correcting the SFT data would be unnecessary. We test this by running 60 skill-free GRPO updates [31] from the SFT (skill dropped), CGSI (Mask), CGSI (Rewrite), and VLM Audit (Rewrite) policies. GRPO improves success from every starting policy, as shown by the training curves in Supp. E. However, Fig. 3 shows that CoMi does not decrease in the same way. For SFT (skill dropped), the CoMi rate after RL remains at 69–86% of its pre-RL rate, with final values of 8.4–35.2%. Models trained with corrected SFT supervision finish at 0.4–5.2%, with small increases or decreases during RL. A task reward indicates success, not whether the referenced source exists, so CoMi after RL is largely set during SFT.
5.8 Case studies
Figure 4 shows two examples of reducing CoMi without sacrificing task performance. In ALFWorld, given identical initial inputs, the SFT (skill dropped) model references absent “skills” to justify searching a desk or sidetable. CGSI (Mask) and CGSI (Rewrite) make the same search decision without referencing the missing skill. In ARC, after creating rule.py to describe the inferred rule, all three models proceed to create solve.py to test it. The SFT (skill dropped) model refers to “the guidance” when creating the file, although no such guidance is present in its context. CGSI (Mask) and CGSI (Rewrite) also create solve.py without making this unsupported reference. Additional CoMi examples are provided in Supp. I.

Figure 4: Case studies. Selected cases from Qwen3.5-9B models after full-parameter SFT. (a) ALFWorld (top): The models’ first-turn behavior. (b) ARC (bottom): All three models created rule.py to describe the inferred rule and then proceeded to create solve.py to test it. Red marks unsupported references; bold highlights task-relevant content. All three runs succeed in each case.
6 Discussion and Conclusion
In this work, we study context misalignment (CoMi) in skill internalization. We show that CoMi is common in successful demonstration trajectories and can be carried into trained models. To address this problem, we propose CGSI, which uses a sentence detector to guide rewriting or loss masking. Our experiments show that CGSI can substantially reduce CoMi while preserving task success. These findings highlight the importance of aligning training supervision with the model’s visible context when internalizing skills.
LLM Usage Statement
We study Qwen3.5-4B and Qwen3.5-9B as the models underlying the agents described in the paper. Kimi-K2.7-Code is used for training-data annotation, paired context auditing, trajectory rewriting, coherence checks, and deployment CoMi evaluation. GPT-6.1 Sol independently re-audits negative deployment trajectories. OpenAI Codex assists with manuscript drafting and code preparation.
Acknowledgments
This work was supported by Ant Group Research Intern Program.
References
[1] R. Agarwal, N. Vieillard, Y. Zhou, P. Stanczyk, S. Ramos, M. Geist, and O. Bachem (2024) On-policy distillation of language models: learning from self-generated mistakes. In International Conference on Learning Representations (ICLR), Cited by: §2.
[2] A. Askell, Y. Bai, A. Chen, D. Drain, D. Ganguli, T. Henighan, A. Jones, N. Joseph, B. Mann, N. DasSarma, et al. (2021) A general language assistant as a laboratory for alignment. arXiv preprint arXiv:2112.00861. Cited by: §1, §2.
[3] F. Bai, Z. Chen, C. Hao, M. Yang, R. Tao, B. Dai, W. X. Zhao, J. Yang, et al. (2026) Towards effective experiential learning: dual guidance for utilization and internalization. arXiv preprint arXiv:2603.24093. Cited by: §2.
[4] B. Chen, C. Shu, E. Shareghi, N. Collier, K. Narasimhan, and S. Yao (2023) FireAct: toward language agent fine-tuning. arXiv preprint arXiv:2310.05915. Cited by: §2.
[5] D. Chen, B. Zhou, V. Koltun, and P. Krähenbühl (2020) Learning by cheating. In Proceedings of the Conference on Robot Learning (CoRL), Proceedings of Machine Learning Research, Vol. 100, pp. 66–75. Cited by: §2.
[6] Y. Chen, J. Benton, A. Radhakrishnan, J. Uesato, C. Denison, J. Schulman, A. Somani, P. Hase, M. Wagner, F. Roger, V. Mikulik, S. R. Bowman, J. Leike, J. Kaplan, and E. Perez (2025) Reasoning models don’t always say what they think. arXiv preprint arXiv:2505.05410. Cited by: §2.
[7] F. Chollet, M. Knoop, G. Kamradt, and B. Landers (2024) ARC prize 2024: technical report. arXiv preprint arXiv:2412.04604. Cited by: Appendix E.
[8] F. Chollet (2019) On the measure of intelligence. arXiv preprint arXiv:1911.01547. Cited by: §H.3, §1, §1, §1, §5.1, Abstract.
[9] G. Dong, X. Yang, J. Jin, Y. Hu, X. Song, Y. Chen, X. Li, J. Tan, et al. (2026) Agent-Reflex: teaching language agents to act reflectively. arXiv preprint arXiv:2610.17953. Cited by: §1, §2.
[10] L. Feng, Z. Xue, T. Liu, and B. An (2025) Group-in-group policy optimization for LLM agent training. In Advances in Neural Information Processing Systems, External Links: Link Cited by: §H.1.
[11] T. Gao, H. Yen, J. Yu, and D. Chen (2023) Enabling large language models to generate text with citations. In Proceedings of the Conference on Empirical Methods in Natural Language Processing (EMNLP), pp. 6465–6488. Cited by: §2.
[12] Harbor Framework Team (2026) Harbor: a framework for evaluating and optimizing agents and models in container environments. Note: https://doi.org/10.5281/zenodo.20953922 Cited by: Appendix E, §H.3.
[13] G. Hinton, O. Vinyals, and J. Dean (2015) Distilling the knowledge in a neural network. arXiv preprint arXiv:1503.02531. Cited by: §2.
[14] M. Hodel (2024) Addressing the abstraction and reasoning corpus via procedural example generation. arXiv preprint arXiv:2404.07353. Cited by: §H.3.
[15] J. Hoffman, S. Gupta, and T. Darrell (2016) Learning with side information through modality hallucination. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (C
Images from the source



