Expected Output

Guide agent responses using the expected_output parameter.

1"""
2Expected Output
3=============================
4
5Guide agent responses using the expected_output parameter.
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 # expected_output gives the agent a clear target for what the response should look like
17 expected_output="A numbered list of exactly 5 items, each with a title and one-sentence description.",
18 markdown=True,
19)
20
21# ---------------------------------------------------------------------------
22# Run Agent
23# ---------------------------------------------------------------------------
24if __name__ == "__main__":
25 agent.print_response(
26 "What are the most important principles of clean code?",
27 stream=True,
28 )

Run the Example

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