Architecture
~8 min readUpdated: December 2026

VeilGRPO: Observation-Masked RL for Multi-Turn AI Agents

VeilGRPO observation-masked GRPO training for multi-turn agents in Smoke Monkey

VeilGRPO (arXiv:2612.05497) prevents multi-turn LLM agents from collapsing when historical tool observations are truncated, omitted, or compressed at inference time. By sampling full-context rollouts and masking historical observations plus filtering the immediately following response during GRPO updates, VeilGRPO boosts latest-observation WebShop success from 4.60% to 43.87%.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

VeilGRPO: Observation-Masked RL for Multi-Turn AI Agents: VeilGRPO (arXiv:2612.05497) prevents multi-turn LLM agents from collapsing when historical tool observations are truncated, omitted, or compressed at inference time. By sampling full-context rollouts and masking historical observations plus filtering the immediately following response during GRPO updates, VeilGRPO boosts latest-observation WebShop success from 4.60% to 43.87%. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways
Quick Implementation Exampleveilgrpo-context-resilient-agent.ts
veilgrpo-context-resilient-agent.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Multi-turn agent configured with sliding-window tool-observation pruning
const agent = createAgent({
agentId: 'veilgrpo-resilient-runner',
provider: 'openai-compatible',
baseUrl: 'http://127.0.0.1:8000/v1',
model: 'veilgrpo/qwen3-8b-c10-agent',
workspacePath: process.cwd(),
maxHistoryToolOutputs: 2, // Aggressive observation truncation safe under VeilGRPO
permissions: {
read_file: 'allow',
write_file: 'ask',
run_command: 'ask',
},
});
async function main() {
const result = await agent.run(
'Search repository logs for failing test fixtures, re-verify missing historical outputs if pruned, and emit a clean patch.'
);
console.log('VeilGRPO Execution:', result.summary);
}
main().catch(console.error);
Video Guides

Watch: Related Video Guides

GRPO Explained: How DeepSeek Trains AI Without a Critic

Unsloth RL Training. Nvidia NeMO RL using GRPO. Reinforcement Learning from Verifiable Rewards RLVR

What Is VeilGRPO and Why Does Next-Response Filtering Matter?

VeilGRPO (arXiv:2612.05497) is an observation-masked Group Relative Policy Optimization algorithm designed for multi-turn agents whose production context windows prune, summarize, or drop older tool outputs. Without changing environment rollouts, VeilGRPO trains on randomly masked observation histories while excluding the immediately following response from the loss.

Crucially, naive observation masking alone (M10) fails catastrophically on structured reasoning environments such as ScienceWorld because forcing the policy to predict the exact original next action after hiding its prerequisite observation teaches blind guesswork. Adding next-response filtering (C10) reverses that collapse—exceeding masking-only M10 by 41.66 to 42.33 percentage points on ScienceWorld while inducing active re-retrieval behavior when older tool state disappears.

Environment (Latest Observation Retained)Full-Obs GRPO (A)Masking Alone (M10)VeilGRPO (C10: Mask + Filter)Key Behavioral Shift
WebShop (3-Seed Mean, T1)4.60%38.40%43.87% (+39.27 pp)Eliminates turn-limit loops (94.68% -> 0%)
ALFWorld (Latest Step, S1)16.42%—63.43% (+47.01 pp)Active re-observation after pruned steps
ScienceWorld (8 Degraded Conds)BaselineBelow Baseline A+41.66–42.33 pp vs M10Prevents blind next-token mimicry

Implementing VeilGRPO Observation Masking and Loss Filtering in RL Trainers

During advantage computation, VeilGRPO keeps the full-context trajectory rewards intact so credit assignment remains accurate. Only during the token-level PPO/GRPO policy loss pass does the trainer replace sampled historical <tool_response> spans with a masked observation token and zero out the loss mask on the assistant turn immediately following each masked span:

python
import torch

def build_veilgrpo_loss_mask(
    turn_roles: list[str],
    obs_indices: list[int],
    mask_prob: float = 0.10,
) -> tuple[set[int], set[int]]:
    # Sample masked observation turns and drop immediately following assistant turn from loss
    masked_obs = {idx for idx in obs_indices if torch.rand(1).item() < mask_prob}
    filtered_resp = {idx + 1 for idx in masked_obs if idx + 1 < len(turn_roles)}
    return masked_obs, filtered_resp

roles = ["user", "assistant", "tool", "assistant", "tool", "assistant"]
print("Mask & Filter turns:", build_veilgrpo_loss_mask(roles, [2, 4], mask_prob=0.5))

Never Use Observation Masking Without Next-Response Filtering

In ablations across ScienceWorld, M10 (masking without filtering the subsequent turn) scored worse than standard full-observation GRPO across all eight evaluation conditions.

Google Search Questions & Answers

Frequently Asked Questions

Q:Does VeilGRPO increase environment rollout or simulator cost?

No. Trajectories are sampled once under full context; observation masking and next-response filtering occur purely during the offline GRPO policy update stage.

Q:Why does VeilGRPO filter the response immediately following a masked observation?

Because that action was originally conditioned on the now-hidden tool output; training the model to reproduce it without the observation causes blind hallucination, whereas filtering it preserves clean downstream recovery gradients.

Q:How much does VeilGRPO improve degraded-context agent success?

When retaining only the latest tool observation, 3-seed WebShop success jumps from 4.60% to 43.87% and ALFWorld success jumps from 16.42% to 63.43%.

Q:Does VeilGRPO generalize to context management techniques unseen during training?

Yes. Policies trained with stochastic masking and next-response filtering transfer directly to unseen summary compression and dropped-feedback perturbations.

Related Alternatives & Comparisons

Related Architecture Guides

View all guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness