Reasoning Tools
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.
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.
The toolkit includes the following tools:
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.analyze: This tool is used to analyze the results from a reasoning step and determine the next actions.
Example
Here's an example of how to use the ReasoningTools toolkit:
1from kern.agent import Agent2from kern.models.anthropic import Claude3from kern.tools.reasoning import ReasoningTools4from kern.tools.yfinance import YFinanceTools56thinking_agent = Agent(7 model=Claude(id="claude-3-7-sonnet-latest"),8 tools=[9 ReasoningTools(add_instructions=True),10 YFinanceTools(11 stock_price=True,12 analyst_recommendations=True,13 company_info=True,14 company_news=True,15 ),16 ],17 instructions="Use tables where possible",18 markdown=True,19)2021thinking_agent.print_response("Write a report comparing NVDA to TSLA", stream=True)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:
1reasoning_agent = Agent(2 model=Claude(id="claude-3-7-sonnet-latest"),3 tools=[4 ReasoningTools(5 think=True,6 analyze=True,7 add_instructions=True,8 add_few_shot=True,9 ),10 ],11)ReasoningTools can be used with any model provider that supports function calling. Here is an example with of a reasoning Agent using OpenAIResponses:
1from textwrap import dedent23from kern.agent import Agent4from kern.models.openai import OpenAIResponses5from kern.tools.reasoning import ReasoningTools67reasoning_agent = Agent(8 model=OpenAIResponses(id="gpt-5.2"),9 tools=[ReasoningTools(add_instructions=True)],10 instructions=dedent("""\11 You are an expert problem-solving assistant with strong analytical skills! ��1213 Your approach to problems:14 1. First, break down complex questions into component parts15 2. Clearly state your assumptions16 3. Develop a structured reasoning path17 4. Consider multiple perspectives18 5. Evaluate evidence and counter-arguments19 6. Draw well-justified conclusions2021 When solving problems:22 - Use explicit step-by-step reasoning23 - Identify key variables and constraints24 - Explore alternative scenarios25 - Highlight areas of uncertainty26 - Explain your thought process clearly27 - Consider both short and long-term implications28 - Evaluate trade-offs explicitly2930 For quantitative problems:31 - Show your calculations32 - Explain the significance of numbers33 - Consider confidence intervals when appropriate34 - Identify source data reliability3536 For qualitative reasoning:37 - Assess how different factors interact38 - Consider psychological and social dynamics39 - Evaluate practical constraints40 - Address value considerations41 \42 """),43 add_datetime_to_context=True,44 stream_events=True,45 markdown=True,46)This Agent can be used to ask questions that elicit thoughtful analysis, such as:
1reasoning_agent.print_response(2 "A startup has $500,000 in funding and needs to decide between spending it on marketing or "3 "product development. They want to maximize growth and user acquisition within 12 months. "4 "What factors should they consider and how should they analyze this decision?",5 stream=True6)or,
1reasoning_agent.print_response(2 "Solve this logic puzzle: A man has to take a fox, a chicken, and a sack of grain across a river. "3 "The boat is only big enough for the man and one item. If left unattended together, the fox will "4 "eat the chicken, and the chicken will eat the grain. How can the man get everything across safely?",5 stream=True,6)