Output Model
Use a separate output model to refine the main model's response.
1"""2Output Model3=============================45Use a separate output model to refine the main model's response.67The output_model receives the same conversation but generates its own8response, replacing the main model's output. This is useful when you9want a cheaper model to handle reasoning/tool-use and a more capable10model to produce the final polished answer.1112For structured JSON output, use ``parser_model`` instead (see parser_model.py).13"""1415from kern.agent import Agent, RunOutput16from kern.models.openai import OpenAIResponses17from rich.pretty import pprint1819# ---------------------------------------------------------------------------20# Create Agent21# ---------------------------------------------------------------------------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)2829# ---------------------------------------------------------------------------30# Run Agent31# ---------------------------------------------------------------------------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 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 output_model.py