This guide provides step-by-step instructions to reproduce the results from the CodeStruct paper using the SWE-Bench Verified dataset.
- Python >= 3.11
- OpenAI API key (for GPT models) OR AWS credentials (for Bedrock models)
- At least 16GB RAM recommended
- GPU not required
The recommended way is to use the setup script which creates a venv and installs everything:
cd CodeStruct
# Run setup (creates venv, installs all dependencies, verifies AST tools)
chmod +x setup.sh
./setup.sh
# Activate the virtual environment
source venv/bin/activateThe setup script will:
- Find Python >= 3.11 on your system
- Create a virtual environment at
venv/ - Install tree-sitter with correct pinned versions (0.21.3 + tree-sitter-languages 1.10.2)
- Install SWE-agent and swebench
- Verify all components work (including AST tool tests)
If you prefer to install manually:
cd CodeStruct
# Create venv with Python 3.11+
python3.11 -m venv venv
source venv/bin/activate
# CRITICAL: Install tree-sitter with pinned versions FIRST
pip install "tree-sitter==0.21.3" "tree-sitter-languages==1.10.2"
# Install SWE-agent
cd SWE-agent
mkdir -p trajectories
pip install -e .
cd ..
# Install SWE-Bench for evaluation
pip install swebench
⚠️ Important: tree-sitter versions must be pinned. tree-sitter >= 0.22 has an incompatible API with tree-sitter-languages, causing AST tools to silently fail.
For OpenAI models:
export OPENAI_API_KEY=sk-your-key-hereFor AWS Bedrock models:
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
export AWS_REGION_NAME=us-east-1Test on a small subset to verify setup:
cd CodeStruct/SWE-agent
# CodeStruct configuration (with AST tools)
python -m sweagent run-batch \
--instances.type swe_bench \
--instances.subset verified \
--instances.split test \
--config config/default_with_readcode_batch.yaml \
--agent.model.name gpt-5-mini \
--agent.model.per_instance_cost_limit 3.00 \
--agent.model.top_p null \
--agent.model.temperature 1 \
--instances.slice :5 \
--num_workers 5With OpenAI GPT-5-mini:
cd CodeStruct/SWE-agent
python -m sweagent run-batch \
--instances.type swe_bench \
--instances.subset verified \
--instances.split test \
--config config/default_with_readcode_batch.yaml \
--agent.model.name gpt-5-mini \
--agent.model.per_instance_cost_limit 3.00 \
--agent.model.top_p null \
--agent.model.temperature 1 \
--num_workers 10With AWS Bedrock Qwen3-Coder 480B:
cd CodeStruct/SWE-agent
python -m sweagent run-batch \
--instances.type swe_bench \
--instances.subset verified \
--instances.split test \
--config config/default_with_readcode_batch.yaml \
--agent.model.name bedrock/qwen.qwen3-coder-480b-a35b-v1:0 \
--agent.model.per_instance_cost_limit 0.00 \
--agent.model.temperature 0 \
--num_workers 15After the batch run completes, find the predictions file in the trajectories directory and evaluate:
cd CodeStruct/SWE-agent
# Find your predictions file path
# It will be in: trajectories/username/config_name__model_name__*/preds.json
python -m swebench.harness.run_evaluation \
--predictions_path trajectories/$USER/default_with_readcode_batch__gpt-5-mini__*/preds.json \
-d princeton-nlp/SWE-bench_Verified \
-s test \
--run_id gpt5mini_codestruct_reproduction \
--max_workers 15The evaluation will generate a results JSON file with:
resolved: Number of issues successfully resolvedtotal: Total number of issues evaluatedresolve_rate: Percentage of issues resolved
To reproduce all model results from the paper:
cd CodeStruct/SWE-agent
# GPT-5 (if available)
python -m sweagent run-batch \
--instances.type swe_bench \
--instances.subset verified \
--instances.split test \
--config config/default_with_readcode_batch.yaml \
--agent.model.name gpt-5 \
--agent.model.per_instance_cost_limit 5.00 \
--agent.model.top_p null \
--agent.model.temperature 1 \
--num_workers 10
# GPT-5-mini
python -m sweagent run-batch \
--instances.type swe_bench \
--instances.subset verified \
--instances.split test \
--config config/default_with_readcode_batch.yaml \
--agent.model.name gpt-5-mini \
--agent.model.per_instance_cost_limit 3.00 \
--agent.model.top_p null \
--agent.model.temperature 1 \
--num_workers 10
# GPT-5-nano
python -m sweagent run-batch \
--instances.type swe_bench \
--instances.subset verified \
--instances.split test \
--config config/default_with_readcode_batch.yaml \
--agent.model.name gpt-5-nano \
--agent.model.per_instance_cost_limit 1.00 \
--agent.model.top_p null \
--agent.model.temperature 1 \
--num_workers 10To compare CodeStruct with the baseline (without AST tools), you'll need to:
- Get the original SWE-agent configuration files (without AST tools)
- Run the same experiments with those configurations
- Compare the results
The baseline configuration should:
- NOT include
tools/ast_readbundle - NOT include
tools/ast_editbundle - Use standard bash tool instead of safeBash
- Use standard string-based editing tools
After evaluation, you'll find result files in:
- Predictions:
trajectories/username/config_model__*/preds.json - Evaluation:
princeton-nlp/SWE-bench_Verified/test/run_id.json
- Resolved: Number of test instances where the patch passed all tests
- Resolved Rate: Percentage of resolved instances
- Applied: Number of patches that were successfully applied
- Applied Rate: Percentage of successfully applied patches
Each instance generates a trajectory file showing:
- Agent's thought process
- Tool calls made
- Code changes applied
- Terminal output
These are stored in: trajectories/username/config_model__*/
Solution: Make sure you ran pip install -e . from the SWE-agent directory
Solution: Verify your environment variables are set:
echo $OPENAI_API_KEY # Should show your key
# or
echo $AWS_ACCESS_KEY_ID # Should show your keySolution: Reduce the number of workers:
--num_workers 5 # Instead of 10 or 15Solution:
- Reduce
num_workers - Close other applications
- Use a machine with more RAM
Solution:
- Check your internet connection
- Reduce workers for API rate limits
- Consider using a faster model for testing
Run on specific instances:
--instances.slice 0:100 # First 100 instances
--instances.slice 100:200 # Instances 100-200Set cost limits per instance:
--agent.model.per_instance_cost_limit 2.00 # Max $2 per instanceAdjust model behavior:
--agent.model.temperature 1 # Higher = more creative
--agent.model.top_p null # Disable nucleus samplingThe ../results/SWE-Bench/ directory contains pre-computed results:
-
CodeStruct results (with AST tools):
gpt5_codestruct.jsongpt5mini_codestruct.jsongpt5nano_codestruct.jsonqwen3_8b_codestruct.jsonqwen3_32b_codestruct.jsonqwen3coder480b_codestruct.json
-
Original results (baseline, no AST tools):
gpt5_original.jsongpt5mini_original.jsongpt5nano_original.jsonqwen3_8b_original.jsonqwen3_32b_original.jsonqwen3coder480b_original.json
You can compare your reproduced results with these files.