Expected Output
Guide agent responses using the expected_output parameter.
1"""2Expected Output3=============================45Guide agent responses using the expected_output parameter.6"""78from kern.agent import Agent9from kern.models.openai import OpenAIResponses1011# ---------------------------------------------------------------------------12# Create Agent13# ---------------------------------------------------------------------------14agent = Agent(15 model=OpenAIResponses(id="gpt-5.2"),16 # expected_output gives the agent a clear target for what the response should look like17 expected_output="A numbered list of exactly 5 items, each with a title and one-sentence description.",18 markdown=True,19)2021# ---------------------------------------------------------------------------22# Run Agent23# ---------------------------------------------------------------------------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 repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/02_input_output45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python expected_output.py