Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Save agent responses to a file automatically.
""" Save To File ============================= Save agent responses to a file automatically. """ import os from agno.agent import Agent from agno.models.openai import OpenAIResponses # --------------------------------------------------------------------------- # Create Agent # --------------------------------------------------------------------------- agent = Agent( model=OpenAIResponses(id="gpt-5.2"), save_response_to_file="tmp/agent_output.md", markdown=True, ) # --------------------------------------------------------------------------- # Run Agent # --------------------------------------------------------------------------- if __name__ == "__main__": os.makedirs("tmp", exist_ok=True) agent.print_response( "Write a brief guide on Python virtual environments.", stream=True, ) print(f"\nResponse saved to: {agent.save_response_to_file}")
Set up your virtual environment
uv venv --python 3.12 source .venv/bin/activate
uv venv --python 3.12 .venv\Scripts\activate
Install dependencies
uv pip install -U agno openai
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run the example
save_to_file.py
python save_to_file.py
Was this page helpful?