arXiv(opens in a new tab)cs.ROSep 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2609.06852

ContextFlow: In-Context Flow Matching for Robot Manipulation

Jian Ding, Xianjie Dai, Roei Herzig, Nussair Hroub, Jinjie Mai, Dengxin Dai, Bernard Ghanem, Mohamed Elhoseiny

Jian Ding^{1}$$^{*}, Xianjie Dai^{1}$$^{*}, Roei Herzig^{2}$$^{*}, Nussair Hroub^{1}$$^{*}, Jinjie Mai^{1}$$^{*}, Dengxin Dai^{3}$$^{*}, Bernard Ghanem^{1}$$^{*}, and Mohamed Elhoseiny^{1}$$^{\dagger}

1^{1} KAUST, Thuwal, Saudi Arabia; {jian.ding, dai.xianjie, nussair.hroub, jinjie.mai, bernard.ghanem, mohamed.elhoseiny}@kaust.edu.sa

2^{2} University of California, Berkeley, USA; roeiherz@gmail.com

3^{3} Zurich, Switzerland; ddx2004@gmail.com

Abstract. Although highly effective in vision and language domains, applying in-context learning to robotics remains challenging. Existing autoregressive in-context imitation methods discretize continuous actions and exacerbate the accumulation of early prediction errors through next-token prediction, limiting their generalization on unseen task configurations. Meanwhile, flow-matching policies have been explored for continuous robot control and can help mitigate compounding errors; however, in-context imitation learning within a flow-matching framework remains underexplored. To address these limitations, we introduce ContextFlow, a conditional flow-matching model that learns continuous action distributions for in-context imitation learning. ContextFlow conditions flow-based action prediction on demonstrations and observations, enabling robust generation from noisy action distributions. To better encode multimodal in-context demonstrations, we adapt perceiver-style multimodal context compressors that distill visual, proprioceptive, and action sequences into compact, task-relevant latent representations. On LIBERO, ContextFlow outperforms ICRT by 35 percentage points in average success rate on unseen task configurations, while matching the performance of the task-specific fine-tuned VLA model π0\pi_0 without any fine-tuning on unseen tasks. On real robots, it generalizes to unseen configurations of both single-arm and bimanual tasks, achieving 40% success on a new pen-uncapping configuration. Project Page: https://dingjiansv101.github.io/contextflow-page/.

Keywords: Robot Manipulation · In-Context Learning · Flow Matching

1 Introduction

A hallmark of human intelligence is the ability to solve a new task after observing only a few demonstrations. In machine learning, this capability is often referred to as in-context learning: a model is conditioned at test time on a small set

∗^{*} Equal contribution.

†^{\dagger} Corresponding author.

J. Ding, X. Dai et al.

Figure

(a)

(b)

(c)

(d)

Fig. 1: Autoregressive (a) vs. Flow Matching (b) for In-Context Imitation Learning on action decoding and compounding errors. In-context imitation learning refers to performing a task conditioned on in-context demonstrations without updating model parameters. (a) In-context autoregressive models generate discretized actions step by step, which leads to compounding errors, especially under task distribution shift. (b) Our proposed in-context flow matching framework instead predicts a chunk of continuous actions, alleviating error accumulation and improving generalization. (c) Comparison of compounding errors under seen task configuration between autoregressive and flow-matching approaches. (d) Comparison of compounding errors under unseen task configuration.

of input-output examples and adapts to a new task without gradient updates. In-context learning has been prominently demonstrated in NLP: Large language models (LLMs) such as GPT-3 [7], trained with autoregressive objectives on massive text corpora, exhibit in-context learning as an emergent behavior [26,39].

