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 Agent
2from kern.models.anthropic import Claude
3from kern.tools.reasoning import ReasoningTools
4from kern.tools.yfinance import YFinanceTools
5
6thinking_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)
20
21thinking_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 dedent
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from kern.tools.reasoning import ReasoningTools
6
7reasoning_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!
12
13 Your approach to problems:
14 1. First, break down complex questions into component parts
15 2. Clearly state your assumptions
16 3. Develop a structured reasoning path
17 4. Consider multiple perspectives
18 5. Evaluate evidence and counter-arguments
19 6. Draw well-justified conclusions
20
21 When solving problems:
22 - Use explicit step-by-step reasoning
23 - Identify key variables and constraints
24 - Explore alternative scenarios
25 - Highlight areas of uncertainty
26 - Explain your thought process clearly
27 - Consider both short and long-term implications
28 - Evaluate trade-offs explicitly
29
30 For quantitative problems:
31 - Show your calculations
32 - Explain the significance of numbers
33 - Consider confidence intervals when appropriate
34 - Identify source data reliability
35
36 For qualitative reasoning:
37 - Assess how different factors interact
38 - Consider psychological and social dynamics
39 - Evaluate practical constraints
40 - Address value considerations
41 \
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=True
6)

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)