|
| 1 | +# Example of Training a BrowseComp-Plus Search Agent |
| 2 | + |
| 3 | +This example demonstrates how to train a web search and information retrieval agent on the **BrowseComp-Plus** dataset using the ReAct (Reasoning and Acting) paradigm. |
| 4 | + |
| 5 | +BrowseComp-Plus is a comprehensive benchmark for evaluating information retrieval and question answering capabilities. The original dataset and benchmark can be found at [BrowseComp-Plus GitHub](https://github.com/texttron/BrowseComp-Plus). |
| 6 | + |
| 7 | +The config file is located in [`bcp_config.yaml`](bcp_config.yaml). |
| 8 | + |
| 9 | +## Key Features |
| 10 | + |
| 11 | +* **Training ReAct Agent**: The workflow trains a ReAct agent that can reason and act with search tools to find information and answer questions. |
| 12 | +* **Local Search Integration**: The agent uses local BM25 or dense retrieval search (no external API required) via BrowseComp-Plus's built-in searcher. |
| 13 | +* **Tool-based Interaction**: The agent can: |
| 14 | + * **Search**: Query the search index to find relevant documents |
| 15 | + * **Get Document** (optional): Retrieve full document content by document ID |
| 16 | +* **LLM-as-Judge Evaluation**: The agent's final answer is evaluated by an auxiliary "judge" LLM against ground-truth answers to generate reward signals for training. |
| 17 | +* **Asynchronous Execution**: The workflow is designed to run asynchronously for better performance. |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +Before running this workflow, please complete the following setup steps. |
| 22 | + |
| 23 | +### 1. Install BrowseComp-Plus |
| 24 | + |
| 25 | +Clone and set up the BrowseComp-Plus repository: |
| 26 | + |
| 27 | +```bash |
| 28 | +# Clone the repository |
| 29 | +git clone https://github.com/texttron/BrowseComp-Plus.git |
| 30 | + |
| 31 | +# Set the environment variable (add this to your ~/.bashrc or ~/.zshrc for persistence) |
| 32 | +export BROWSECOMP_PATH="/path/to/BrowseComp-Plus" |
| 33 | + |
| 34 | +# Install dependencies |
| 35 | +cd $BROWSECOMP_PATH |
| 36 | +pip install -r requirements.txt |
| 37 | +``` |
| 38 | + |
| 39 | +### 2. Download and Decrypt the Dataset |
| 40 | + |
| 41 | +Follow the instructions in BrowseComp-Plus to download and decrypt the dataset: |
| 42 | + |
| 43 | +```bash |
| 44 | +cd $BROWSECOMP_PATH |
| 45 | + |
| 46 | +# Download the encrypted dataset |
| 47 | +# Follow instructions at: https://github.com/texttron/BrowseComp-Plus#data |
| 48 | +python scripts_build_index/decrypt_dataset.py --output data/browsecomp_plus_decrypted.jsonl --generate-tsv topics-qrels/queries.tsv |
| 49 | +``` |
| 50 | + |
| 51 | +### 3. Build the Search Index |
| 52 | + |
| 53 | +Build the BM25 search index (or other index types if preferred): |
| 54 | + |
| 55 | +```bash |
| 56 | +cd $BROWSECOMP_PATH |
| 57 | + |
| 58 | +# Build Search index |
| 59 | +bash scripts_build_index/download_indexes.sh |
| 60 | + |
| 61 | +# (Optional) To try out other retrieval index methods, please refer to instructions in BrowseComp-Plus Repo |
| 62 | +``` |
| 63 | + |
| 64 | +### 4. Generate Trinity-RFT Format Dataset |
| 65 | + |
| 66 | +Convert the BrowseComp-Plus dataset to Trinity-RFT format: |
| 67 | + |
| 68 | +```bash |
| 69 | +# From the Trinity-RFT root directory |
| 70 | +python examples/browse_comp_plus/get_browse_comp_data_for_trinity.py \ |
| 71 | + --input $BROWSECOMP_PATH/data/browsecomp_plus_decrypted.jsonl \ |
| 72 | + --output_dir data/trinity_format \ |
| 73 | + --train_size 400 \ |
| 74 | + --test_size 200 \ |
| 75 | + --seed 42 |
| 76 | +``` |
| 77 | + |
| 78 | +This will create: |
| 79 | +- `data/trinity_format/train.jsonl`: Training set (400 samples) |
| 80 | +- `data/trinity_format/test.jsonl`: Test set (200 samples) |
| 81 | + |
| 82 | +### 5. Set Environment Variables and Config |
| 83 | + |
| 84 | +The configuration file uses environment variables with sensible defaults. Set the required variables: |
| 85 | + |
| 86 | +```bash |
| 87 | +# Required: Path to BrowseComp-Plus directory |
| 88 | +export BROWSECOMP_PATH="/path/to/BrowseComp-Plus" |
| 89 | +``` |
| 90 | + |
| 91 | +You should also set the `model_path` and the `auxiliary_model_path` in `bcp_config.yaml`. |
| 92 | + |
| 93 | +## Running the Training |
| 94 | + |
| 95 | +Once everything is configured, start the training: |
| 96 | + |
| 97 | +```bash |
| 98 | +# Make sure environment variables are set |
| 99 | +export BROWSECOMP_PATH="/path/to/BrowseComp-Plus" |
| 100 | +export TRINITY_TASKSET_PATH="data/trinity_format" |
| 101 | + |
| 102 | +# start the ray server |
| 103 | +ray start --head |
| 104 | + |
| 105 | +# Run training |
| 106 | +trinity run --config examples/browse_comp_plus/bcp_config.yaml |
| 107 | +``` |
| 108 | + |
| 109 | +### Workflow Arguments |
| 110 | + |
| 111 | +The `workflow_args` section controls the agent's behavior: |
| 112 | + |
| 113 | +* **`searcher_type`**: Type of search index to use (e.g. `"bm25"`, etc.) |
| 114 | +* **`index_path`**: Path to the search index (uses `BROWSECOMP_INDEX_PATH` env variable) |
| 115 | +* **`browsecomp_path`**: Path to BrowseComp-Plus directory (uses `BROWSECOMP_PATH` env variable) |
| 116 | +* **`max_iterations`**: Maximum number of search/reasoning steps (default: 30) |
| 117 | +* **`top_k`**: Number of search results returned per query (default: 5) |
| 118 | +* **`snippet_max_tokens`**: Maximum tokens to include from each document snippet (default: 512) |
| 119 | +* **`include_get_document`**: Whether to enable the `get_document` tool (default: false) |
| 120 | + |
| 121 | + |
| 122 | +## Results |
| 123 | + |
| 124 | +From the below curve you can see that the agent learns for leverage more search calls to gain more accurate answers. |
| 125 | + |
| 126 | +Reward curve: |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +Search call curve: |
| 131 | + |
| 132 | + |
0 commit comments