ツールキットはエージェントに追加できる関数のコレクションです。
ここでは、モデル対応ツール OpenAI 等の使い方を説明します。
Agno : ユーザガイド : コンセプト : ツール – ツールキット : モデル (OpenAI 等)
作成 : クラスキャット・セールスインフォメーション
作成日時 : 08/05/2025
バージョン : Agno 1.7.7
* 本記事は docs.agno.com の以下のページを独自に翻訳した上で、補足説明を加えてまとめ直しています :
* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。
◆ お問合せ : 下記までお願いします。
- クラスキャット セールス・インフォメーション
- sales-info@classcat.com
- ClassCatJP
Agno ユーザガイド : コンセプト : ツール – ツールキット : モデル : OpenAI
OpenAITools はエージェントが OpenAI モデルとやり取りして、音声トランスクリプション、画像生成、そしてテキスト発話変換を実行することを可能にします。
前提条件
OpenAITools を使用する前に、openai ライブラリがインストールされ OpenAI API キーが設定されていることを確認してください。
- ライブラリのインストール
pip install -U openai
- API キーの設定: API キーを OpenAI から取得して環境変数として設定します
export OPENAI_API_KEY="your-openai-api-key"
初期化
OpenAITools をインポートしてエージェントのツールリストに追加します。
from agno.agent import Agent
from agno.tools.openai import OpenAITools
agent = Agent(
name="OpenAI Agent",
tools=[OpenAITools()],
show_tool_calls=True,
markdown=True,
)
使用例
1. 音声の文字起こし
この例は音声ファイルを文字起こしするエージェントを実演します。
transcription_agent.py
from pathlib import Path
from agno.agent import Agent
from agno.tools.openai import OpenAITools
from agno.utils.media import download_file
audio_url = "https://agno-public.s3.amazonaws.com/demo_data/sample_conversation.wav"
local_audio_path = Path("tmp/sample_conversation.wav")
download_file(audio_url, local_audio_path)
agent = Agent(
name="OpenAI Transcription Agent",
tools=[OpenAITools(transcription_model="whisper-1")],
show_tool_calls=True,
markdown=True,
)
agent.print_response(f"Transcribe the audio file located at '{local_audio_path}'")
2. 画像生成
この例はテキストプロンプトに基づいて画像を生成するエージェントを実演します。
image_generation_agent.py
from agno.agent import Agent
from agno.tools.openai import OpenAITools
from agno.utils.media import save_base64_data
agent = Agent(
name="OpenAI Image Generation Agent",
tools=[OpenAITools(image_model="dall-e-3")],
show_tool_calls=True,
markdown=True,
)
response = agent.run("Generate a photorealistic image of a cozy coffee shop interior")
if response.images:
save_base64_data(response.images[0].content, "tmp/coffee_shop.png")
3. 音声生成
この例はテキストから音声を生成するエージェントを実演します。
speech_synthesis_agent.py
from agno.agent import Agent
from agno.tools.openai import OpenAITools
from agno.utils.media import save_base64_data
agent = Agent(
name="OpenAI Speech Agent",
tools=[OpenAITools(
text_to_speech_model="tts-1",
text_to_speech_voice="alloy",
text_to_speech_format="mp3"
)],
show_tool_calls=True,
markdown=True,
)
agent.print_response("Generate audio for the text: 'Hello, this is a synthesized voice example.'")
response = agent.run_response
if response and response.audio:
save_base64_data(response.audio[0].base64_audio, "tmp/hello.mp3")
Note : View more examples here.
カスタマイズ
トランスクリプション、画像生成と TTS に使用される基盤となる OpenAI モデルをカスタマイズできます :
OpenAITools(
transcription_model="whisper-1",
image_model="dall-e-3",
text_to_speech_model="tts-1-hd",
text_to_speech_voice="nova",
text_to_speech_format="wav"
)
以上