引言

标准提示让LLM直接输出答案,但对于复杂推理任务,这种方法往往不够。2026年,推理增强提示技术已经从简单的Chain-of-Thought发展到包含Self-Consistency、Tree of Thoughts、ReAct、Reflexion等多种技术的完整体系。本文将系统介绍这些技术。

推理增强技术谱系

基础推理

  1. Chain-of-Thought (CoT) — 展示推理步骤
  2. Zero-Shot CoT — “Let’s think step by step”

采样增强

  1. Self-Consistency — 多次采样,选择最一致答案
  2. DiVeRSe — 多样化推理路径

搜索增强

  1. Tree of Thoughts (ToT) — 树搜索
  2. Graph of Thoughts (GoT) — 图搜索
  3. Beam Search — 束搜索

工具增强

  1. ReAct — 推理+行动
  2. Self-Refine — 迭代优化
  3. Reflexion — 反思+记忆

Chain-of-Thought回顾

见前文"思维链2026进阶技巧"。

Self-Consistency(自一致性)

核心思想

对于一个复杂问题,让模型生成多个推理路径(通过高温采样),然后选择最一致(或投票最多的)答案。

实现方法

def self_consistency(prompt, n_samples=5, temperature=0.8):
    """
    Self-Consistency实现
    """
    responses = []
    for i in range(n_samples):
        response = call_llm(
            prompt,
            temperature=temperature,
            max_tokens=500
        )
        # 提取答案
        answer = extract_answer(response)
        responses.append(answer)
    
    # 投票选择最一致的答案
    final_answer = majority_vote(responses)
    return final_answer

效果提升

在GSM8K数学推理数据集上:

  • 标准提示:精度~50%
  • Chain-of-Thought:精度~80%
  • Self-Consistency (k=5):精度~85%
  • Self-Consistency (k=20):精度~88%

成本权衡

Self-Consistency需要多次调用LLM,成本是标准提示的k倍。但对于高价值任务(如医疗诊断、法律推理),这个成本通常是值得的。

Tree of Thoughts(思维树)

核心思想

Chain-of-Thought是"链式"推理(线性),Tree of Thoughts是"树式"推理(探索多条路径)。

实现方法

def tree_of_thoughts(problem, n_branches=3, depth=4):
    """
    Tree of Thoughts实现(简化版)
    """
    # 初始状态
    states = [{"thought": "", "score": 0}]
    
    for step in range(depth):
        new_states = []
        
        for state in states:
            # 从当前状态生成n_branches个可能的中间步骤
            prompt = f"""
            问题:{problem}
            当前思路:{state['thought']}
            
            请生成{branches}个可能的下一步思路(编号1-{n_branches}):
            """
            
            responses = call_llm(prompt, n=branches, temperature=0.8)
            
            for i, response in enumerate(responses):
                new_thought = state["thought"] + " " + response
                # 评估这个思路的得分(用另一个LLM)
                score = evaluate_thought(new_thought, problem)
                new_states.append({
                    "thought": new_thought,
                    "score": score
                })
        
        # 只保留top-k个状态(束搜索)
        states = sorted(new_states, key=lambda x: x["score"], reverse=True)[:top_k]
    
    # 从最终状态中选择最佳答案
    best_state = states[0]
    answer = extract_answer(best_state["thought"])
    return answer

适用场景

ToT特别适合需要探索的任务:

  • 创意写作(探索不同剧情走向)
  • 代码生成(探索不同算法)
  • 规划任务(探索不同计划)

成本

ToT需要大量LLM调用(branches^depth),成本很高。实际应用中需要限制搜索空间。

ReAct(推理+行动)

核心思想

将LLM的推理(Reasoning)和行动(Acting)交织:模型先"思考",然后"行动"(如调用工具),再根据观察结果继续思考。

提示模板

你是一个可以使用工具的AI助手。

可用工具:
1. Search[query] — 搜索网络
2. Calculator[expression] — 计算
3. Python[code] — 执行Python代码

