Overview
Background
Agent developers typically work with open-source models, using fine-tuning methods such as SFT (Supervised Fine-Tuning) and RFT (Reinforcement Fine-Tuning) to balance Agent cost, performance, and effectiveness in specific scenarios. This extension helps Agent developers conveniently and continuously leverage real online interaction data to optimize models and Agents, establishing a complete data loop from production to training systems, enabling “Agents that get smarter with use” through online training.Online Training
Online Training is a training paradigm that directly utilizes real user interaction data in production or near-production environments to continuously optimize Agent behavior. Unlike traditional Offline Training—which involves collecting historical logs, building static datasets, and training models in isolated environments—online training emphasizes deep coupling with real toolchains and user behavior, achieving a “run, learn, and optimize” closed loop.Key Characteristics
1. Reuse Production Toolchains Agents can directly invoke real tools deployed in production (such as APIs, databases, business systems, etc.) during training, without the need to build simulation environments or write mock tools specifically for training. Advantage: Avoids “training-deployment deviation” (Reality Gap) caused by inconsistencies between mock tools and actual production behavior; significantly reduces integration costs and improves the authenticity and effectiveness of training data. 2. Support Incremental Learning with Fast Cold Start Does not depend on complete historical datasets; Agents can start learning from a small number or even single real interactions, suitable for newly launched Agents or long-tail scenarios, significantly lowering the startup threshold.Constraints
Safe Support for Read-Only Tools by Default Since the training process may involve multiple attempts or replays, directly invoking write-operation tools (such as “place order”, “deduct payment”, “send message”) may cause repeated execution, leading to business risks. Therefore, write operations require additional safeguards through sandbox mechanisms, idempotent design, or manual review. Users need to ensure the safety of the tools used by their Agents. Multi-Turn Interaction Scenarios Require Explicit Modeling Current mainstream training frameworks natively support single-turn interactions between users and Agents (user asks → Agent responds). In this interaction, Agents can have multiple interactions with LLMs. For multi-turn dialogues or complex task flows (such as book flight → select seat → payment), developers need to design additional state management, user behavior simulation, or trajectory sampling strategies.Architecture
This solution uses Trinity-RFT as the training store. Trinity-RFT is a general-purpose, flexible, and user-friendly Large Language Model (LLM) Reinforcement Fine-Tuning (RFT) framework. Github: https://github.com/agentscope-ai/Trinity-RFT Version requirement: v0.4.0 and above The online training mode decouples three components: Agent Runner, inference service (Explorer), and training service (Trainer):- Agent Runner is responsible for running user Agent applications, processing user requests, and interacting with Explorer through RESTful APIs. This component is implemented, deployed, and managed by users themselves, with no constraints from Trinity-RFT.
- Explorer serves as the inference service, processing requests from Agent Runner, recording trainable data (Experience), and storing data in the database. Explorer provides the following RESTful interfaces for Agent Runner to call:
- chat: Compatible with standard OpenAI chat completions interface, handling user dialogue requests.
- feedback: Receives user feedback on Agent responses.
- commit: Notifies Explorer to submit data to Trainer.
- Trainer serves as the training service, retrieving new training data from the database, training the model, and storing updated model checkpoints in a shared file system for Explorer to use.
Core Features
This solution provides end-to-end online training support natively in AgentScope Java, aiming to establish a complete loop from production to model optimization with the following goals:- Leverage Real Online Interaction Data: Agent developers can directly train using real request invocations and tool states from production Agent environments
- Minimal Setup Experience: Agent developers only need to provide key training configurations (such as reward functions in RL) to automatically complete execution, data collection, and the entire training process
- Unified Training Interface Covering Mainstream Optimization Methods: Native support for supervised fine-tuning (SFT), knowledge distillation, and task-specific reinforcement learning algorithms (such as PPO), without needing to switch frameworks or depend on other ecosystems
Quick Start
Maven Dependency
Define Request Selection Logic
Request selection logic is used to filter out requests that need to be used for training.Built-in Strategies:
SamplingRateStrategy - Random sampling. All online requests are filtered by percentage.Custom Strategy
You can implement the TrainingSelectionStrategy interface by referring to SamplingRateStrategy or ExplicitMarkingStrategy, and customize your request filtering logic in the shouldSelect method according to your business needs.Define Reward Function
You can implement the RewardCalculator interface and customize your reward calculation logic in the calculate method according to your business needs. Generally, rewards are decimals between 0 and 1.Start Training Backend
Install Trinity
Before installation, ensure your system meets the following requirements. Source installation is recommended:- Python: Version 3.10 to 3.12 (inclusive)
- CUDA: Version >= 12.8
- GPU: At least 2 GPUs