Translation Agent

Code

1import base64
2from pathlib import Path
3
4from kern.agent import Agent
5from kern.models.openai import OpenAIResponses
6from kern.tools.models.groq import GroqTools
7from kern.utils.media import save_base64_data
8
9path = "tmp/sample-fr.mp3"
10
11agent = Agent(
12 name="Groq Translation Agent",
13 model=OpenAIResponses(id="gpt-5.2"),
14 tools=[GroqTools()],
15 cache_session=True,
16)
17
18response = agent.run(
19 f"Let's transcribe the audio file located at '{path}' and translate it to English. After that generate a new music audio file using the translated text."
20)
21
22if response and response.audio:
23 base64_audio = base64.b64encode(response.audio[0].content).decode("utf-8")
24 save_base64_data(base64_audio, Path("tmp/sample-en.mp3")) # type: ignore

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API key

1export GROQ_API_KEY=xxx
2export OPENAI_API_KEY=xxx

Install dependencies

1uv pip install -U groq openai kern-ai

Run Agent

1python cookbook/11_models/groq/translation_agent.py