add-workflow
Guide for adding a new RolloutWorkflow to AReaL. Use when user wants to create a new workflow.
Best use case
add-workflow is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Guide for adding a new RolloutWorkflow to AReaL. Use when user wants to create a new workflow.
Teams using add-workflow should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/add-workflow/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How add-workflow Compares
| Feature / Agent | add-workflow | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Guide for adding a new RolloutWorkflow to AReaL. Use when user wants to create a new workflow.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Add Workflow
Add a new RolloutWorkflow implementation to AReaL.
## When to Use
This skill is triggered when:
- User asks "how do I add a workflow?"
- User wants to create a new RolloutWorkflow
- User mentions implementing a custom rollout
## Prerequisites
Before starting, ensure you understand:
- The workflow's purpose and requirements
- Input/output data format
- Reward function to use
## Step-by-Step Guide
### Step 1: Create Workflow File
Create `areal/workflow/<name>.py`:
```python
import uuid
from typing import Any, Callable
import torch
from areal.api.cli_args import GenerationHyperparameters
from areal.api.engine_api import InferenceEngine
from areal.api.io_struct import ModelRequest, ModelResponse
from areal.api.reward_api import AsyncRewardWrapper
from areal.api.workflow_api import RolloutWorkflow
from areal.utils import logging
logger = logging.getLogger("MyWorkflow")
class MyWorkflow(RolloutWorkflow):
"""Description of your workflow."""
def __init__(
self,
gconfig: GenerationHyperparameters,
tokenizer,
reward_fn: Callable,
):
self.gconfig = gconfig.new_with_stop_and_pad_token_ids(tokenizer)
self.tokenizer = tokenizer
self.async_reward_fn = AsyncRewardWrapper(reward_fn)
async def arun_episode(
self,
engine: InferenceEngine,
data: dict[str, Any],
) -> dict[str, torch.Tensor]:
"""Run a single episode. MUST be async and non-blocking."""
# 1. Prepare input_ids from data
input_ids = self.tokenizer.apply_chat_template(
data["messages"],
tokenize=True,
add_generation_prompt=True,
)
# 2. Build ModelRequest
req = ModelRequest(
rid=uuid.uuid4().hex,
input_ids=list(input_ids),
gconfig=self.gconfig.new(n_samples=1),
tokenizer=self.tokenizer,
)
# 3. Generate completion (async)
resp: ModelResponse = await engine.agenerate(req)
# 4. Compute reward (async)
prompt_str = self.tokenizer.decode(input_ids)
completion_str = self.tokenizer.decode(resp.output_tokens)
reward = await self.async_reward_fn(
prompt_str,
completion_str,
resp.input_tokens,
resp.output_tokens,
**data,
)
# 5. Return results in expected format
return {
"input_ids": torch.tensor(resp.input_tokens),
"output_ids": torch.tensor(resp.output_tokens),
"reward": torch.tensor(reward),
}
```
### Step 2: Register in __init__.py
Add to `areal/workflow/__init__.py`:
```python
from areal.workflow.<name> import MyWorkflow
__all__ = [
# ... existing exports
"MyWorkflow",
]
```
### Step 3: Update Entry Script
Update your training script to use the new workflow:
```python
trainer.train(
workflow="areal.workflow.<name>.MyWorkflow",
# ... other args
)
```
### Step 4: Add Tests
Create `areal/tests/test_<name>_workflow.py`:
```python
import pytest
from areal.workflow.<name> import MyWorkflow
@pytest.mark.asyncio
async def test_workflow_basic():
# Test basic functionality
pass
```
## Reference Implementations
| Workflow | File | Description |
| ------------------ | ------------------------------- | -------------------------- |
| MultiTurnWorkflow | `areal/workflow/multi_turn.py` | Multi-turn conversation |
| RLVRWorkflow | `areal/workflow/rlvr.py` | RL with verifiable rewards |
| VisionRLVRWorkflow | `areal/workflow/vision_rlvr.py` | Vision + RLVR |
## Key Requirements
1. **Async**: `arun_episode` must be `async def` and non-blocking
1. **No sync I/O**: Use `aiofiles` for file operations
1. **Wrap rewards**: Use `AsyncRewardWrapper` for reward functions
1. **Tensor format**: Output tensors should be `[batch, seq_len, ...]`
1. **Use helpers**: `concat_padded_tensors` for combining outputs
## Common Mistakes
- ❌ Using `open()` instead of `aiofiles.open()`
- ❌ Forgetting to `await` async calls
- ❌ Not wrapping reward function with `AsyncRewardWrapper`
- ❌ Wrong tensor shape conventions
______________________________________________________________________
<!--
================================================================================
MAINTAINER GUIDE
================================================================================
Location: .claude/skills/add-workflow/SKILL.md
Invocation: /add-workflow <name>
## Purpose
Step-by-step guide for adding new RolloutWorkflow implementations.
## How to Update
### When Workflow API Changes
1. Update the code template in Step 1
2. Update the required imports
3. Update the method signature if changed
### When New Patterns Emerge
1. Add to "Reference Implementations" table
2. Update "Key Requirements" if new requirements added
================================================================================
-->Related Skills
builder-workflow
Phase-level implementation workflow for builder agents. Handles loading project rules, reading phase files, finding references, invoking domain skills, implementing all steps, and running verification (tests + typecheck). Invoke this skill as your first action — not user-invocable.
aero-workflow-automation
Automate Aero Workflow tasks via Rube MCP (Composio). Always search tools first for current schemas.
act-workflow-syntax
Use when creating or modifying GitHub Actions workflow files. Provides guidance on workflow syntax, triggers, jobs, steps, and expressions for creating valid GitHub Actions workflows that can be tested locally with act.
1k-git-workflow
Git workflow and conventions for OneKey development. Use when creating branches, committing code, or creating PRs. Triggers on git, branch, commit, PR, pull request, merge, workflow.
testing-workflow
Meta-skill that orchestrates comprehensive testing across a project by coordinating testing-patterns, e2e-testing, and testing agents. Use when setting up testing for a new project, improving coverage for an existing project, establishing a testing strategy, or verifying quality before a release.
security-workflow
Use when creating backlog tasks from security findings, integrating security scans into workflow states, or managing security remediation tracking. Invoked for security workflow integration and task automation.
moai-workflow-testing
AI-powered enterprise web application testing orchestrator with Context7 integration, intelligent test generation, visual regression testing, cross-browser coordination, and automated QA workflows for modern web applications
auditor-workflow
Group-level implementation audit workflow for auditor agents. Handles loading project rules, reading connected phases, reviewing code reviews, checking deferred items, cross-phase impact analysis, verification, and structured reporting to the orchestrator. Invoke this skill as your first action — not user-invocable.
workflows-work
Execute work plans efficiently while maintaining quality and finishing features
sc-workflow
Generate structured implementation workflows from PRDs and feature requirements with expert guidance. Use when planning feature implementation, breaking down PRDs, or creating development roadmaps.
r2r-workflow
Explain the Research-to-Roadmap (r2r) workflow visually. Shows the 6-phase pipeline JD built for transforming R&D projects into production roadmaps.
feature-dev-workflow
Complete end-to-end feature development workflow from issue tracking through PR delivery. Use for implementing features, building new functionality, and adding capabilities. Includes requirements discovery, architecture planning, implementation, testing, code review, design audit, and comprehensive validation.