跳转至

RLVR 深入:Search & Tool Use 方向

更新日期:2026-04-15


一、Tool Use 是 RLVR 的新赛道

数学和代码的 RLVR 已经相对成熟,2025-2026 的前沿在"让模型学会使用工具"。Tool Use 的验证器:工具调用结果是否达成目标。

flowchart LR
    rl_math["数学 RLVR<br/>(2024 R1)"]
    rl_code["代码 RLVR"]
    rl_tool["Tool Use RLVR<br/>(2025-2026 前沿)"]
    rl_agent["Agent RL<br/>多步任务"]

    rl_math --> rl_tool
    rl_code --> rl_tool
    rl_tool --> rl_agent

    classDef stage fill:#fff,stroke:#cc785c,color:#1a1a1a;
    class rl_math,rl_code,rl_tool,rl_agent stage

代表方向:

  • Search:网页搜索 + 浏览(Perplexity / Anthropic Research)
  • Code execution:跑 Python 验证(OpenAI Code Interpreter)
  • Computer Use:GUI 操作(Anthropic / OpenAI Operator)
  • API calls:调外部服务(订机票 / 数据库查询)

二、Tool Use RLVR 的挑战

挑战 数学/代码 RLVR Tool Use RLVR
验证器 字符串匹配/测试通过 需要判断"任务完成度"
环境一致性 纯函数,每次相同 工具可能有副作用(数据库、API)
多步依赖 答案是一次性的 多次工具调用,前面影响后面
探索空间 CoT 的 token 空间 CoT + 工具调用组合 → 指数爆炸
奖励延迟 一步就有 reward 多步后才知道成功/失败

三、Search Tool Use(网页搜索)

3.1 架构

class SearchAgent:
    def __init__(self, model, search_tool, browser_tool):
        self.model = model
        self.search = search_tool
        self.browser = browser_tool

    def solve(self, question):
        history = [{"role": "system", "content": "You have access to search and browser tools..."}]
        history.append({"role": "user", "content": question})

        for step in range(max_steps):
            action = self.model.generate_action(history)
            if action.type == "search":
                results = self.search(action.query)
                history.append({"role": "tool", "content": results})
            elif action.type == "browse":
                content = self.browser.fetch(action.url)
                history.append({"role": "tool", "content": content})
            elif action.type == "answer":
                return action.answer

        return "I couldn't find the answer"

3.2 验证方法

3.3 代表工作


四、通用 Tool Use

4.1 MCP (Model Context Protocol)

2024 末 Anthropic 提出的协议,2026 年已成为工具调用的事实标准。参考 MCP Spec

flowchart LR
    llm["LLM"]
    mcp["MCP Client"]
    s1["Server: search"]
    s2["Server: code"]
    s3["Server: file"]
    s4["Server: 自家 API"]

    llm <--> mcp
    mcp <--> s1
    mcp <--> s2
    mcp <--> s3
    mcp <--> s4

    classDef stage fill:#fff,stroke:#cc785c,color:#1a1a1a;
    class llm,mcp,s1,s2,s3,s4 stage

详见 agent-mcp.md §三 MCP 深入。RLVR 训练时把 MCP server 模拟成 verifier,不需要每次跑真实 API。

4.2 Tool Use RL 的关键工作

4.3 Tool Use RL 的奖励设计

class ToolUseReward:
    def compute(self, trajectory, task):
        # trajectory: [(observation, action, tool_result), ...]
        rewards = {}

        # 1. 最终任务完成度 (最重要)
        rewards['task'] = self.task_verifier(trajectory[-1], task)

        # 2. 工具使用正确性 (中间信号)
        tool_errors = sum(1 for t in trajectory if 'error' in t['tool_result'])
        rewards['tool_correctness'] = 1.0 - tool_errors / len(trajectory)

        # 3. 效率 (步数惩罚)
        rewards['efficiency'] = max(0, 1.0 - len(trajectory) / max_steps)

        # 4. 格式正确性
        rewards['format'] = self.check_format(trajectory)

        # 组合
        total = (0.7 * rewards['task'] + 
                 0.15 * rewards['tool_correctness'] +
                 0.1 * rewards['efficiency'] +
                 0.05 * rewards['format'])
        return total, rewards

五、Agent RL 的特殊挑战

5.1 信用分配 (Credit Assignment)

多步 Agent 中,任务失败可能源于任何一步。如何判断"错在哪一步"?

5.2 探索 vs 利用

# 普通 RL: 采样温度 0.7 足够探索
# Agent RL: 需要更激进的探索策略
# 因为动作空间 = CoT + 工具调用组合, 搜索空间巨大

exploration_strategies = {
    'high_temperature': 1.0,        # 更随机
    'epsilon_greedy': 0.2,          # 20% 概率随机动作
    'ucb_exploration': True,         # 偏好未尝试过的动作
    'intrinsic_reward': 'curiosity', # 好奇心驱动探索
}

六、GUI / Computer Use

6.1 概念

让模型像人一样使用电脑:看屏幕、点击、打字、拖拽。参考 Claude Computer Use (Anthropic)

class ComputerUseAgent:
    def step(self, screenshot):
        # 看屏幕
        understanding = self.vlm.analyze(screenshot)

        # 决定动作
        action = self.model.generate_action(understanding)
        # 可能的 action:
        # - click(x, y)
        # - type("...")
        # - scroll(direction)
        # - hotkey("ctrl+c")

        # 执行动作 (通过 OS API)
        execute_action(action)

        # 等待页面变化
        time.sleep(0.5)
        return take_screenshot()

6.2 验证环境


七、前沿:Deep Research Agent

2025 年出现的新方向:让 Agent 做长期研究任务,包括文献检索、实验设计、论文写作。


参考文献


上级 · E. 后训练与对齐