Airsc is free for everyone. If it helps you, support it with $2–$20.

Support
AgentSafeAgent workflow & memoryAdvanced

PARL

The-Swarm-Corporation · The-Swarm-Corporation/PARL

This implements a Parallel-Agent Reinforcement Learning (PARL) paradigm for training AI models to decompose tasks into parallel subtasks and coordinate multiple agents.

PARL (Parallel-Agent Reinforcement Learning) is a training paradigm that teaches models to decompose complex tasks into parallel subtasks and coordinate multiple agents simultaneously.

55 stars4License: Apache-2.0Updated 7 months ago0 opens

Preview

▍

What you can do with it

  • Train AI agents to efficiently decompose complex tasks into parallel subtasks.
  • Develop multi-agent systems that coordinate up to 100 sub-agents simultaneously.
  • Implement staged reward shaping to optimize agent performance in parallel execution.

Safety check

Safe

No risky patterns found in the files we scanned.

Automated scan of the repo files. Always review code you run.

From the README

PARL: Parallel-Agent Reinforcement Learning

⚠️ Disclaimer: This is an open-source community implementation of the PARL (Parallel-Agent Reinforcement Learning) technique based on the Kimi K2.5 technical report. This is NOT an official implementation from Kimi AI or any affiliated organization. This project is maintained independently by The Swarm Corporation and the open-source community.

Open-source implementation of PARL (Parallel-Agent Reinforcement Learning), a novel training paradigm that enables AI models to decompose complex tasks into parallel subtasks and coordinate multiple agents simultaneously.

Overview

PARL is a training methodology that addresses the critical challenge of serial collapse in multi-agent systems, where models default to sequential execution despite having parallel computational capacity. By implementing staged reward shaping and a latency-oriented evaluation metric, PARL trains models to efficiently orchestrate up to 100 sub-agents across 1,500+ coordinated steps.

Key Features

  • Staged Reward Shaping: Dynamic reward annealing that encourages parallelism early in training and gradually shifts focus toward task success
  • Instantiation Reward: Incentivizes subagent creation and concurrent execution
  • Critical Steps Metric: Latency-oriented evaluation inspired by parallel computation's critical path concept
  • Differentiable Components: Fully compatible with gradient-based optimization
  • Orchestrator-Subagent Architecture: Trainable coordinator with frozen execution agents

Architecture

┌─────────────────────────────────────────────┐
│         Orchestrator Agent                  │
│  (Trainable Central Coordinator)            │
│  - Decomposes tasks into subtasks           │
│  - Manages parallel execution               │
│  - Coordinates subagent workflows           │
└──────────────┬──────────────────────────────┘
               │
               ├──────────┬──────────┬─────────┐
               │          │          │         │
          ┌────▼───┐ ┌───▼────┐ ┌──▼────┐  ┌─▼──────┐
          │Subagent│ │Subagent│ │Subagent│  │Subagent│
          │   1    │ │   2    │ │   3    │  │  ...N  │
          └────────┘ └────────┘ └────────┘  └────────┘
           (Frozen)   (Frozen)   (Frozen)    (Frozen)

Reward Function

PARL implements the three-term reward from the Kimi K2.5 technical report:

r_PARL(x,y) = λ1·r_parallel + λ2·r_finish + r_perf(x,y)

Where:

  • r_parallel (instantiation reward): Incentivizes subagent instantiation; mitigates serial collapse.
  • r_finish (sub-agent finish rate): Rewards completed subtasks; prevents spurious parallelism (spawning many subagents without meaningful decomposition).
  • r_perf(x,y) (task-level outcome): Evaluates overall success and quality of solution y for task x.
  • λ1 and λ2: Annealed to zero over training so the final policy optimizes r_perf.

Critical Steps Metric

Per the paper, total critical steps are defined as:

CriticalSteps = Σ_t (S_main^(t) + max_i S_sub,i^(t))
  • S_main^(t): Steps taken by the main agent in stage t (typically 1).
  • S_sub,i^(t): Steps taken by the i-th subagent in that parallel group.
  • The duration of stage t is governed by the longest-running subagent in that cohort.

This metric captures the true execution time (critical path) and incentivizes effective parallelization.

Installation

pip3 install -U open-parl

Quick Start

import torch
from parl import PARLReward, CriticalStepsMetric

# Initialize the reward function
reward_fn = PARLReward(
    lambda_init=0.1,
    lambda_final=0.0,
    total_training_steps=10000,
    device='cuda' if torch.cuda.is_available() else 'cpu'
)

# Prepare episode data
num_subagents = torch.tensor([25, 30, 40])
completed_subtasks = torch.tensor([20, 28, 35])  # Completed subtasks
assigned_subtasks = torch.tensor([25, 30, 40])   # Assigned subtasks
trajectory_features = torch.randn(3, 64)
success = torch.tensor([1.0, 1.0, 0.0])
training_step = 5000

# Compute rewards (completed_subtasks/assigned_subtasks optional; default r_finish=1)
rewards = reward_fn.compute_full_reward(
    num_subagents=num_subagents,
    trajectory_features=trajectory_features,
    success=success,
    training_step=training_step,
    max_subagents=100,
    completed_subtasks=completed_subtasks,
    assigned_subtasks=assigned_subtasks,
)

print(f"Total Reward: {rewards['total_reward']}")
print(f"λ1 (r_parallel): {rewards['lambda1']:.4f}, λ2 (r_finish): {rewards['lambda2']:.4f}")
print(f"Instantiation: {rewards['instantiation_component']}")
print(f"Finish: {rewards['finish_component']}, Task: {rewards['task_component']}")

# Evaluate using Critical Steps metric (S_main typically 1 per stage)
critical_steps_metric = CriticalStepsMetric()

main_steps = torch.ones(3, 5)  # Main agent steps per stage (typically 1)
sub_steps = torch.rand(3, 5, 10)

critical_steps = critical_steps_metric(main_steps, sub_steps)
print(f"Critical Steps: {critical_steps}")

Examples

ExampleFileDescriptionRequirements
Basic Usagebasic_usage.pyCore PARL reward function and Critical Steps metric without external modelsopen-parl only
Quick Start (HF)quickstart_hf.pyMinimal integration with Hugging Face GLM-4.7-Flash modeltransformers, torch, accelerate
Full HF Integrationhuggingface_integration.pyComplete orchestrator class with training loop, batching, and reward analysistransformers, torch, accelerate

API Reference

For detailed API documentation, see docs/API.md.

Experiments

Run the example training simulation:

python -m parl.main

This will demonstrate reward evolution across training stages and critical steps computation.

Testing

Run the comprehensive test suite:

# Using pytest
pytest tests/ -v

# 
View source on GitHub