Large language model agents rely on effective model context to obtain task-relevant information for decision-making. Many existing context engineering approaches primarily rely on the context generated from the past experience and retrieval mechanisms that reuse these context. However, retrieved context from past tasks must be adapted by the execution agent to fit new situations, placing additional reasoning burden on the underlying LLM. To address this limitation, we propose a generative context augmentation framework using Contrastive Learning of Experience via Agentic Reflection (CLEAR). CLEAR first employs a reflection agent to perform contrastive analysis over past execution trajectories and summarize useful context for each observed task. These summaries are then used as supervised fine-tuning data to train a context augmentation model (CAM). Then we further optimize CAM using reinforcement learning, where the reward signal is obtained by running the task execution agent. By learning to generate task-specific knowledge rather than retrieve knowledge from the past, CAM produces context that is better tailored to the current task. We conduct comprehensive evaluations on the AppWorld and WebShop benchmarks. Experimental results show that CLEAR consistently outperforms strong baselines. It improves task completion rate from 72.62% to 81.15% on AppWorld test set and averaged reward from 0.68 to 0.74 on a subset of WebShop, compared with baseline agent. Our code is publicly available at https://github.com/awslabs/CLEAR.
Figures & tables
Figure 1: CLEAR training framework design. First, we execute each task qi∼Dtrain for m times and collect groups of replay Γi for qi . We employ reflection agents πR to generate instance-level instruction ci for each qi , collected into DSFT . Then, we initialize CAM from an open-source LLM and perform SFT on DSFT . Finally, we further perform RL on the trained CAM, which leverages the reward signal from πE for policy update of CAM.
Figure 2: During inference, a new task qnew is sampled from Dtest and is passed into πθC to generate cnew∼πθC(qnew) . The auxiliary context cnew is appended to qnew and the execution agent πE starts with qnew⊕cnew .
Method
TGC ↑
SGC ↑
Avg
Pass@3
Avg
Pass@3
Baseline
72.62(2.59)
86.90
52.38(2.73)
66.07
RAG
72.02(2.15)
86.31
54.67(3.72)
71.43
ACE Zhang et al. (2025)
74.40(3.57)
85.71
58.93(6.19)
73.21
GEPA Agrawal et al. (2025)
75.99(0.74)
89.88
57.14(3.86)
78.57
MIPRO Opsahl-Ong et al. (2024)
74.40(1.46)
88.10
55.36(1.46)
80.36
Table 1: AppWorld experiments results. Task Goal Completion (TGC) and Scenario Goal Completion (SGC) on the Test-N split are reported. Results are averaged over three runs (standard deviation in parentheses) except the Pass@3 metric.
Method
Avg. Reward
Std.
Baseline
0.6799
0.0119
RAG
0.7252
0.0076
CLEAR (ours)
0.7406
0.0044
Table 2: WebShop-40k experiments results. Averaged reward on the test dataset is reported. Results are averaged over three runs with standard deviation also reported.
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
Experiment ID
Method
TGC ↑
SGC ↑
Avg
Pass@3
Avg
Pass@3
1
Qwen/Qwen3-32B
67.40(2.95)
83.33
48.81(4.49)
66.07
2
SFT without CL
68.65 (2.68)
88.69
42.86 (4.72)
67.86
3
SFT with CL
74.21(1.72)
90.48
50.60(2.73)
71.43
4
CLEAR
81.15 (2.48)
91.67
66.67 (4.49)
82.14
Appendix
Table 3: Ablation study on AppWorld Test-N split. For the CAM, we use the following variant: (1) a Qwen/Qwen3-32B model without SFT and RL as in experiment 1. (2) a Qwen3-32B model after SFT on DSFT_no_CL (no RL) as in experiment 2. (3) a Qwen3-32B model after SFT with CL (no RL) as in experiment 3. (4) full CLEAR framework as in experiment 4. Results are averaged over three runs (standard deviation in parentheses) except the Pass@3 metric.
Method
Run time (s)
# of turns
CAM throughput (tokens/s)
CAM latency (s)
Baseline
63.4
17.3
NA
NA
CLEAR (ours)
77.2
18.5
69.5
1.21
Appendix
Table 4: CAM Latency study. Task run time, number of turns of the execution agent πE , throughput of CAM, and latency for invoking CAM. All numbers are averaged over AppWorld Test-N split. The model for πE is Claude-Sonnet-4 .
Model for πE
Method
TGC ↑
SGC ↑
Avg
Pass@3
Avg
Pass@3
DeepSeek-V3.1
Baseline
41.27(3.05)
64.29
19.05(2.06)
26.79
RAG
33.33(1.57)
53.57
10.71(4.72)
21.43
ACE
32.54(1.50)
53.57
13.69(1.03)
28.57
CLEAR (ours)
42.95 (2.85)
66.07
24.40 (4.49)
33.93
Appendix
Table 5: AppWorld experiments results. Task Goal Completion (TGC) and Scenario Goal Completion (SGC) on the Test-N split are reported. Results are averaged over three runs (standard deviation in parentheses) except the Pass@3 metric.