Code
audio_multi_turn.py
Usage
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run Agent
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Keep audio conversation context across turns with OpenAIChat’s gpt-audio model and add_history_to_context.
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIChat
from agno.utils.audio import write_audio_to_file
from rich.pretty import pprint
agent = Agent(
model=OpenAIChat(
id="gpt-audio",
modalities=["text", "audio"],
audio={"voice": "sage", "format": "wav"},
),
add_history_to_context=True,
db=SqliteDb(
session_table="audio_multi_turn_sessions", db_file="tmp/audio_multi_turn.db"
),
)
run_response = agent.run("Is a golden retriever a good family dog?")
pprint(run_response.content)
if run_response.response_audio is not None:
write_audio_to_file(
audio=run_response.response_audio.content, filename="tmp/answer_1.wav"
)
run_response = agent.run("What breed are we talking about?")
pprint(run_response.content)
if run_response.response_audio is not None:
write_audio_to_file(
audio=run_response.response_audio.content, filename="tmp/answer_2.wav"
)
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 openai sqlalchemy agno
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run Agent
python audio_multi_turn.py
Was this page helpful?