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)
47
48# Example usage with a complex reasoning problem
49reasoning_agent.print_response(
50 "Solve this logic puzzle: A man has to take a fox, a chicken, and a sack of grain across a river. "
51 "The boat is only big enough for the man and one item. If left unattended together, the fox will "
52 "eat the chicken, and the chicken will eat the grain. How can the man get everything across safely?",
53 stream=True,
54)
55
56# # Economic analysis example
57# reasoning_agent.print_response(
58# "Is it better to rent or buy a home given current interest rates, inflation, and market trends? "
59# "Consider both financial and lifestyle factors in your analysis.",
60# stream=True
61# )
62
63# # Strategic decision-making example
64# reasoning_agent.print_response(
65# "A startup has $500,000 in funding and needs to decide between spending it on marketing or "
66# "product development. They want to maximize growth and user acquisition within 12 months. "
67# "What factors should they consider and how should they analyze this decision?",
68# stream=True
69# )