JoyCode Agent

repository·main·Indexed 43 days ago

https://github.com/jd-opensource/joycode-agent

An end-to-end LLM-powered pipeline and multi-agent architecture designed to fix real-world open-source software issues. It features patch generation, intelligent test creation, and failure attribution, achieving high success rates on the SWE-bench dataset. The system includes a CLI for interactive and non-interactive task execution, a patch voting system, and integration with Docker for environment isolation.

Tokens
2.1K
Snippets
6
Records
11
Agent score
6%

What's inside JoyCode

  1. Configure Docker and Instances

    main

    Docker Setup

    Ensure Docker is running and can pull images from the required registry:

    docker pull docker.1ms.run/swebench/sweb.eval.x86_64.django__django-11099:latest

    Instance Selection

    To specify which SWE-bench instances to process, list their IDs in a file named instance_id.txt. Example format:

    django__django-11099
    matplotlib__matplotlib-23562
    sympy__sympy-18189
  2. Install and Setup JoyCode

    main

    To use JoyCode, you need Python 3.11+, Docker (with access to docker.1ms.run), and LLM API keys (e.g., OpenAI, Anthropic). Follow these steps to set up your environment:

    1. Clone the repository
    2. Create and activate a Conda environment
    3. Install dependencies via pip
    # Clone repository
    git clone https://github.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
  3. Use the Patch Voting System

    main

    To compare and select between multiple patch candidates, use the voting scripts. This requires prepared voting data.

    1. Prepare voting inputs using scripts/prepare_voting_data.py.
    2. Run the voting process using vote.py.

    Required Input Files:

    • patch_1.json: Primary patch candidates
    • patch_2.json: Alternative patch candidates
    • test-00000-of-00001.parquet: Instance metadata with problem statements
    # Prepare voting inputs
    python scripts/prepare_voting_data.py
    
    # Run voting
    python vote.py
  4. Run the Patch Pipeline

    main

    The main entry point for the pipeline is run_patch_pipeline.py. Use it to generate patches, create tests, and validate fixes for software issues.

    # Run with default settings
    python run_patch_pipeline.py --num-processes 1 --enable-post-processing
  5. Configure LLM Models

    main

    LLM settings are managed in llm_server/model_config.json. You must provide the api_key, base_url, and model_name for the patch_generation stage. You can also tune max_tokens and temperature.

    {
      "patch_generation": {
        "api_key": "your_api_key_here",
        "base_url": "https://api.openai.com/v1",
        "model_name": "gpt-5",
        "max_tokens": 4000,
        "temperature": 1
      }
    }
  6. Use the JoyCode Agent CLI

    main

    The JoyCode Agent CLI allows you to interact with the agent either through an interactive terminal session or by providing a non-interactive problem statement.

    Interactive Mode: By default, the CLI starts an interactive loop where you can type instructions directly to the agent. You can exit by typing exit or quit, or by pressing Ctrl+C.

    Non-Interactive Mode: Pass a --problem-statement to provide a specific task. In this mode, the agent will process the instruction and then exit automatically once the task is complete.

    Environment Requirement: The agent requires an ANTHROPIC_API_KEY environment variable to be set to function.

    # Interactive mode
    python cli.py
    
    # Non-interactive mode with a problem statement
    python cli.py --problem-statement "Fix the bug in the authentication module"
    
    # Running with a specific workspace and requiring permission for commands
    python cli.py --workspace ./my_project --needs-permission
  7. Troubleshoot JoyCode issues

    main

    Docker Connectivity

    If Docker issues occur, verify connectivity and test pulling a small image:

    docker info
    docker pull docker.1ms.run/hello-world

    LLM Configuration

    To verify your llm_server/model_config.json is valid and readable:

    python -c "import json; print(json.load(open('llm_server/model_config.json')))"

    Memory/Resource Issues

    If you encounter memory issues, reduce the number of parallel processes:

    python run_patch_pipeline.py --num-processes 1
  8. Common Usage Patterns for the Pipeline

    main

    Depending on your goal, use the following command patterns:

    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 and validation:

    python run_patch_pipeline.py --no-generate-tests --no-validate-with-tests
    # 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
    
    # Disable test validation
    python run_patch_pipeline.py --no-validate-with-tests
  9. Understand the Pipeline Output Structure

    main

    Results are stored in the output_files/ directory, organized by instance ID. Each instance folder contains:

    • predictions.json: The generated patch and associated metadata.
    • agent_logs.txt: Main execution logs for the agent.
    • test_generation_result.json: Results from the test generation stage.
    • test_generation_logs.txt: Logs from the test generation stage.
    • agent_logs_retry.txt: Logs specifically for retry attempts.
    • compressed_trajectory.txt: A compressed version of the execution trajectory.

    Global summary files include:

    • successful_cases.txt: Summary of successful instances.
    • failed_cases.txt: Summary of failed instances.
    • empty_diff_cases.txt: Cases where no patches were generated.
    • similar_case_matches_summary.json: Analysis of similar cases.
  10. Use CLI options for run_patch_pipeline.py

    main

    The run_patch_pipeline.py script supports several flags to control execution behavior:

    OptionDescriptionDefault
    --num-processesNumber of parallel processes1
    --enable-post-processingEnable trajectory compression and retriesFalse
    --simple-modePatch generation onlyFalse
    --problem-idProcess single instanceNone
    --num-examplesLimit number of instancesAll
    --no-generate-testsSkip test generationFalse
    --no-validate-with-testsSkip test validationFalse
  11. Configure JoyCode Agent CLI arguments

    main

    The CLI provides several flags to control the workspace, logging, execution environment, and agent behavior.

    FlagTypeDefaultDescription
    --workspacestr./workspacePath to the directory where code repositories are cloned and processed.
    --problem-statementstrNoneThe task description. If provided, the agent runs in non-interactive mode.
    --logs-pathstragent_logs.txtPath where agent logs will be saved.
    --needs-permission (-p)flagFalseIf set, the agent will ask for user permission before executing commands.
    --use-container-workspacestrNonePath to a container workspace to run commands in.
    --docker-container-idstrNoneSpecific Docker container ID to run commands in.
    --minimize-stdout-logsflagFalseMinimizes logs printed to stdout (quiet mode).
    --agent-purposestrpatch_generationSets the agent's role. Supported values: patch_generation, retry_agent, test_generation.