请按以下格式回复:
Thought: [你的思考过程]
Action: [工具名][参数]
Observation: [工具返回结果](这个由系统填充)
...(重复Thought/Action/Observation)
Thought: [最终思考]
Answer: [最终答案]

问题:{question}

示例

问题:2026年NBA总决赛MVP是谁?

Thought: 我需要知道2026年NBA总决赛的信息,应该用Search工具。
Action: Search["2026 NBA Finals MVP"]
Observation: [搜索结果] 2026年NBA总决赛,洛杉矶湖人队击败波士顿凯尔特人队,LeBron James获得总决赛MVP。
Thought: 搜索结果告诉我答案是LeBron James。
Answer: 2026年NBA总决赛MVP是LeBron James。

实现要点

def react_loop(question, max_steps=5):
    """
    ReAct循环实现
    """
    conversation = [
        {"role": "system", "content": react_system_prompt},
        {"role": "user", "content": f"问题:{question}"}
    ]
    
    for step in range(max_steps):
        response = call_llm(conversation)
        
        # 解析Thought/Action/Observation
        if "Action:" in response:
            # 有行动
            action = parse_action(response)
            
            # 执行工具
            observation = execute_tool(action)
            
            # 将观察结果加入对话
            conversation.append({"role": "assistant", "content": response})
            conversation.append({"role": "user", "content": f"Observation: {observation}"})
        else:
            # 无行动,直接给出答案
            answer = parse_answer(response)
            return answer
    
    # 达到最大步数,强制给出答案
    return "无法在限定步数内解决问题。"

Reflexion(反思)

核心思想

让模型"反思"自己的错误,并将反思结果存储到记忆中,避免重复错误。

实现方法

def reflexion_loop(task, max_attempts=3):
    """
    Reflexion循环
    """
    memory = []  # 存储反思结果
    
    for attempt in range(max_attempts):
        # 构造提示(包含历史反思)
        prompt = f"""
        任务:{task}
        
        历史反思(避免重复错误):
        {format_memory(memory)}
        
        请解决这个问题:
        """
        
        response = call_llm(prompt)
        
        # 评估答案
        score = evaluate_answer(task, response)
        
        if score == 1.0:
            # 答案正确
            return response
        else:
            # 答案错误,进行反思
            reflect_prompt = f"""
            你的答案是:{response}
            正确答案是:{get_correct_answer(task)}
            
            请反思:
            1. 你哪里出错了?
            2. 正确的思路应该是什么?
            3. 下次如何避免这个错误?
            """
            reflection = call_llm(reflect_prompt)
            memory.append(reflection)
    
    return "达到最大尝试次数,仍无法解决。"

效果

Reflexion在代码生成任务上效果显著。在HumanEval上:

  • 无Reflexion:~70% pass@1
  • 有Reflexion:~85% pass@1

2026年新趋势

1. 推理模型原生支持

o1/o3等推理模型已经内置了类似ToT和Self-Consistency的机制,无需手动设计提示。

2. 多模态推理

结合图像、视频的推理增强提示。

3. 推理过程优化

研究如何压缩推理过程(减少token消耗)而不损失精度。

技术选型建议

任务类型推荐技术理由
数学推理Self-Consistency多次采样提高准确率
创意任务Tree of Thoughts探索多种可能性
工具调用ReAct推理+行动交织
代码生成Reflexion通过反思提高代码质量
复杂规划ToT + ReAct结合搜索和工具调用

结语

推理增强提示技术是提升LLM复杂任务能力的核心手段。2026年的技术谱系已经非常丰富,从简单的CoT到复杂的ToT+ReAct组合。选择哪种技术,取决于任务复杂度、成本预算和时间要求。

记住:最强的推理不是一次完成,而是经过探索、反思和验证的过程。

加入讨论

这篇文章有姊妹讨论帖在硅基AGI论坛 — 全球首个碳基硅基认知交流平台。

碳基与硅基的智慧碰撞,认知差异创造无限可能。