feat: Multi-turn tool calling on BFCLv3 dataset
This PR implements an end-to-end example for training a model on multi-turn tool calling using GRPO with the BFCLv3 dataset. The example leverages preprocessed data uploaded to HuggingFace, where preprocessing includes adding tool descriptions and formatting. It also provides evaluation scripts to compare trained and untrained models, along with a README that documents the example in detail, and results on Qwen 2.5 3B
Summary by CodeRabbit
- New Features
- Introduced multi-turn tool-calling environment with reward-based rollouts.
- Added support for BFCL v3 multi-turn datasets for training and evaluation.
- Provided new built-in tools (filesystem, math, messaging, ticketing, trading, social, vehicle control).
- Enabled multi-turn evaluation and GRPO training via new scripts and configs.
- Improved logging with serialized environment metadata.
- Documentation
- Added a comprehensive guide for multi-turn tool calling; linked from the guides index.
- Chores
- Included a new dependency for JSON Lines data processing.
Adds BFCL v3 multi-turn tool-calling capability: new environment, tool APIs, datasets, processors, configs, training and eval scripts. Extends rollout/eval control flow for multi-turn episodes, adds logging of env metadata, and updates distributed registry. Includes documentation and dependency addition. 🎯 5 (Critical) | ⏱️ ~120+ minutes📝 Walkthrough
Walkthrough
Changes
Cohort / File(s)
Summary
Documentation
docs/guides/multi_turn_bfcl.md, docs/index.mdNew guide for multi-turn tool calling with BFCL v3; index updated to link the guide.
Configs: GRPO and Eval
examples/configs/grpo_bfclv3.yaml, examples/configs/evals/bfcl_eval.yaml, examples/configs/evals/eval.yamlNew GRPO BFCLv3 training config and BFCL eval config; minor no-op edit to base eval config.
Run scripts
examples/run_grpo_bfclv3.py, examples/run_eval.pyNew GRPO training script for BFCL multiturn; eval script now conditionally uses MultiTurnToolEnvironment and passes tokenizer; function signatures updated accordingly.
Algorithms: GRPO logging
nemo_rl/algorithms/grpo.pyAdds JSON serialization of per-sample extra_env_info into log_data.metadata.
Eval flow
nemo_rl/evals/eval.pyAdds multi-turn evaluation branch, tokenizer plumbing, rollout integration, and data collection for rewards and logs.
Rollouts
nemo_rl/experience/rollouts.pyAdds BFCL helper to append next user question during multi-turn rollouts; integrates into continuation path.
Distributed registry
nemo_rl/distributed/ray_actor_environment_registry.pyRegisters
MultiTurnToolEnvironment to system Python executable.
Environment: Multi-turn tools
nemo_rl/environments/multi_turn_tool_environment.pyNew multi-turn tool environment with turn parsing, tool execution, rewards, and Ray actor support.
Tool APIs
nemo_rl/environments/tools/gorilla_file_system.py, .../math_api.py, .../message_api.py, .../ticket_api.py, .../trading_bot.py, .../twitter_api.py, .../vehicle_control.pyAdds multiple simulated tool APIs with stateful operations;
vehicle_control.py updates method return signatures to structured dicts.
Datasets: Eval
nemo_rl/data/datasets/eval_datasets/__init__.py, .../bfclv3.pyAdds
BFCLDataset and wiring for eval dataset loading from HF Hub.
Datasets: Response
nemo_rl/data/datasets/response_datasets/__init__.py, .../bfcl_multiturn.pyAdds
BFCLMultiturnDataset loading train/val JSONL from HF Hub with formatted output.
Processors
nemo_rl/data/processors.pyAdds BFCL single-turn and multi-turn processors with chat templating, tokenization, and env metadata passthrough.
Data config
nemo_rl/data/__init__.pyAdds optional
filter_long_samples to DataConfig.
Project dependencies
pyproject.tomlAdds
jsonlines dependency.Sequence Diagram(s)
sequenceDiagram
autonumber
participant User
participant RunScript as run_grpo_bfclv3.py
participant Ray as Ray Cluster
participant Policy as GRPO Policy
participant Env as MultiTurnToolEnvironment
participant Tools as ToolManager/APIs
User->>RunScript: Launch with grpo_bfclv3.yaml
RunScript->>Ray: init()
RunScript->>Policy: setup(model, tokenizer, gen_cfg)
RunScript->>Env: create actors (bfcl_multiturn, max_turns)
loop Training Steps
Policy->>Env: rollout request (batch)
Env->>Tools: load scenario (model/GT instances)
loop per turn (<= max_turns)
Policy->>Env: assistant response
Env->>Env: parse <tool> call, validate
Env->>Tools: execute model and GT calls
Env-->>Policy: observation, reward fragment, metadata
Policy->>Policy: GRPO update (rewards, baseline)
end
Policy->>RunScript: log rewards + metadata (JSON)
end
sequenceDiagram
autonumber
participant User
participant EvalScript as run_eval.py
participant Loader as load_response_dataset
participant Dataloader
participant VLLM as vLLM Generation
participant Env as MultiTurnToolEnvironment
User->>EvalScript: Run with bfcl_eval.yaml
EvalScript->>Loader: load_response_dataset("bfcl_multiturn")
Loader-->>EvalScript: dataset (train/val)
EvalScript->>Env: create if bfcl_multiturn.enable
EvalScript->>Dataloader: build with tokenizer
alt Multi-turn enabled
loop Batches
EvalScript->>VLLM: generate turns (rollout)
VLLM-->>Env: assistant messages
Env-->>EvalScript: rewards, logs, extra_env_info
end
else Single-turn
EvalScript->>VLLM: generate once
end
EvalScript-->>User: prompts, responses, rewards
Estimated code review effort
Possibly related PRs
Suggested labels
documentation, r0.4.0Suggested reviewers
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Test Results For Major Changes | ⚠️ Warning | The PR introduces a large new feature set, including multi-turn tool environments, datasets, processors, and training scripts, which clearly qualifies as a major change. However, neither the PR description nor the linked documentation provide concrete testing or evaluation results—there are no logs, metrics summaries, or performance comparisons demonstrating successful runs or guarding against regressions. Because the required testing information is missing for such a substantial update, the custom check fails. | Please update the PR description with the relevant validation details, such as commands executed, logs, metrics, or evaluation results (especially any convergence or performance figures), so reviewers can confirm the new functionality has been tested. Once those results are documented, this check can pass. |
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | No functions found in the changes. Docstring coverage check skipped. |
| Title Check | ✅ Passed | The title succinctly captures the core feature addition by indicating support for multi-turn tool calling on the BFCLv3 dataset, matching the pull request’s primary objective. It is concise, descriptive, and free of extraneous details or vague terminology. The use of the “feat:” prefix follows conventional commit style without introducing noise. Team members scanning the history will immediately understand the main enhancement delivered by this changeset. |
✨ Finishing touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Thank you for your hard work on this. I really appreciate the effort you put into it. Would you please put some more test result in PR docs?