|
| 1 | +--- |
| 2 | +title: Reasoning Tools |
| 3 | +sidebarTitle: Reasoning |
| 4 | +--- |
| 5 | + |
| 6 | +The `ReasoningTools` toolkit allows an Agent to use reasoning like any other tool, at any point during execution. Unlike traditional approaches that reason once at the start to create a fixed plan, this enables the Agent to reflect after each step, adjust its thinking, and update its actions on the fly. |
| 7 | + |
| 8 | +We've found that this approach significantly improves an Agent's ability to solve complex problems it would otherwise fail to handle. By giving the Agent space to "think" about its actions, it can examine its own responses more deeply, question its assumptions, and approach the problem from different angles. |
| 9 | + |
| 10 | +The toolkit includes the following tools: |
| 11 | + |
| 12 | +- `think`: This tool is used as a scratchpad by the Agent to reason about the question and work through it step by step. It helps break down complex problems into smaller, manageable chunks and track the reasoning process. |
| 13 | +- `analyze`: This tool is used to analyze the results from a reasoning step and determine the next actions. |
| 14 | + |
| 15 | +## Example |
| 16 | + |
| 17 | +Here's an example of how to use the `ReasoningTools` toolkit: |
| 18 | + |
| 19 | +```python |
| 20 | +from agno.agent import Agent |
| 21 | +from agno.models.anthropic import Claude |
| 22 | +from agno.tools.thinking import ThinkingTools |
| 23 | +from agno.tools.yfinance import YFinanceTools |
| 24 | + |
| 25 | +thinking_agent = Agent( |
| 26 | + model=Claude(id="claude-3-7-sonnet-latest"), |
| 27 | + tools=[ |
| 28 | + ThinkingTools(add_instructions=True), |
| 29 | + YFinanceTools( |
| 30 | + stock_price=True, |
| 31 | + analyst_recommendations=True, |
| 32 | + company_info=True, |
| 33 | + company_news=True, |
| 34 | + ), |
| 35 | + ], |
| 36 | + instructions="Use tables where possible", |
| 37 | + show_tool_calls=True, |
| 38 | + markdown=True, |
| 39 | +) |
| 40 | + |
| 41 | +thinking_agent.print_response("Write a report comparing NVDA to TSLA", stream=True) |
| 42 | +``` |
| 43 | + |
| 44 | +The toolkit comes with default instructions and few-shot examples to help the Agent use the tool effectively. Here is how you can enable them: |
| 45 | + |
| 46 | +```python |
| 47 | +reasoning_agent = Agent( |
| 48 | + model=Claude(id="claude-3-7-sonnet-latest"), |
| 49 | + tools=[ |
| 50 | + ReasoningTools( |
| 51 | + think=True, |
| 52 | + analyze=True, |
| 53 | + add_instructions=True, |
| 54 | + add_few_shot=True, |
| 55 | + ), |
| 56 | + ], |
| 57 | +) |
| 58 | +``` |
| 59 | + |
| 60 | +`ReasoningTools` can be used with any model provider that supports function calling. Here is an example with of a reasoning Agent using `OpenAIChat`: |
| 61 | + |
| 62 | +```python |
| 63 | +from textwrap import dedent |
| 64 | + |
| 65 | +from agno.agent import Agent |
| 66 | +from agno.models.openai import OpenAIChat |
| 67 | +from agno.tools.reasoning import ReasoningTools |
| 68 | + |
| 69 | +reasoning_agent = Agent( |
| 70 | + model=OpenAIChat(id="gpt-4o"), |
| 71 | + tools=[ReasoningTools(add_instructions=True)], |
| 72 | + instructions=dedent("""\ |
| 73 | + You are an expert problem-solving assistant with strong analytical skills! 🧠 |
| 74 | +
|
| 75 | + Your approach to problems: |
| 76 | + 1. First, break down complex questions into component parts |
| 77 | + 2. Clearly state your assumptions |
| 78 | + 3. Develop a structured reasoning path |
| 79 | + 4. Consider multiple perspectives |
| 80 | + 5. Evaluate evidence and counter-arguments |
| 81 | + 6. Draw well-justified conclusions |
| 82 | +
|
| 83 | + When solving problems: |
| 84 | + - Use explicit step-by-step reasoning |
| 85 | + - Identify key variables and constraints |
| 86 | + - Explore alternative scenarios |
| 87 | + - Highlight areas of uncertainty |
| 88 | + - Explain your thought process clearly |
| 89 | + - Consider both short and long-term implications |
| 90 | + - Evaluate trade-offs explicitly |
| 91 | +
|
| 92 | + For quantitative problems: |
| 93 | + - Show your calculations |
| 94 | + - Explain the significance of numbers |
| 95 | + - Consider confidence intervals when appropriate |
| 96 | + - Identify source data reliability |
| 97 | +
|
| 98 | + For qualitative reasoning: |
| 99 | + - Assess how different factors interact |
| 100 | + - Consider psychological and social dynamics |
| 101 | + - Evaluate practical constraints |
| 102 | + - Address value considerations |
| 103 | + \ |
| 104 | + """), |
| 105 | + add_datetime_to_instructions=True, |
| 106 | + stream_intermediate_steps=True, |
| 107 | + show_tool_calls=True, |
| 108 | + markdown=True, |
| 109 | +) |
| 110 | +``` |
| 111 | + |
| 112 | +This Agent can be used to ask questions that elicit thoughtful analysis, such as: |
| 113 | + |
| 114 | +```python |
| 115 | +reasoning_agent.print_response( |
| 116 | + "A startup has $500,000 in funding and needs to decide between spending it on marketing or " |
| 117 | + "product development. They want to maximize growth and user acquisition within 12 months. " |
| 118 | + "What factors should they consider and how should they analyze this decision?", |
| 119 | + stream=True |
| 120 | +) |
| 121 | +``` |
| 122 | + |
| 123 | +or, |
| 124 | + |
| 125 | +```python |
| 126 | +reasoning_agent.print_response( |
| 127 | + "Solve this logic puzzle: A man has to take a fox, a chicken, and a sack of grain across a river. " |
| 128 | + "The boat is only big enough for the man and one item. If left unattended together, the fox will " |
| 129 | + "eat the chicken, and the chicken will eat the grain. How can the man get everything across safely?", |
| 130 | + stream=True, |
| 131 | +) |
| 132 | +``` |
0 commit comments