跳到正文
cccskills
免费在 GitHub 公开

multiturn-rl

Set up and run multi-turn RL training for interactive environments (terminal tasks, tool use, search/RAG, games) using the Tinker API. Use when the user wants multi-turn RL, agentic training, tool-use RL, or interactive environment training.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md6.2 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Multi-Turn RL Training

Help the user set up RL training for multi-turn interactive environments using the Tinker API.

Step 1: Understand the request

Ask the user (if not already specified):

  • Model: Which model to train (e.g., moonshotai/Kimi-K2-Thinking, Qwen/Qwen3-8B)
  • Environment type:
    • Terminal/sandbox tasks: Model executes shell commands (Harbor)
    • Search/RAG: Model uses retrieval tools (Search-R1)
    • Multiplayer games: Two models compete (TicTacToe, Twenty Questions, Guess Number)
    • Custom multi-turn: User-defined interactive environment
  • Turn structure: Max turns, tool outputs, observation handling

Step 2: Reference existing recipes

Read these files for patterns:

  • tinker_cookbook/recipes/harbor_rl/train.py — Terminal task RL with sandbox execution
  • tinker_cookbook/recipes/harbor_rl/harbor_env.py — HarborDatasetBuilder, sandbox factory
  • tinker_cookbook/recipes/search_tool/train.py — Search-R1 with Chroma vector DB
  • tinker_cookbook/recipes/multiplayer_rl/text_arena/train.py — Two-player games
  • tinker_cookbook/recipes/multiplayer_rl/twenty_questions/train.py — Twenty Questions
  • tinker_cookbook/recipes/multiplayer_rl/guess_number/train.py — Guess the Number
  • tinker_cookbook/rl/message_env.py — Message-based environment interface
  • docs/rl/sequence-extension.mdx — Multi-turn RL and KV-cache
  • docs/rl/rl-envs.mdx — Custom environments

Step 3: Configure the environment

Harbor (Terminal Tasks)

Interactive sandbox where model runs shell commands and gets outputs:

from tinker_cookbook.recipes.harbor_rl.harbor_env import HarborDatasetBuilder, HarborTask

dataset_builder = HarborDatasetBuilder(
    tasks=tasks,                    # List of HarborTask objects
    batch_size=8,                   # groups_per_batch
    group_size=4,                   # rollouts per task
    model_name=model_name,
    renderer_name=renderer_name,
    max_turns=10,                   # max interaction turns
    sandbox_timeout=3600,           # sandbox lifetime (seconds)
    command_timeout=120,            # per-command timeout
    grader_timeout=60,              # grading timeout
)

Search/RAG (Search-R1)

Model queries a vector database during generation:

See recipes/search_tool/train.py for Chroma integration and streaming minibatch config.

Multiplayer Games

Two models play against each other:

See recipes/multiplayer_rl/text_arena/train.py for the competitive RL pattern.

Key Multi-Turn Parameters

  • max_turns: Maximum number of interaction turns
  • max_tokens: Max tokens per generation step
  • kl_penalty_coef: KL penalty (often 0.0 for multi-turn to allow exploration)
  • max_steps_off_policy: Enable async rollouts for expensive environments

Async Rollouts

Multi-turn envs are slow due to tool execution. Use async config:

config = Config(
    ...
    async_config=AsyncConfig(
        max_steps_off_policy=cli_config.max_steps_off_policy,
        groups_per_batch=cli_config.groups_per_batch,
    ) if cli_config.max_steps_off_policy is not None else None,
)

Step 4: Write the training script

Follow the Harbor pattern:

import asyncio
import chz
from tinker_cookbook import cli_utils, model_info
from tinker_cookbook.rl.train import AsyncConfig, Config, main

@chz.chz
class CLIConfig:
    model_name: str = "moonshotai/Kimi-K2-Thinking"
    lora_rank: int = 32
    max_tokens: int = 8192
    max_turns: int = 10
    group_size: int = 4
    groups_per_batch: int = 8
    learning_rate: float = 1e-5
    kl_penalty_coef: float = 0.0
    max_steps_off_policy: int | None = None

