OpenAI GPT-4.1

Add the following code to your Python file

1from kern.agent import Agent
2from kern.models.openai.responses import OpenAIResponses
3
4agent = Agent(
5 model=OpenAIResponses(id="gpt-5.2"),
6 reasoning_model=OpenAIResponses(id="gpt-5.2"),
7)
8agent.print_response(
9 "Solve the trolley problem. Evaluate multiple ethical frameworks. "
10 "Include an ASCII diagram of your solution.",
11 stream=True,
12)

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Install dependencies

1uv pip install -U kern-ai openai

Export your OpenAI API key

1export OPENAI_API_KEY="your_openai_api_key_here"
1$Env:OPENAI_API_KEY="your_openai_api_key_here"

Run Agent

1python openai.py