# joycode-agent
**Repository Path**: JD-opensource/joycode-agent
## Basic Information
- **Project Name**: joycode-agent
- **Description**: Repository-level Repair Agent Based on SWE-BenchβJoyCode Agent
- **Primary Language**: Python
- **License**: MIT
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 39
- **Forks**: 2
- **Created**: 2025-10-15
- **Last Updated**: 2025-10-24
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# JoyCode SWE-bench Agent Pipeline
[](https://www.python.org/downloads/) [](https://opensource.org/licenses/MIT) [](https://www.docker.com/)
**JoyCode** is an end-to-end LLM-powered pipeline for fixing real-world open-source software issues. It generates patches, creates and verifies tests, and employs intelligent retry mechanisms to achieve high success rates on the SWE-bench dataset.
**Project Status:** JoyCode has achieved **74.6% resolution rate** on SWE-bench Verified split, demonstrating state-of-the-art performance in automated software engineering.
**Key Innovation:** Our pipeline combines patch generation with intelligent test creation and failure attribution, enabling robust automated code repair with comprehensive validation and smart retry mechanisms.
## β¨ Features
### π **High Performance & Cost Efficiency**
- **74.6% Success Rate** on SWE-bench Verified, ranking 2nd globally
- **30-50% Lower Resource Consumption** than top competitors
- Exceptional cost-performance ratio with near state-of-the-art results
### π **Patch-Test Co-generation**
- **Smart Test Generation**: Automatic Fail2Pass and Pass2Pass test creation with pre-validation
- **Collaborative Verification**: Patches and tests generated together for comprehensive validation
- **Closed-loop Iteration**: "Generate β Validate β Refine" cycle replacing one-shot approaches
### π§ **Intelligent Failure Attribution**
- **Root Cause Analysis**: Precise failure attribution to patch vs. test issues
- **Targeted Retry Strategy**: Experience-driven retries based on failure analysis
- **CSR-Powered Learning**: Historical success pattern retrieval for optimization
### ποΈ **Multi-Agent Architecture**
- **Specialized Agents**: Testing, Patch, CSR, and Decision agents with distinct roles
- **React-based Workflow**: "Observe-Think-Act" loop mimicking human developers
- **Smart Decision Making**: LLM-powered voting for optimal patch selection
### π‘ **Smart Resource Management**
- **Token-Efficient Design**: Targeted LLM calls avoiding wasteful parallel sampling
- **Early Failure Detection**: Pre-validation to filter invalid paths
- **Quality-First Generation**: Fewer, higher-quality patches over massive sampling
### π³ **Production-Ready Engineering**
- **Containerized Execution**: Isolated Docker environments with SWE-bench images
- **Repository-Level Understanding**: Multi-file coordination and cross-module reasoning
- **Comprehensive Logging**: Full trajectory recording with optional compression
- **Multi-LLM Support**: Flexible model configuration for different pipeline stages
## π Installation
### Requirements
- Python 3.11+
- Docker with access to `docker.1ms.run`
- LLM API keys (OpenAI, Anthropic, etc.)
### Setup
```bash
# Clone repository
git clone https://gitee.com/JD-opensource/joycode-agent.git
cd joycode
# Create conda environment
conda create -n joycode python=3.11
conda activate joycode
# Install dependencies
pip install -r requirements.txt
```
## βοΈ Configuration
### LLM Configuration
Configure your models in `llm_server/model_config.json`:
```json
{
"patch_generation": {
"api_key": "your_api_key_here",
"base_url": "https://api.openai.com/v1",
"model_name": "gpt-5",
"max_tokens": 4000,
"temperature": 1
}
}
```
### Docker Setup
Ensure Docker is running and you can access the registry:
```bash
# Test Docker connectivity
docker pull docker.1ms.run/swebench/sweb.eval.x86_64.django__django-11099:latest
```
### Instance Configuration
Specify instances to process in `instance_id.txt`:
```
django__django-11099
matplotlib__matplotlib-23562
sympy__sympy-18189
...
```
## π Usage
### Quick Start
```bash
# Run with default settings
python run_patch_pipeline.py --num-processes 1 --enable-post-processing
```
### Common Usage Patterns
```bash
# Simple mode (patch only, no tests)
python run_patch_pipeline.py --simple-mode
# Single instance processing
python run_patch_pipeline.py --problem-id django__django-11099 --num-processes 1
# Batch processing with limits
python run_patch_pipeline.py --num-examples 10 --num-processes 4
# Disable test generation
python run_patch_pipeline.py --no-generate-tests --no-validate-with-tests
# Custom configuration
python run_patch_pipeline.py --enable-post-processing --num-processes 2
```
### Command Line Options
| Option | Description | Default |
|--------|-------------|---------|
| `--num-processes` | Number of parallel processes | 1 |
| `--enable-post-processing` | Enable trajectory compression and retries | False |
| `--simple-mode` | Patch generation only | False |
| `--problem-id` | Process single instance | None |
| `--num-examples` | Limit number of instances | All |
| `--no-generate-tests` | Skip test generation | False |
| `--no-validate-with-tests` | Skip test validation | False |
## π οΈ Advanced Features
### Patch Voting System
Compare and select between multiple patch candidates:
```bash
# Prepare voting inputs
python scripts/prepare_voting_data.py
# Run voting
python vote.py
```
**Input Requirements:**
- `patch_1.json`: Primary patch candidates
- `patch_2.json`: Alternative patch candidates
- `test-00000-of-00001.parquet`: Instance metadata with problem statements
### Pipeline Stages
1. **Container Setup**: Pull and start SWE-bench Docker images
2. **Test Generation** (optional): Create and validate tests on original code
3. **Agent Execution**: Generate patches using LLM agents via `cli.py`
4. **Validation**: Run tests and evaluate patch quality
5. **Post-processing** (optional): Trajectory compression, similarity matching, intelligent retries
### Output Structure
```
output_files/
βββ /
β βββ predictions.json # Generated patch and metadata
β βββ agent_logs.txt # Main agent execution logs
β βββ test_generation_result.json # Test generation results
β βββ test_generation_logs.txt # Test generation logs
β βββ agent_logs_retry.txt # Retry attempt logs
β βββ compressed_trajectory.txt # Compressed execution trajectory
βββ successful_cases.txt # Summary of successful instances
βββ failed_cases.txt # Summary of failed instances
βββ empty_diff_cases.txt # Cases with no generated patches
βββ similar_case_matches_summary.json # Similar case analysis
```
## π Performance Results
```
Submission summary for 20250909_JoyCode on SWE-bench verified split
==================================================
Resolved 373 instances (74.6%)
==================================================
Resolved by Repository:
- astropy/astropy: 13/22 (59.09%)
- django/django: 178/231 (77.06%)
- matplotlib/matplotlib: 25/34 (73.53%)
- mwaskom/seaborn: 1/2 (50.0%)
- pallets/flask: 1/1 (100.0%)
- psf/requests: 3/8 (37.5%)
- pydata/xarray: 19/22 (86.36%)
- pylint-dev/pylint: 2/10 (20.0%)
- pytest-dev/pytest: 17/19 (89.47%)
- scikit-learn/scikit-learn: 28/32 (87.5%)
- sphinx-doc/sphinx: 29/44 (65.91%)
- sympy/sympy: 57/75 (76.0%)
```
## π§ Development
### Repository Structure
```
joycode/
βββ run_patch_pipeline.py # Main entry point
βββ cli.py # Core agent CLI
βββ test_case_generator/ # Test generation logic
βββ test/ # Test execution and validation
βββ utils/docker_utils.py # Container management
βββ llm_server/ # LLM integration layer
βββ princeton-nlp___swe-bench_verified/ # Local SWE-bench dataset
βββ vote.py # Patch voting system
```
### Troubleshooting
**Docker Issues:**
```bash
# Check Docker connectivity
docker info
docker pull docker.1ms.run/hello-world
```
**LLM Configuration:**
```bash
# Verify model config
python -c "import json; print(json.load(open('llm_server/model_config.json')))"
```
**Memory Issues:**
```bash
# Reduce parallel processes
python run_patch_pipeline.py --num-processes 1
```
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## π Acknowledgments
- [SWE-bench](https://www.swe-bench.com/) for providing the benchmark dataset