> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 什么是推理？

> 推理使智能体（Agents）在响应前能够“思考”，并“分析”其行动（即工具调用）的结果，极大地提高了智能体解决需要顺序工具调用的问题的能力。

推理智能体（Reasoning Agents）在响应前会经历一个内部的思考链（chain of thought），尝试不同的想法，并在需要时进行验证和纠正。Agno 支持 3 种推理方法：

1. [推理模型](#reasoning-models)
2. [推理工具](#reasoning-tools)
3. [推理智能体](#reasoning-agents)

哪种方法最适合取决于您的用例，我们建议您尝试所有方法，并沉浸在推理智能体这个新时代中。

## 推理模型

推理模型是一类专门的大型语言模型，通过强化学习训练，使其能够在回答前进行思考。它们在响应前会产生一个内部的思考链。推理模型的例子包括 OpenAI o-series、扩展思考模式下的 Claude 3.7 sonnet、Gemini 2.0 flash thinking 和 DeepSeek-R1。

模型层的推理关系到模型在**开始生成响应之前**所做的一切。推理模型在单次解决（single-shot）用例方面表现出色。它们非常适合解决不需要多次交互或顺序调用工具的难题（编码、数学、物理）。

### 示例

```python o3_mini.py theme={null}
from agno.agent import Agent
from agno.models.openai import OpenAIChat

agent = Agent(model=OpenAIChat(id="o3-mini"))
agent.print_response(
    "Solve the trolley problem. Evaluate multiple ethical frameworks. "
    "Include an ASCII diagram of your solution.",
    stream=True,
)
```

在 [推理模型指南](/reasoning/reasoning-models) 中阅读更多关于推理模型的信息。

## 推理模型 + 回应模型

如果我们想使用一个推理模型进行推理，但使用另一个模型来生成响应，会怎么样？众所周知，推理模型在解决问题方面非常出色，但在以自然的方式进行响应方面（如 Claude sonnet 或 GPT-4o）却不是那么擅长。

通过使用一个单独的模型进行推理，另一个模型进行响应，我们可以获得两全其美的好处。

### 示例

让我们使用 Groq 的 deepseek-r1 进行推理，并使用 Claude sonnet 进行自然回应。

```python deepseek_plus_claude.py theme={null}
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.models.groq import Groq

deepseek_plus_claude = Agent(
    model=Claude(id="claude-3-7-sonnet-20250219"),
    reasoning_model=Groq(
        id="deepseek-r1-distill-llama-70b", temperature=0.6, max_tokens=1024, top_p=0.95
    ),
)
deepseek_plus_claude.print_response("9.11 和 9.9 -- 哪个更大?", stream=True)
```

## 推理工具

通过向模型提供一个 **“思考”工具**，我们可以为一个专门的结构化思考空间，从而极大地提高其推理能力。这是一种简单而有效的方法，可以为非推理模型添加推理能力。

该研究最初由 Anthropic 在[这篇博文](https://www.anthropic.com/engineering/claude-think-tool)中发布，但在此之前已被许多 AI 工程师（包括我们自己的团队）实践了。

### 示例

```python claude_thinking_tools.py theme={null}
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.thinking import ThinkingTools
from agno.tools.yfinance import YFinanceTools

reasoning_agent = Agent(
    model=Claude(id="claude-3-7-sonnet-latest"),
    tools=[
        ThinkingTools(add_instructions=True),
        YFinanceTools(
            stock_price=True,
            analyst_recommendations=True,
            company_info=True,
            company_news=True,
        ),
    ],
    instructions="Use tables where possible",
    markdown=True,
)

if __name__ == "__main__":
    reasoning_agent.print_response(
        "Write a report on NVDA. Only the report, no other text.",
        stream=True,
        show_full_reasoning=True,
        stream_intermediate_steps=True,
    )
```

在 [推理工具指南](/reasoning/reasoning-tools) 中阅读更多关于推理工具的信息。

## 推理智能体

推理智能体（Reasoning Agents）是 Agno 开发的一种新型多智能体系统，它将思考链推理与工具使用相结合。

您可以通过设置 `reasoning=True` 来为任何智能体启用推理。

当一个设置了 `reasoning=True` 的智能体接到任务时，一个独立的“推理智能体”会首先使用思考链来解决问题。在每个步骤中，它会调用工具来收集信息、验证结果并进行迭代，直到得出最终答案。一旦推理智能体得出最终答案，它会将结果交回给原始智能体进行验证并提供响应。

### 示例

```python reasoning_agent.py theme={null}
from agno.agent import Agent
from agno.models.openai import OpenAIChat

reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    reasoning=True,
    markdown=True,
)
reasoning_agent.print_response(
    "Solve the trolley problem. Evaluate multiple ethical frameworks. "
    "Include an ASCII diagram of your solution.",
    stream=True,
    show_full_reasoning=True,
)
```

在 [推理智能体指南](/reasoning/reasoning-agents) 中阅读更多关于推理智能体的信息。
