TLDR: CLAPP is an AI assistant that helps researchers use the CLASS cosmology code. It leverages multiple AI agents, retrieves information from CLASS documentation, and can execute and debug Python code, making it easier for scientists to work with complex cosmological simulations and generate plots.
In the rapidly evolving landscape of scientific research, computational tools are indispensable. For cosmologists, one such critical tool is CLASS (the Cosmic Linear Anisotropy Solving System), a powerful Einstein-Boltzmann solver used to calculate cosmic microwave background anisotropies and large-scale structure observables. Despite its widespread use, CLASS, like many complex scientific software packages, can be challenging to navigate, especially for new users, due to its extensive codebase and numerous parameters.
Addressing this challenge, a new interactive AI assistant named CLAPP (CLASS LLM Agent for Pair Programming) has been introduced. CLAPP is designed to significantly lower the entry barrier for researchers working with CLASS, enabling more productive human-AI collaboration in computational and numerical cosmology. It provides conversational coding support, capable of answering questions, generating code, debugging errors, and producing plots, all within a user-friendly web application.
What is CLAPP and Why is it Needed?
Modern cosmology heavily relies on sophisticated computational tools like CLASS. However, the sheer size and complexity of such tools, with tens of thousands of lines of code and hundreds of tunable parameters, often lead to tedious and error-prone processes for researchers. While large language models (LLMs) like GPT-4 have shown promise in code generation and problem-solving, they often lack specialized training on scientific software, leading to inaccuracies or outdated information.
CLAPP bridges this gap by combining the power of LLMs with domain-specific knowledge and a live execution environment. It acts as a specialized AI pair-programming assistant, understanding the intricacies of CLASS and its Python wrapper, classy.
How CLAPP Works: A Look Under the Hood
CLAPP’s robust architecture is built on three key components:
Multi-Agent LLM Orchestration: Instead of a single AI, CLAPP employs a team of specialized language models that work together. In its “Deep Thought Mode,” a dedicated CLASS agent drafts a response, which is then reviewed and refined by a separate review agent. This iterative process, similar to an automated peer-review, ensures high-quality and accurate answers. For quicker interactions, a “Fast Mode” provides immediate drafts without the review loop. These agents are powered by models like OpenAI’s GPT-4 or Google’s Gemini, each guided by specific prompts to optimize their roles.
Retrieval-Augmented Generation (RAG) with CLASS Knowledge: To prevent hallucinations and ensure accuracy, CLAPP grounds its responses in the official and latest CLASS documentation and codebase. When a user asks a question, CLAPP performs a semantic search over a vectorized database of CLASS materials. The most relevant snippets are then injected directly into the LLM prompt, allowing CLAPP to provide authoritative and contextually accurate information, whether explaining a parameter like “omega b” or generating code.
Live Code Execution and Plotting: A standout feature of CLAPP is its ability to not just talk about code, but to run it. Users can install the full CLASS code and its Python wrapper classy directly within the application. If CLAPP generates Python code, a “Run Last Code Block” button activates, allowing immediate execution. If errors occur, a debugging agent automatically analyzes the messages and attempts to correct the code, creating a self-correcting loop. This capability extends to generating plots on the fly, allowing researchers to visualize results directly within the chat interface, dramatically shortening the experimentation cycle.
Practical Applications and User Experience
CLAPP is deployed as a user-friendly web application via Streamlit, making it accessible to anyone with an internet connection without complex installations. Users simply provide an API key for their chosen LLM (OpenAI or Google Gemini) and can begin interacting with CLAPP through a chat interface. The system maintains conversational memory, allowing for seamless, context-aware dialogue.
Examples demonstrate CLAPP’s versatility, from plotting the lensed CMB TT Câ„“ using classy to illustrating the suppression of the matter power spectrum due to massive neutrinos. The system provides both the generated code and a detailed free-text explanation of the solution, making it an invaluable tool for both beginners and advanced users of CLASS.
Also Read:
- AI-Powered Tools for Navigating Complex Codebases
- Enhancing AI Agent Tool Selection with Knowledge Graphs for Enterprise Tasks
The Future of Scientific Collaboration
CLAPP represents a significant step towards integrating AI pair-programming tools into the daily practice of cosmologists. By combining state-of-the-art language models with domain-specific retrieval and a live execution environment, it functions as an intelligent assistant tailored for cosmology workflows. The project is open-source, with its code available on GitHub, inviting the cosmology community to experiment and contribute. This approach holds immense potential for extension to other scientific codes and domains, promising a future where AI assistants become increasingly valuable collaborators, augmenting human capabilities in research. You can find the full research paper here: CLAPP: The CLASS LLM Agent for Pair Programming.


