Retrieval-Augmented Code Generation for Situated Action Generation: A Case Study on Minecraft

Kranti Chalamalasetti, Sherzod Hakimov, David SchlangenEMNLP 2024

Introduction

Situated action generation—the ability of an agent to translate human language into precise physical actions within a 3D environment—is a cornerstone of collaborative robotics and virtual assistants. In the context of the "Minecraft Collaborative Building Task," an AI "Builder" must interpret instructions from a human "Architect" to assemble complex structures. This task requires not only linguistic understanding but also robust spatial reasoning and the ability to track long-term dialogue history.

Traditional end-to-end neural models often struggle with the sequential nature of building and the ambiguity of human speech. This research explores a novel approach: framing action prediction as a retrieval-augmented code generation task, leveraging the pre-trained reasoning capabilities of Large Language Models (LLMs).

Methodology: Actions as Code and RAG-ICL

The core innovation lies in treating 3D block placement as a programming task. Instead of predicting raw voxel coordinates, the researchers convert builder actions into a Python-like domain-specific language (DSL) using functions such as place(color, x, y, z) and pick(color, x, y, z). This allows the LLM to utilize its extensive pre-training on code to maintain logical consistency and syntactic structure.

Overview of the LLM-based action prediction pipeline, showing the transformation of natural language instructions into executable code sequences.

To bridge the gap between general-purpose language models and the specific nuances of Minecraft building, the authors employ Retrieval-Augmented In-Context Learning (RAG-ICL). For every new instruction, a Sentence Transformer retrieves the three most relevant instruction-action pairs from the training dataset. These are then provided as few-shot examples within a highly structured prompt containing system roles, environment boundaries, and inventory details.

Experimental Results

The study evaluated several state-of-the-art models, including GPT-4o, Llama-3-70b, and a fine-tuned Llama-3-8b. GPT-4o emerged as the leader with a micro-averaged F1-score of 0.39, nearly doubling the performance of previous non-LLM baselines (0.21).

Qualitative Successes and Spatial Challenges

Qualitatively, the models demonstrated an impressive ability to handle complex linguistic phenomena like anaphora (referring back to previous objects). For instance, GPT-4o successfully interpreted instructions such as "duplicating this in a corner," where "this" refers to a previously built structure.

Example of successful anaphora resolution where the model correctly interprets "duplicating this" to replicate a structure in a new location.

However, a significant "spatial reasoning gap" remains. Even the most advanced models struggled with spatial prepositions (e.g., "to the left of") and abstract geometric concepts (e.g., "a ring"), with GPT-4o correctly interpreting prepositions only 26% of the time. Furthermore, LLMs tend to be "too perfect," failing to replicate the human-like trial-and-error sequences (placing and then correcting blocks) found in the ground-truth data.

Conclusion and Future Directions

While retrieval-augmented code generation significantly advances the state-of-the-art in situated action generation, current LLMs still lack a deep "physical" understanding of 3D space. Future research will likely move toward multi-modal architectures that integrate direct visual grounding of the voxel grid, reducing the reliance on purely text-based coordinate descriptions and improving the agent's ability to take the architect's perspective.

Summary updated

BibTeX
@inproceedings{chalamalasetti2024retrieval,
  author = {Kranti Chalamalasetti and Sherzod Hakimov and David Schlangen},
  title = {{Retrieval-Augmented Code Generation for Situated Action Generation: A Case Study on Minecraft}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.652},
}
Figure