How baidu-baige/loongsage works
LoongSage is a post-training reinforcement-learning framework for LLMs. Its main workflow orchestrates inference rollouts, captures agent trajectories, scores and prepares training data, then updates the policy and synchronizes weights back to inference. The graph preserves major documented capabilities—online distillation, multimodal handling, pluggable algorithms and rewards, asynchronous sampling, and flexible resources—alongside the principal path. Relationship evidence is limited to the README and the supplied source index/excerpts; unsampled subsystems are represented at their known directory paths without asserting unverified internal calls.
Main entry points: agentflow AgentFlow service · megatron_actor_worker.py Policy worker · trainer.py Training orchestration · parser.py Conversation parsing
Components 23
Orchestration
- Training orchestration
coda/controller/trainer.py - Rollout management
coda/controller/rollout_manager.py - Training management
coda/controller/train_manager.py - Teacher management
coda/controller/teacher_manager.py
Agents and data
- AgentFlow service
coda/agentflow - Request routing
coda/agentflow/router/router.py - Conversation parsing
coda/agentflow/router/parser.py - Agent adapters
coda/agentflow/agent - Execution sandboxes
coda/agentflow/sandbox - Tokenization
coda/agentflow/tokenizer_manager.py - Trajectory storage
coda/agentflow/trajectory_store.py - Data preparation
coda/data_factory - Multimodal processing
coda/agentflow/multimodal.py
Learning
- Reward functions
coda/reward - RL algorithms
coda/algorithms - Policy worker
coda/backends/megatron/megatron_actor_worker.py - Training worker base
coda/backends/megatron/megatron_train_worker.py - Distillation teachers
coda/backends/megatron/megatron_teacher_worker.py - Distillation policies
coda/algorithms/kl_policy.py
Distributed runtime
- SGLang inference
coda/backends/sglang/engine.py - Weight transfer
coda/transfer_mesh/channel.py - Resource placement
coda/resource_scheduler/resource_scheduler.py
Other components
- Training operator
Connections 26
- Training operator → Training orchestration: configures run
README.md - Training orchestration → Rollout management: orchestrates sampling
README.md - Training orchestration → Training management: orchestrates training
README.md - Training orchestration → Teacher management: orchestrates teachers
README.md - Rollout management → SGLang inference: manages engines
coda/controller/rollout_manager.py - SGLang inference → AgentFlow service: serves inference
README.md - AgentFlow service → Request routing: routes requests
README.md - Request routing → Conversation parsing: parses exchanges
- AgentFlow service → Agent adapters: hosts agents
README.md - AgentFlow service → Execution sandboxes: manages lifecycles
README.md - Conversation parsing → Tokenization: uses tokenizer
coda/agentflow/router/parser.py - Conversation parsing → Trajectory storage: records trajectories
coda/agentflow/router/parser.py - AgentFlow service → Trajectory storage: stores trajectories
README.md - Trajectory storage → Data preparation: supplies samples
coda/data_factory/data_source.py - Data preparation → Policy worker: feeds training batches
- Policy worker → Training worker base: extends worker
coda/backends/megatron/megatron_actor_worker.py - Training management → Training worker base: coordinates training
- Policy worker → RL algorithms: computes policy updates
coda/backends/megatron/megatron_actor_worker.py - Policy worker → Weight transfer: sends weights
coda/backends/megatron/megatron_actor_worker.py - Weight transfer → SGLang inference: updates inference weights
- Teacher management → Distillation teachers: manages teachers
coda/controller/teacher_manager.py - Distillation teachers → Distillation policies: provides teacher outputs
coda/backends/megatron/megatron_teacher_worker.py - Policy worker → Distillation policies: builds KL policies
coda/backends/megatron/megatron_actor_worker.py - Reward functions → AgentFlow service: scores trajectories
- Resource placement → Rollout management: places resources
- Multimodal processing → Tokenization: processes modalities
coda/agentflow/tokenizer_manager.py