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67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
---
dataset_info:
- config_name: matpo_train_musique
  features:
  - name: dataset
    dtype: string
  - name: data_source
    dtype: string
  - name: prompt
    list:
    - name: content
      dtype: string
    - name: role
      dtype: string
  - name: ability
    dtype: string
  - name: reward_model
    struct:
    - name: ground_truth
      dtype: string
    - name: style
      dtype: string
  - name: extra_info
    struct:
    - name: answer
      dtype: string
    - name: evidence_list
      list: 'null'
    - name: index
      dtype: int64
    - name: need_tools_kwargs
      dtype: bool
    - name: question
      dtype: string
    - name: question_type
      dtype: string
    - name: split
      dtype: string
    - name: tools_kwargs
      struct:
      - name: google_search
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: scrape
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
  splits:
  - name: train
    num_bytes: 29724892
    num_examples: 6175
  download_size: 1088403
  dataset_size: 29724892
- config_name: matpo_val_frames_repeat_2
  features:
  - name: data_source
    dtype: string
  - name: prompt
    list:
    - name: content
      dtype: string
    - name: role
      dtype: string
  - name: ability
    dtype: string
  - name: reward_model
    struct:
    - name: ground_truth
      dtype: string
    - name: style
      dtype: string
  - name: extra_info
    struct:
    - name: answer
      dtype: string
    - name: index
      dtype: string
    - name: metadata
      struct:
      - name: level
        dtype: int64
      - name: reasoning_types
        dtype: string
      - name: row_number
        dtype: int64
      - name: source
        dtype: string
      - name: wiki_links
        list: string
    - name: need_tools_kwargs
      dtype: bool
    - name: question
      dtype: string
    - name: split
      dtype: string
    - name: tools_kwargs
      struct:
      - name: google_search
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: scrape
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: search_and_browse
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
  splits:
  - name: train
    num_bytes: 8706034
    num_examples: 1648
  download_size: 408571
  dataset_size: 8706034
- config_name: matpo_val_gaia_repeat_8
  features:
  - name: dataset
    dtype: string
  - name: level
    dtype: int64
  - name: task_id
    dtype: string
  - name: data_source
    dtype: string
  - name: prompt
    list:
    - name: content
      dtype: string
    - name: role
      dtype: string
  - name: ability
    dtype: string
  - name: reward_model
    struct:
    - name: ground_truth
      dtype: string
    - name: style
      dtype: string
  - name: extra_info
    struct:
    - name: answer
      dtype: string
    - name: evidence_list
      list: 'null'
    - name: index
      dtype: int64
    - name: need_tools_kwargs
      dtype: bool
    - name: question
      dtype: string
    - name: question_type
      dtype: string
    - name: split
      dtype: string
    - name: tools_kwargs
      struct:
      - name: google_search
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: scrape
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
  splits:
  - name: train
    num_bytes: 4360455
    num_examples: 824
  download_size: 72077
  dataset_size: 4360455
- config_name: matpo_val_webwalkerqa_repeat_2
  features:
  - name: data_source
    dtype: string
  - name: prompt
    list:
    - name: content
      dtype: string
    - name: role
      dtype: string
  - name: ability
    dtype: string
  - name: reward_model
    struct:
    - name: ground_truth
      dtype: string
    - name: style
      dtype: string
  - name: extra_info
    struct:
    - name: answer
      dtype: string
    - name: index
      dtype: string
    - name: metadata
      struct:
      - name: difficulty_level
        dtype: string
      - name: domain
        dtype: string
      - name: golden_path
        list: string
      - name: lang
        dtype: string
      - name: source_website
        list: string
      - name: type
        dtype: string
    - name: need_tools_kwargs
      dtype: bool
    - name: question
      dtype: string
    - name: split
      dtype: string
    - name: tools_kwargs
      struct:
      - name: google_search
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: scrape
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: search_and_browse
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
  splits:
  - name: train
    num_bytes: 7471252
    num_examples: 1360
  download_size: 452476
  dataset_size: 7471252
- config_name: single_agent_train_musique
  features:
  - name: dataset
    dtype: string
  - name: data_source
    dtype: string
  - name: prompt
    list:
    - name: content
      dtype: string
    - name: role
      dtype: string
  - name: ability
    dtype: string
  - name: reward_model
    struct:
    - name: ground_truth
      dtype: string
    - name: style
      dtype: string
  - name: extra_info
    struct:
    - name: answer
      dtype: string
    - name: evidence_list
      list: 'null'
    - name: index
      dtype: int64
    - name: need_tools_kwargs
      dtype: bool
    - name: question
      dtype: string
    - name: question_type
      dtype: string
    - name: split
      dtype: string
    - name: tools_kwargs
      struct:
      - name: google_search
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: scrape
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
  splits:
  - name: train
    num_bytes: 36449467
    num_examples: 6175
  download_size: 1220027
  dataset_size: 36449467