Similar paradigms have been explored in robotics as in-context imitation learning, where demonstrations are represented as sequences of observations and expert actions. This promises to adapt a policy to a new task from only a few demonstrations, avoiding fine-tuning that existing imitation learning methods [27, 30, 31] require. Yet generalization in robotic manipulation is hard, as policies must produce continuous actions over long horizons from few demonstrations. Consequently, prior in-context imitation work [11, 32], like ours, targets unseen configurations within related primitives (e.g., unseen objects or spatial arrangements) rather than arbitrary new tasks. Many existing in-context imitation learning approaches [11, 32, 38] instantiate the policy as an autoregressive model (ARM) [7, 36], a well-studied and scalable structure that can be directly adapted from LLMs. However, ARM-based policies (Fig. 1 (a)) face two fundamental limitations in robotic control. First, they predict actions sequentially, with each future token conditioned on previously predicted ones; as a result, an early prediction error can propagate and compound over time. Although this issue can be partially mitigated when training and evaluation are drawn from the same task configurations (see Fig. 1 (c)), it becomes much more pronounced in in-context imitation learning, where training and evaluation are drawn from different task configurations (see Fig. 1 (d)). Under such a distribution shift, early errors occur more frequently and are amplified throughout the autoregressive rollout. Second, many ARM-based policies rely on action tokenizers [28, 38] that discretize continuous actions, introducing reconstruction error [28,38] and further exacerbating execution failures.

In the broader imitation learning literature, action chunking [17,45] or continuous action modeling, such as flow matching [4, 21, 22, 24], has been explored to alleviate reconstruction and compounding errors. Flow matching (see Fig. 1 (b)) operates directly in continuous action space and predicts an action chunk in parallel rather than token by token, which helps mitigate compounding errors, especially under distribution shift. However, unlike autoregressive in-context learning, whose architecture and training recipe are well-established in LLMs, the incorporation of in-context learning into a flow-matching framework remains underexplored. In this paper, we build on the architectural principles of a vision-language-action flow model, π0\pi_0 [4], and extend it to support multimodal in-context imitation learning. Concretely, we begin by building ContextFlow-Plain, which uses a context expert to encode the in-context demonstrations, along with the current observation, into a set of context tokens. An action expert then takes the current proprioceptive state and noisy action tokens, and refines them through a sequence of flow-matching updates while attending to the context tokens, ultimately predicting a clean continuous action chunk. By generating continuous action vectors in parallel and avoiding action discretization, ContextFlow-Plain mitigates the compounding errors that are especially harmful under unseen task configurations.

Although ContextFlow-Plain has already equipped a flow-matching framework with in-context learning ability, its performance is further constrained by the cost of encoding long, multimodal in-context demonstrations with a large vision-language-action encoder. Robot trajectories often span hundreds of timesteps and include camera observations, proprioception, and actions, all of which exhibit substantial spatial and temporal redundancy; processing these raw sequences directly with attention is prohibitively expensive. To address this efficiency bottleneck, we propose ContextFlow, which augments ContextFlow-Plain with multimodal context compressors adapted from perceiver-style architectures [14,15,19]. We tailor this structure to in-context demonstration encoding by distilling visual, proprioceptive, and action streams into a compact, fixed-size set of latent context tokens, preserving task-relevant information while substantially reducing the cost of context encoding and cross-attention.

We demonstrate the effectiveness of ContextFlow on the LIBERO simulation. To further evaluate ContextFlow on diverse and challenging real-world robot tasks, we collect a new dataset of expert demonstrations on the ALOHA platform. The dataset contains 1,318 multimodal trajectories across 25 task configurations, spanning both single-arm skills and challenging bimanual tasks that require high-frequency control and closed-loop feedback. Our contributions are three-fold:

– We formulate in-context imitation learning for robotics within a conditional flow matching framework, and empirically observe lower errors on unseen configurations.

J. Ding, X. Dai et al.

– We curate a real-world ALOHA dataset for in-context imitation learning, featuring both single-arm tasks and fine-grained bimanual manipulation tasks.

– We evaluate ContextFlow both in LIBERO simulation and on ALOHA real robots. Across these settings, ContextFlow outperforms autoregressive in-context imitation learning baselines in our evaluations, while matching the performance of task-specific, fine-tuned large vision-language-action models without requiring any fine-tuning on unseen configurations.

References (45)