async def cli_main(cli_config: CLIConfig):
    renderer_name = model_info.get_recommended_renderer_name(cli_config.model_name)

    dataset_builder = ...  # Your multi-turn dataset builder

    config = Config(
        learning_rate=cli_config.learning_rate,
        dataset_builder=dataset_builder,
        model_name=cli_config.model_name,
        lora_rank=cli_config.lora_rank,
        max_tokens=cli_config.max_tokens,
        kl_penalty_coef=cli_config.kl_penalty_coef,
        log_path="/tmp/tinker-examples/multiturn/my_run",
        async_config=AsyncConfig(
            max_steps_off_policy=cli_config.max_steps_off_policy,
            groups_per_batch=cli_config.groups_per_batch,
        ) if cli_config.max_steps_off_policy is not None else None,
    )

    await main(config)

Step 5: Run

# Harbor terminal RL
python -m tinker_cookbook.recipes.harbor_rl.train

# Search-R1
python -m tinker_cookbook.recipes.search_tool.train

# Multiplayer games
python -m tinker_cookbook.recipes.multiplayer_rl.text_arena.train

Step 6: Add tests

If you created a new multi-turn recipe, add a smoke test:

# tests/recipes/test_recipe_<name>.py
import pytest
from tests.helpers import run_recipe

@pytest.mark.integration
def test_<recipe_name>():
    run_recipe(
        "tinker_cookbook.recipes.<recipe_name>.train",
        ["behavior_if_log_dir_exists=delete", "groups_per_batch=4", "group_size=2"],
    )

run_recipe() automatically passes max_steps=2 so the recipe runs 2 training steps and exits. See tests/recipes/test_recipe_text_arena.py and tests/recipes/test_recipe_twenty_questions.py for existing multi-turn examples. For environment-specific logic (sandbox setup, tool parsing), add unit tests as *_test.py next to the source code.

Common pitfalls

  • Multi-turn envs are expensive — start with small groups_per_batch (4-8)
  • Use max_steps_off_policy for async rollouts when env execution is slow
  • Env objects are single-use — the builder creates fresh envs each batch
  • Sandbox timeouts need to be generous enough for complex tasks
  • KV-cache (sequence extension) is key for multi-turn efficiency — see docs/rl/sequence-extension.mdx
  • kl_penalty_coef=0.0 is common for multi-turn since you want the model to explore tool use

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Guide for checkpointing — saving, loading, and resuming training with CheckpointRecord. Use when the user asks about saving weights, resuming training, checkpoint management, or the checkpoint lifecycle.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

ci

免费

Guide for testing conventions and CI pipelines — unit tests, integration smoke tests, pytest markers, and GitHub Actions workflows. Use when the user asks about testing, CI, running tests, or adding tests for a recipe.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

Guide for using completers — TokenCompleter and MessageCompleter for text generation during RL rollouts and evaluation. Use when the user asks about generating text, completing messages, or using completers in RL environments.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

Guide for contributing to the tinker-cookbook repo — development setup, code style, type checking, PR process, and design conventions. Use when the user asks about how to contribute, set up the dev environment, code style, or project conventions.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

datasets

免费

Guide for dataset construction — SupervisedDatasetBuilder, RLDatasetBuilder, ChatDatasetBuilder, and custom dataset creation from JSONL, HuggingFace, or conversation data. Use when the user asks about datasets, data loading, data preparation, or custom data formats.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

Set up and run knowledge distillation (on-policy, off-policy, or multi-teacher) from a teacher model to a student model using the Tinker API. Use when the user wants to distill knowledge, compress models, or train a student from a teacher.

中文简介正在准备中。当前显示原文说明。

uiuc-kang-lab/rlvr_generalization_bounds52026年5月13日 更新

查看 uiuc-kang-lab 的全部技能

报告此技能的问题