- config_name: single_agent_val_frames_repeat_2
  features:
  - name: data_source
    dtype: string
  - name: prompt
    list:
    - name: content
      dtype: string
    - name: role
      dtype: string
  - name: ability
    dtype: string
  - name: reward_model
    struct:
    - name: ground_truth
      dtype: string
    - name: style
      dtype: string
  - name: extra_info
    struct:
    - name: answer
      dtype: string
    - name: index
      dtype: string
    - name: metadata
      struct:
      - name: level
        dtype: int64
      - name: reasoning_types
        dtype: string
      - name: row_number
        dtype: int64
      - name: source
        dtype: string
      - name: wiki_links
        list: string
    - name: need_tools_kwargs
      dtype: bool
    - name: question
      dtype: string
    - name: split
      dtype: string
    - name: tools_kwargs
      struct:
      - name: google_search
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: scrape
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
  splits:
  - name: train
    num_bytes: 10451730
    num_examples: 1648
  download_size: 384560
  dataset_size: 10451730
- config_name: single_agent_val_gaia_repeat_8
  features:
  - name: dataset
    dtype: string
  - name: level
    dtype: int64
  - name: task_id
    dtype: string
  - name: data_source
    dtype: string
  - name: prompt
    list:
    - name: content
      dtype: string
    - name: role
      dtype: string
  - name: ability
    dtype: string
  - name: reward_model
    struct:
    - name: ground_truth
      dtype: string
    - name: style
      dtype: string
  - name: extra_info
    struct:
    - name: answer
      dtype: string
    - name: evidence_list
      list: 'null'
    - name: index
      dtype: int64
    - name: need_tools_kwargs
      dtype: bool
    - name: question
      dtype: string
    - name: question_type
      dtype: string
    - name: split
      dtype: string
    - name: tools_kwargs
      struct:
      - name: google_search
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: scrape
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
  splits:
  - name: train
    num_bytes: 5257791
    num_examples: 824
  download_size: 72587
  dataset_size: 5257791
- config_name: single_agent_val_webwalkerqa_repeat_2
  features:
  - name: data_source
    dtype: string
  - name: prompt
    list:
    - name: content
      dtype: string
    - name: role
      dtype: string
  - name: ability
    dtype: string
  - name: reward_model
    struct:
    - name: ground_truth
      dtype: string
    - name: style
      dtype: string
  - name: extra_info
    struct:
    - name: answer
      dtype: string
    - name: index
      dtype: string
    - name: metadata
      struct:
      - name: difficulty_level
        dtype: string
      - name: domain
        dtype: string
      - name: golden_path
        list: string
      - name: lang
        dtype: string
      - name: source_website
        list: string
      - name: type
        dtype: string
    - name: need_tools_kwargs
      dtype: bool
    - name: question
      dtype: string
    - name: split
      dtype: string
    - name: tools_kwargs
      struct:
      - name: google_search
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
      - name: scrape
        struct:
        - name: create_kwargs
          struct:
          - name: ground_truth
            dtype: string
  splits:
  - name: train
    num_bytes: 8858574
    num_examples: 1360
  download_size: 412503
  dataset_size: 8858574
configs:
- config_name: matpo_train_musique
  data_files:
  - split: train
    path: matpo_train_musique/train-*
- config_name: matpo_val_frames_repeat_2
  data_files:
  - split: train
    path: matpo_val_frames_repeat_2/train-*
- config_name: matpo_val_gaia_repeat_8
  data_files:
  - split: train
    path: matpo_val_gaia_repeat_8/train-*
- config_name: matpo_val_webwalkerqa_repeat_2
  data_files:
  - split: train
    path: matpo_val_webwalkerqa_repeat_2/train-*
- config_name: single_agent_train_musique
  data_files:
  - split: train
    path: single_agent_train_musique/train-*
- config_name: single_agent_val_frames_repeat_2
  data_files:
  - split: train
    path: single_agent_val_frames_repeat_2/train-*
- config_name: single_agent_val_gaia_repeat_8
  data_files:
  - split: train
    path: single_agent_val_gaia_repeat_8/train-*
