ThinkingTools 工具集为代理在执行过程中提供了专用的反思空间。该工具集使代理可以使用一个“思绪板”(scratchpad)来解决问题、列出规则、检查信息、验证合规性以及在采取行动前评估结果。

与让代理立即响应或采取行动的方法不同,该工具集通过为代理提供思考其行动、审视自身响应并记录整个对话过程中思考过程的空间,鼓励周密的考虑。

该工具集包含以下工具:

  • think:此工具充当代理的“思绪板”,用于解决问题、列出适用的规则、验证收集到的信息以及评估计划行动的合规性和正确性。

示例

以下是使用 ThinkingTools 工具集的示例:

from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.thinking import ThinkingTools
from agno.tools.yfinance import YFinanceTools

thinking_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",
    show_tool_calls=True,
    markdown=True,
)

thinking_agent.print_response("Write a report comparing NVDA to TSLA", stream=True)

该工具集附带默认指令,以帮助代理有效地使用该工具。以下是启用这些指令的方法:

thinking_agent = Agent(
    model=Claude(id="claude-3-7-sonnet-latest"),
    tools=[
        ThinkingTools(
            think=True,
            add_instructions=True,
        ),
    ],
)

ThinkingTools 可与支持函数调用的任何模型提供商一起使用。以下是一个使用 OpenAIChat 的思考型代理示例:

from textwrap import dedent

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.thinking import ThinkingTools

thinking_agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    tools=[ThinkingTools(add_instructions=True)],
    instructions=dedent("""\
        You are an expert problem-solving assistant with strong analytical skills! 🧠

        Your approach to problems:
        1. First, break down complex questions into component parts
        2. Clearly state your assumptions
        3. Develop a structured reasoning path
        4. Consider multiple perspectives
        5. Evaluate evidence and counter-arguments
        6. Draw well-justified conclusions

        When solving problems:
        - Use explicit step-by-step reasoning
        - Identify key variables and constraints
        - Explore alternative scenarios
        - Highlight areas of uncertainty
        - Explain your thought process clearly
        \
    """),
    add_datetime_to_instructions=True,
    stream_intermediate_steps=True,
    show_tool_calls=True,
    markdown=True,
)

此代理可用于处理需要仔细考虑的复杂问题:

thinking_agent.print_response(
    "We need to implement a new content moderation policy for our platform. "
    stream=True
)

或者:

thinking_agent.print_response(
    "Our company is developing a new AI product. We need to consider ethical implications "
    stream=True,
)