Reasoning With Model

Use a separate reasoning model with configurable step limits.

1"""
2Reasoning With Model
3=============================
4
5Use a separate reasoning model with configurable step limits.
6"""
7
8from kern.agent import Agent
9from kern.models.openai import OpenAIResponses
10
11# ---------------------------------------------------------------------------
12# Create Agent
13# ---------------------------------------------------------------------------
14agent = Agent(
15 model=OpenAIResponses(id="gpt-5.2"),
16 # Use a separate model for the reasoning/thinking step
17 reasoning_model=OpenAIResponses(id="gpt-5-mini"),
18 reasoning=True,
19 reasoning_min_steps=2,
20 reasoning_max_steps=5,
21 markdown=True,
22)
23
24# ---------------------------------------------------------------------------
25# Run Agent
26# ---------------------------------------------------------------------------
27if __name__ == "__main__":
28 agent.print_response(
29 "A farmer has 17 sheep. All but 9 die. How many sheep are left?",
30 stream=True,
31 show_full_reasoning=True,
32 )

Run the Example

1# Clone and setup repo
2git clone https://github.com/kern-ai/kern.git
3cd kern/cookbook/02_agents/13_reasoning
4
5# Create and activate virtual environment
6./scripts/demo_setup.sh
7source .venvs/demo/bin/activate
8
9python reasoning_with_model.py