- config_name: single_agent_val_webwalkerqa_repeat_2
  data_files:
  - split: train
    path: single_agent_val_webwalkerqa_repeat_2/train-*
license: apache-2.0
---

<div align="center">

# MATPO: Multi-Agent Tool-Integrated Policy Optimization

Train Multiple Agent Roles Within a Single LLM via Reinforcement Learning.

<!-- [![arXiv](https://img.shields.io/badge/arXiv-Coming_Soon.svg)](https://arxiv.org/pdf/2510.04678)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/)
[![Code](https://img.shields.io/badge/code-GitHub-black.svg)](https://github.com/mzf666/MATPO) -->

<!-- <hr> -->
<div align="center">

[![Models](https://img.shields.io/badge/Models-5EDDD2?style=for-the-badge&logo=huggingface&logoColor=ffffff&labelColor)](https://huggingface.co/veggiebird/MATPO-14b)
[![Data](https://img.shields.io/badge/Data-0040A1?style=for-the-badge&logo=huggingface&logoColor=ffffff&labelColor)](https://huggingface.co/datasets/veggiebird/MATPO-data)
[![Paper](https://img.shields.io/badge/Paper-000000?style=for-the-badge&logo=arxiv&logoColor=white)](https://arxiv.org/abs/2510.04678)
[![Github](https://img.shields.io/badge/Code-000000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/mzf666/MATPO)
</div>


</div>

<div align="center">
  <table>
    <tr>
      <td align="center">
        <img src="assets/main_gaia.png" width="220px" alt="GAIA Results"><br>
        <em>GAIA Results</em>
      </td>
      <td align="center">
        <img src="assets/main_frameqa.png" width="220px" alt="FRAMES Results"><br>
        <em>FRAMES Results</em>
      </td>
      <td align="center">
        <img src="assets/main_webwalkerqa.png" width="220px" alt="WebWalkerQA Results"><br>
        <em>WebWalkerQA Results</em>
      </td>
    </tr>
  </table>
</div>

<p align="center">
  <img src="assets/multi_agent_framework.png" width="500px" alt="MATPO Framework">
</p>


<p align="center">
  <em>MATPO allows planner and worker agents to coexist within a single LLM and be trained via RL, achieving an 18.38% relative improvement over single-agent baselines on GAIA-text, FRAMES, and WebWalker-QA.</em>
</p>

## News & Updates

- **[2025-Oct-08]** MATPO-Qwen3-14B checkpoints and rollouts released
- **[2025-Oct-08]** Code and training scripts released
- **[2025-Oct-06]** Arxiv Paper released


## Overview

**MATPO** (Multi-Agent Tool-Integrated Policy Optimization) is a novel reinforcement learning framework that enables training multiple specialized agent roles (planner and worker agents) within a single large language model. 

### The Problem
Current single-agent approaches for multi-turn tool-integrated planning face critical limitations:
- **Context Length Bottleneck**: Tool responses (e.g., web scraping) consume excessive tokens, making long-range planning prohibitive
- **Noisy Tool Responses**: Raw tool responses interfere with the model's attention and planning capabilities

### Our Solution
MATPO introduces a **multi-agent-in-one-model** architecture where:
- A **planner-agent** orchestrates high-level planning and delegates subtasks
- **Worker-agents** handle specific browsing and search tasks with isolated contexts
- Both roles are trained within a **single LLM** using role-specific prompts via reinforcement learning


## Key Features

- **Multi-Agent-in-One-Model**: Train planner and worker agents within a single LLM using role-specific system prompts
- **Principled Credit Assignment**: Extends GRPO with theoretically grounded reward distribution across planner and worker rollouts
- **Easy Integration**: Built on top of [veRL](https://github.com/volcengine/verl), compatible with existing RL training frameworks
- **Robust Training**: More stable learning curves compared to single-agent approaches, especially with noisy tool responses
- **Infrastructure Efficient**: No need for deployment of separate models or additional rollout engines


## MATPO Architecture

MATPO employs a hierarchical multi-agent framework where a single LLM serves multiple roles:

```
User Query → Planner Agent → Subtask 1 → Worker Agent → Result 1
                           → Subtask 2 → Worker Agent → Result 2
                           → ...
                           → Final Answer
```


<p align="center">
  <img src="assets/single_agent.png" width="600px" alt="Single-agent GRPO Framework">
  <img src="assets/multi_agent_RL_rollout.png" width="600px" alt="MATPO Framework">
</p>

<p align="center">
  <em>Comparison between the rollout trajectories between the single-agent GRPO (top) and the multi-agent MATPO (bottom).</em>
</p>


### Multi-Agent Rollout Process

1. **Planner Agent**: 
   - Receives user query with planner-specific system prompt
   - Generates high-level plan and decomposes it into subtasks
   - Delegates subtasks to worker agents
   - Synthesizes worker responses into final answer

2. **Worker Agent**:
   - Receives subtask with worker-specific system prompt
   - Performs multi-turn tool-integrated planning (search, scrape, analyze)
   - Returns summarized result to planner
   - Maintains isolated context to prevent token overflow

3. **Credit Assignment**:
   - Final answer accuracy determines the reward
   - Reward is normalized across all planner-worker rollout groups
   - Gradient flows to both planner actions and worker actions proportionally

 
<p align="center">
  <img src="assets/multi-agent-grpo-implementation.png" width="600px" alt="MATPO Framework">
</p>

<p align="center">
  <em>Visualization of MATPO implementation.</em>
</p>



## Quick Start

Prerequisites:
- Python 3.10 or higher
- CUDA 12.4+ (for GPU support)
- 16 x (8 x 80G-A800) GPUs (for training with Qwen3-14B-base)

Clone the repository.
```bash
git clone https://github.com/mzf666/MATPO.git
cd MATPO
```

For prerequisites installation (CUDA, cuDNN, Apex), we recommend following the [verl prerequisites guide](https://verl.readthedocs.io/en/latest/start/install.html#pre-requisites) which provides detailed instructions for:

- CUDA: Version >= 12.4
- cuDNN: Version >= 9.8.0
- Apex

Setup environment and install dependencies.
```bash
conda create -n matpo python==3.10 -y
conda activate matpo
bash examples/sglang_multiturn/install.sh
```

Setup Node.js for Serper API support. 

MCP (Model Context Protocol) requires Node.js to run MCP servers. Node.js version 18+ is recommended for optimal compatibility with MCP tools.
```bash
target_path=YOUR_TARGET_PATH

# Download Node.js binary (example for Linux x64)
wget https://nodejs.org/dist/v24.2.0/node-v24.2.0-linux-x64.tar.xz

# Extract to your target path
tar -xf node-v24.2.0-linux-x64.tar.xz -C $target_path

# Add to PATH
export NODEJS_HOME=$target_path/node-v24.2.0-linux-x64
export PATH=$NODEJS_HOME/bin:$PATH
export NODE_SHARED=$target_path/node-shared/node_modules
export PATH=$NODE_SHARED/.bin:$PATH

# Verify installation
node --version
npm --version

# Install serper mcp server
mkdir -p $target_path/node-shared
cd $target_path/node-shared
npm init -y
npm install serper-search-scrape-mcp-server
```

Configure the Node.js paths and HTTP / HTTPS proxies (if necessary) in the `examples/sglang_multiturn/launch.sh` script properly.

Download the training and testing datasets to the `data` directory. The prerpocessed datasets can be downloaded [here](https://huggingface.co/datasets/veggiebird/MATPO-data).


Train a Qwen3-14B-base model with MATPO on the MuSiQue dataset and evaluate on the GAIA-text datasets:

```bash
# tested on 16 x (8 x 80G-A800) nodes

export SERPER_API_KEY="YOUR_SERPER_API_KEY" && \
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY" && \
export WANDB_API_KEY="YOUR_WANDB_API_KEY" && \
export SINGLENODE=true && \
export RAY_DEBUG=legacy && \
export HYDRA_FULL_ERROR=1 && \
source YOUR_CONDA_PATH activate matpo && \
cd YOUR_PROJECT_PATH && \
bash examples/sglang_multiturn/launch.sh \
    examples/sglang_multiturn/qwen3-14b_musique_MATPO.sh
```

## Experiments and Results

### Main Results

MATPO consistently outperforms single-agent GRPO baselines across all benchmarks:

| Method | GAIA-text | WebWalkerQA | FRAMES | Relative Average Improvement |
|--------|-----------|-------------|---------|---------------------|
| Single-Agent GRPO | 32.16% | 30.14% | 56.22% | - |
| **MATPO (Ours)** | **42.60%** | **33.00%** | **63.64%** | **+18.38%** |

### Training Configuration

- **Base Model**: Qwen3-14B-base
- **Training Dataset**: Filtered MuSiQue dataset.
- **Training Steps**: 180 steps
- **Rollouts per Query**: 8 (for group normalization)
- **Reward Function**: 0.9 × accuracy + 0.1 × tool_format_reward

### Model Checkpoints and Rollouts


We release the trained Qwen3-14B-base model checkpoints at the 180th training step of both [single-agent GRPO](https://huggingface.co/veggiebird/MATPO-single-agent-14b) and [MATPO](https://huggingface.co/veggiebird/MATPO-14b).

The associated model rollouts across various training steps can be found [here](https://huggingface.co/datasets/veggiebird/MATPO-rollout).


### Key Findings

- **More Stable Training**: MATPO exhibits more stable learning curves and avoids catastrophic performance drops observed in single-agent training

- **Robustness to Noise**: Multi-agent decomposition effectively isolates noisy tool responses, preventing them from interfering with high-level planning

- **Better Credit Assignment**: Principled reward distribution across planner and worker rollouts leads to more effective learning


### Practical Implementation Tips

Based on our experiments, we recommend:

- **Final Summary**: Final summaries from worker agents are critical for clean planner-worker interfaces
- **Query Recap**: Recapping original user query in worker prompt significantly improves performance
- **URL Blocking**: Remember to blocking HuggingFace search results to avoid data leakage

## Citation

If you find MATPO helpful in your research, please consider citing our paper:

```bibtex
@misc{mo2025multiagenttoolintegratedpolicyoptimization,
      title={Multi-Agent Tool-Integrated Policy Optimization}, 
      author={Zhanfeng Mo and Xingxuan Li and Yuntao Chen and Lidong Bing},
      year={2025},
      eprint={2510.04678},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2510.04678}, 
}
```


## Acknowledgments

We would like to thank:

- **VolcEngine** for developing and open-sourcing [veRL](https://github.com/volcengine/verl), the RL training framework that powers MATPO
- **Alibaba Cloud** for the Qwen3 model series
- **Google** for the Serper API that enables web search capabilities
- The authors of **GAIA**, **WebWalkerQA**, **FRAMES**, and **MuSiQue** datasets
- The open-source community for valuable feedback and contributions


## FAQ

<details>
<summary><b>Q: What's the difference between MATPO and traditional multi-agent systems?</b></summary>

MATPO uses a single LLM to play multiple agent roles via different system prompts, rather than deploying separate models. This offers:
- Lower infrastructure complexity
- Better parameter efficiency
- Easier deployment and maintenance
- Compatible with existing RL frameworks
</details>

<details>
<summary><b>Q: Can I use MATPO with models other than Qwen3?</b></summary>

Yes! MATPO is model-agnostic. You can use any decoder-only LLM that supports tool calling and multi-turn conversations. We've tested with Qwen3-14B-base, but models like Llama 3, Mistral, or other reasoning-capable LLMs should work.
</details>

<details>
<summary><b>Q: How many GPUs do I need for training?</b></summary>

For Qwen3-14B-base, we recommend:
- **Training**: 8x A100/A800 GPUs (80GB)
- **Inference**: 1-2x A100/A800 GPUs (40GB/80GB)

</details>

<details>
<summary><b>Q: How does MATPO handle credit assignment?</b></summary>

MATPO extends GRPO with principled credit assignment:
1. The planner's final answer determines the accuracy reward
2. This reward is normalized across all rollouts in a group
3. Gradients flow proportionally to both planner and worker actions
4. Worker agents receive the same advantage value as their parent planner rollout

See our paper for more details.
</details>

<details>
<summary><b>Q: Can I use MATPO for tasks other than web search?</b></summary>

Absolutely! While our paper focuses on web search, MATPO's framework is general. You can extend it to:
- Code generation with execution feedback
- Scientific reasoning with calculator tools
- Data analysis with pandas/SQL tools
- Any multi-turn task with verifiable rewards
</details>

<details>
<summary><b>Q: How stable is MATPO training compared to single-agent RL?</b></summary>

MATPO is significantly more stable. Our experiments show:
- Single-agent GRPO often suffers catastrophic drops after step 120
- MATPO maintains steady improvement throughout training
- Multi-agent structure isolates noisy tool responses, preventing interference

See Figure 4 in our paper for training curves.
</details>

<details>
<summary><b>Q: Do I need to block HuggingFace URLs during training?</b></summary>

For research integrity, yes - especially if your evaluation benchmarks are hosted on HuggingFace. This prevents models from "cheating" by finding ground-truth answers online. 

For production systems with no data leakage concerns, this is optional.
</details>

-----

<p align="center">
  <strong>Star ⭐ this repository if you find it helpful!</strong>
</p>