Output Model

Use a separate output model to refine the main model's response.

1"""
2Output Model
3=============================
4
5Use a separate output model to refine the main model's response.
6
7The output_model receives the same conversation but generates its own
8response, replacing the main model's output. This is useful when you
9want a cheaper model to handle reasoning/tool-use and a more capable
10model to produce the final polished answer.
11
12For structured JSON output, use ``parser_model`` instead (see parser_model.py).
13"""
14
15from kern.agent import Agent, RunOutput
16from kern.models.openai import OpenAIResponses
17from rich.pretty import pprint
18
19# ---------------------------------------------------------------------------
20# Create Agent
21# ---------------------------------------------------------------------------
22agent = Agent(
23 model=OpenAIResponses(id="gpt-5-mini"),
24 description="You are a helpful chef that provides detailed recipe information.",
25 output_model=OpenAIResponses(id="gpt-5.2"),
26 output_model_prompt="You are a world-class culinary writer. Rewrite the recipe with vivid descriptions, pro tips, and elegant formatting.",
27)
28
29# ---------------------------------------------------------------------------
30# Run Agent
31# ---------------------------------------------------------------------------
32if __name__ == "__main__":
33 run: RunOutput = agent.run("Give me a recipe for pad thai.")
34 pprint(run.content)

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 output_model.py