Reflexion
Reflexion is a framework for language agents that uses verbal reinforcement learning to improve performance on reasoning and decision-making tasks. It solves the problem of agents not learning from past mistakes by enabling them to reflect on failures and use those reflections in subsequent attempts. It is intended for researchers and developers working with large language models.
✨ Key features
- Implements Reflexion: verbal reinforcement learning for language agents
- Supports reasoning tasks on HotPotQA with multiple agent types
- Supports decision-making tasks in AlfWorld environments
- Provides configurable reflexion strategies (none, last attempt, reflection, both)
- Includes notebooks for easy experimentation and result exploration
- Logs all runs for reproducibility and analysis
🎯 Use cases
- Improve question-answering accuracy on HotPotQA with self-reflection
- Train agents to solve household tasks in AlfWorld through iterative learning
- Compare different reflexion strategies to find optimal learning approach
- Resume interrupted experiments using logging directories
📦 Installation
🧰 Requirements: Python environment with dependencies from requirements.txt, OpenAI API key for GPT-4 access.
git clone https://github.com/noahshinn/reflexion && cd ./hotpotqa_runs
Then install dependencies:
pip install -r requirements.txt
Set your OpenAI API key:
export OPENAI_API_KEY=<your key>
🚀 Usage
For reasoning (HotPotQA), run the provided notebooks in ./hotpot_runs/notebooks. For decision-making (AlfWorld), configure ./run_reflexion.sh and execute:
./run_reflexion.sh
⚠️ Good to know
Due to GPT-4 limited access and significant API charges, it may not be feasible for individual developers to rerun the results; all runs from the paper are logged for reference.
❓ FAQ
What agent types are available for HotPotQA?
The agent types are ReAct, CoT_context (CoT with supporting context), and CoT_no_context (CoT without context).
What reflexion strategies can I use?
Strategies include NONE, LAST_ATTEMPT, REFLEXION, and LAST_ATTEMPT_AND_REFLEXION, which control what context the agent receives about previous attempts.
How do I resume a previous AlfWorld run?
Set is_resume to true, specify the resume_dir logging directory, and set start_trial_num to the trial number to resume from.
Where can I find the results from the paper?
All runs are logged in ./alfworld_runs/root for decision-making, ./hotpotqa_runs/root for reasoning, and ./programming_runs/root for programming.
📊 Repository
🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.