Leveraging In-Context Learning for Language Model Agents

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Gupta, Shivanshu, Singh, Sameer, Sabharwal, Ashish, Khot, Tushar, Bogin, Ben
Format: Preprint
Publié: 2025
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866908408681070592
author Gupta, Shivanshu
Singh, Sameer
Sabharwal, Ashish
Khot, Tushar
Bogin, Ben
author_facet Gupta, Shivanshu
Singh, Sameer
Sabharwal, Ashish
Khot, Tushar
Bogin, Ben
contents In-context learning (ICL) with dynamically selected demonstrations combines the flexibility of prompting large language models (LLMs) with the ability to leverage training data to improve performance. While ICL has been highly successful for prediction and generation tasks, leveraging it for agentic tasks that require sequential decision making is challenging -- one must think not only about how to annotate long trajectories at scale and how to select demonstrations, but also what constitutes demonstrations, and when and where to show them. To address this, we first propose an algorithm that leverages an LLM with retries along with demonstrations to automatically and efficiently annotate agentic tasks with solution trajectories. We then show that set-selection of trajectories of similar tasks as demonstrations significantly improves performance, reliability, robustness, and efficiency of LLM agents. However, trajectory demonstrations have a large inference cost overhead. We show that this can be mitigated by using small trajectory snippets at every step instead of an additional trajectory. We find that demonstrations obtained from larger models (in the annotation phase) also improve smaller models, and that ICL agents can even rival costlier trained agents. Thus, our results reveal that ICL, with careful use, can be very powerful for agentic tasks as well.
format Preprint
id arxiv_https___arxiv_org_abs_2506_13109
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Leveraging In-Context Learning for Language Model Agents
Gupta, Shivanshu
Singh, Sameer
Sabharwal, Ashish
Khot, Tushar
Bogin, Ben
Computation and Language
Artificial Intelligence
In-context learning (ICL) with dynamically selected demonstrations combines the flexibility of prompting large language models (LLMs) with the ability to leverage training data to improve performance. While ICL has been highly successful for prediction and generation tasks, leveraging it for agentic tasks that require sequential decision making is challenging -- one must think not only about how to annotate long trajectories at scale and how to select demonstrations, but also what constitutes demonstrations, and when and where to show them. To address this, we first propose an algorithm that leverages an LLM with retries along with demonstrations to automatically and efficiently annotate agentic tasks with solution trajectories. We then show that set-selection of trajectories of similar tasks as demonstrations significantly improves performance, reliability, robustness, and efficiency of LLM agents. However, trajectory demonstrations have a large inference cost overhead. We show that this can be mitigated by using small trajectory snippets at every step instead of an additional trajectory. We find that demonstrations obtained from larger models (in the annotation phase) also improve smaller models, and that ICL agents can even rival costlier trained agents. Thus, our results reveal that ICL, with careful use, can be very powerful for agentic tasks as well.
title Leveraging In-Context Learning for Language Model Agents
topic Computation and Language
Artificial Intelligence
url https://arxiv.org/abs/2506.13109