Agentic In-Context Learning: What Algorithms Can Transformers Learn in Closed-Loop Interaction?
Organizations: Tsinghua University · Beijing Institute of Mathematical Sciences and Applications
Abstract
The learning algorithm view of in-context learning (ICL) studies how fixed-parameter Transformers learn from supplied examples. Language model agents extend this setting through interaction: their actions determine what evidence enters context next. We call this regime Agentic In-Context Learning (Agentic ICL). Existing studies largely depend on externally supplied contexts or reward-bearing interaction histories, while work on general tool-using agents lacks a learning algorithm view. We represent an interactive learner by its state, update, and decision rule, covering active learning, bandits, and online reinforcement learning (RL). For expressivity, we construct causal Transformers that approximate these algorithms over a finite horizon, and bound the resulting loss in return. For training, we characterize when optimizing process rewards preserves behavior that maximizes the final outcome. Distillation experiments show that Transformers can learn to execute three representative recursions. We then train models from outcome or process rewards without oracle action or state targets, as in RL post-training. Different rewards yield distinct decision policies. Improving the alignment of process supervision with outcome-optimal action preferences shifts learned decisions accordingly. Such behavioral differences persist in a pretrained language model across textual paraphrases.
Figures & tables
| Setting | State | Update | Decision / examples |
|---|---|---|---|
| Active learning | Labeled set, query pool, posterior | Add queried label, update posterior | BALD, value-of-information query selection |
| Bandits | Posterior or reward statistics | Posterior or statistical update | Thompson sampling, UCB |
| Online RL | Values, policy parameters, or learned model | TD, policy-gradient, or model update | Q-learning, SARSA, actor-critic, learned-model planning |
Appendix figures & tables24 assets
Supplementary material from the paper’s appendix.
Appendix
| Algorithmic instance | Returned record | Action | Environment kernel | Information state |
|---|---|---|---|---|
| Setting: sequential information acquisition | ||||
| Pool-based active learning (BALD) | , | , with the queried copied into the record | : labeled set, unlabeled pool, posterior | |
| Bayesian sequential design (VOI/KG) | query or experiment | , | ||
| Setting: bandits | ||||
| Thompson sampling | reward | arm | posterior over arm-reward models | |
| UCB | reward | arm | , with counts and reward sums in | |
| Split | Cost law | Purpose | ||
|---|---|---|---|---|
| Training | short-horizon training | |||
| In-distribution test | same | same | short-horizon reference | |
| Nominal-horizon control | same | no calls beyond four | ||
| Feasible-long test | / | / | same | longer calls feasible |
| Policy | Mean | Median | 90th pct. | Gap to Bayes | ||
|---|---|---|---|---|---|---|
| Hard Bayes oracle | 2.88 | 3 | 4 | 8.0% | 2.0% | 0 |
| Outcome reward, 6L/256W | 2.73 | 3 | 4 | 5.0% | 1.0% | 0.019 |
| Policy | Mean | Median | 90th pct. | Gap to Bayes | ||
|---|---|---|---|---|---|---|
| Hard Bayes oracle | 3.011 | 3 | 5 | 10.3% | 0.2% | 0 |
| Outcome reward, 6L/256W | 2.799 | 3 | 4 | 6.5% | 0.0% | 0.028 |
| Training condition | Bayes agreement | KG agreement | Neither |
|---|---|---|---|
| Outcome reward | 88.7% | 8.1% | 3.2% |
| One-step process reward | 11.4% | 86.5% | 2.1% |
| Outcome-preserving | 87.9% | 8.8% | 3.3% |
| Bayes DP-score distillation | 93.4% | 4.3% | 2.3% |
| Condition | Objective audited | Opt. mass | Regret | Nearest / runner-up | Gap |
|---|---|---|---|---|---|
| Outcome reward | outcome reward | 0.803 | 0.010 | Bayes / two-step | 0.038 |
| One-step process reward | one-step verifier score | 0.812 | 0.007 | KG / entropy | 0.091 |
| Bayes DP-score distillation | outcome, audit only | 0.771 | 0.013 | Bayes / two-step | 0.057 |
| Condition | Bayes | Two-step | KG | Entropy | Open-loop |
|---|---|---|---|---|---|
| Outcome reward | .043 | .081 † | .182 | .249 | .286 |
| One-step process reward | .219 | .174 | .047 | .138 | .275 |
| Outcome-preserving | .046 | .084 | .184 | .254 | .289 |
| Bayes DP-score distillation | .018 | .075 † | .214 | .267 | .301 |
| Condition / audit | Top-action agreement | OptMass | Regret |
|---|---|---|---|
| Outcome / outcome | 96.9% | .923 | .006 |
| One-step process reward / immediate score | 95.7% | .916 | .005 |
| Distillation / outcome | 98.1% | .891 | .008 |
| Preserving / outcome | 96.6% | .918 | .006 |
| Paired intervention | Bayes ref. | Exact verifier | Outcome model | One-step process reward model |
|---|---|---|---|---|
| Remaining horizon | .204 | 0 | .187 | .021 |
| Remaining budget | .173 | 0 | .161 | .018 |
| Diagnostic | Outcome reward | One-step process reward |
|---|---|---|
| posterior log-odds NRMSE | 0.021 | 0.024 |
| Bayes-update identity NRMSE | 0.028 | 0.031 |
| action TV on state-equivalent order swaps | 0.014 | 0.016 |
| unseen value gap | 0.019 | 0.052 |
| likelihood-intervention TV to score reference | 0.058 | 0.073 |
| Reference | action TV | state / update NRMSE | long-horizon TV | value gap |
|---|---|---|---|---|
| Bayes DP | 0.018 | 0.013 / 0.019 | 0.031 | 0.006 |
| UCB bandit | 0.009 | 0.006 / 0.008 | 0.019 | 0.004 |
| Q-learning | 0.016 | 0.011 / 0.017 | 0.067 | 0.008 |
| Null range | 0.408-0.760 | 0.895-1.000 / 0.216-0.691 | 0.481-0.732 | 0.031-0.533 |
| Oracle | action TV | state / update NRMSE | long-horizon TV | value gap |
|---|---|---|---|---|
| Bayes DP | 0.760 | 1.000 / 0.691 | 0.732 | 0.533 |
| UCB bandit | 0.490 | 1.000 / 0.308 | 0.481 | 0.031 |
| Q-learning | 0.408 | 0.895 / 0.216 | 0.490 | 0.035 |
| Probe evaluation | Metric | Bayes DP | UCB | Q-learning |
|---|---|---|---|---|
| unmodified | state | 0.013 | 0.006 | 0.011 |
| update | 0.019 | 0.008 | 0.017 | |
| feedback shuffled | state | 1.153 | 0.741 | 1.062 |
| update | 1.089 | 0.697 | 0.986 | |
| targets permuted | state | 1.003 | 0.994 | 1.005 |
| update | 0.989 | 1.010 | 0.997 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Depth mean | ||
|---|---|---|---|---|---|---|---|---|---|---|
| 5 | .019 | .020 | .021 | .024 | .028 | .032 | — | — | — | .024 |
| 6 | .020 | .021 | .024 | .027 | .032 | .035 | .037 | — | — | .028 |
| 7 | .021 | .024 | .027 | .029 | .035 | .039 | .043 | .046 | — | .033 |
| 8 | .024 | .026 | .030 | .034 | .038 | .042 | .047 | .052 | .058 | .039 |
| Paired with | 5 | 6 | 7 | 8 |
|---|---|---|---|---|
| Model action TV | .010 | .011 | .013 | .014 |
| Condition | Trainer objective | Entropy protocol | Aligned reference |
|---|---|---|---|
| Outcome reward | terminal BTS return | in first ; then | hard Bayes DP |
| Outcome-preserving process reward | outcome plus perturbed telescoping potential | same | hard Bayes DP |
| Primary one-step process reward | , | in first ; then | exact one-step process reward optimum |
| Bayes DP-score distillation | cross-entropy to score teacher | none |
| Violation fraction on | |||
|---|---|---|---|
| .50 | .50 | 52.4% | -.124 |
| .50 | .75 | 48.5% | -.101 |
| .50 | 1.00 | 45.1% | -.086 |
| .50 | 1.25 | 47.9% | -.112 |
| .75 | .50 | 45.7% | -.117 |
| .75 | .75 ⋆ | 41.3% | -.096 |
| Nearest candidate | Candidate TV | Hard-objective TV | Verifier regret | Return | |
|---|---|---|---|---|---|
| (.50,.50) | Entropy | .091 | .238 | .012 | .668 |
| (.50,.75) | Entropy | .079 | .211 | .009 | .687 |
| (.50,1.00) | Hybrid † | .087 | .198 | .008 | .696 |
| (.50,1.25) | Entropy | .098 | .226 | .011 | .679 |
| (.75,.50) | KG | .076 | .219 | .010 | .696 |
| (.75,.75) ⋆ | KG | .047 | .188 | .007 | .710 |
| Condition | Bayes DP-score TV | KG-score TV | Two-step-score TV | Return | Post. NRMSE | Update NRMSE |
|---|---|---|---|---|---|---|
| Outcome-preserving process reward | 0.046 | 0.184 | 0.084 | 0.752 | 0.023 | 0.030 |
| , 4,096 histories | , 1,024 histories | ||||
|---|---|---|---|---|---|
| Violations | Violations | ||||
| .00 | 1540 | -.078000 | 1024 | -.103180 | |
| .25 | 1428 | -.069700 | 1001 | -.101249 | |
| .50 | 1076 | -.043800 | 836 | -.087732 | |
| .70 | 628 | -.020600 | 482 | -.060792 | |
| .85 | 231 | -.006280 | 164 | -.027286 | |
| Bayes TV | Two-step TV | KG TV | Entropy TV | Open-loop TV | |
|---|---|---|---|---|---|
| .00 | .218 | .172 | .038 | .142 | .277 |
| .25 | .211 | .166 | .048 | .151 | .278 |
| .50 | .179 | .129 | .073 | .172 | .281 |
| .70 | .128 | .077 | .118 | .205 | .283 |
| .85 | .081 | .063 | .157 | .226 | .285 |
| .90 | .061 | .069 | .168 | .239 | .286 |
| Nearest | Return | OptMass | Regret | Hard agreement on | |||
|---|---|---|---|---|---|---|---|
| Bayes | KG | Neither | |||||
| .00 | KG | .711 | .830 | .005 | 6.9% | 90.5% | 2.6% |
| .25 | KG | .716 | .824 | .006 | 9.1% | 87.3% | 3.6% |
| .50 | KG | .725 | .809 | .008 | 21.0% | 72.1% | 6.9% |
| .70 | Two-step | .737 | .786 | .009 | 49.0% | 42.4% | 8.6% |
| .85 | Two-step | .744 | .792 | .010 | 76.7% | 17.5% | 5.8% |
| Training | Evaluation | Bayes-ref. TV | KG-ref. TV | return |
|---|---|---|---|---|
| Outcome reward | training templates | 0.131 | 0.191 | 0.676 |
| unseen paraphrases | 0.178 | 0.245 | 0.641 | |
| shuffled cards | 0.674 | 0.698 | 0.296 | |
| One-step process reward | training templates | 0.268 | 0.114 | 0.629 |
| unseen paraphrases | 0.277 | 0.153 | 0.602 | |
| shuffled cards | 0.671 | 0.685 | 0.290 |
| Training | Evaluation | Two-step TV | Entropy TV | Open-loop TV |
|---|---|---|---|---|
| Outcome reward | training templates | .155 | .232 | .288 |
| unseen paraphrases | .206 | .282 | .334 | |
| shuffled cards | .683 | .708 | .721 | |
| One-step process reward | training templates | .229 | .199 | .300 |
| unseen paraphrases | .244 | .220 | .313 | |
| shuffled cards | .678 | .704 | .720 |
In-Context Learning
In-context learning studies how models adapt to new tasks from examples or instructions supplied at inference time, without changing their weights.
See all 402 papers