Save To File
Save agent responses to a file automatically.
1"""2Save To File3=============================45Save agent responses to a file automatically.6"""78import os910from kern.agent import Agent11from kern.models.openai import OpenAIResponses1213# ---------------------------------------------------------------------------14# Create Agent15# ---------------------------------------------------------------------------16agent = Agent(17 model=OpenAIResponses(id="gpt-5.2"),18 save_response_to_file="tmp/agent_output.md",19 markdown=True,20)2122# ---------------------------------------------------------------------------23# Run Agent24# ---------------------------------------------------------------------------25if __name__ == "__main__":26 os.makedirs("tmp", exist_ok=True)27 agent.print_response(28 "Write a brief guide on Python virtual environments.",29 stream=True,30 )31 print(f"\nResponse saved to: {agent.save_response_to_file}")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 save_to_file.py