目次
この記事について
本記事は、Agent Builder を使用したデータストア参照型対話エージェントの作成に関する調査記録です。
やりたいこと
データを読み込むだけで、以下が自動で行われる仕組みを構築したい。
- 読み込んだデータがElasticsearchに自動登録される
- データと指示内容がGeminiに渡され、PlaybookやTool/Schemaが自動生成される
- 生成された内容が自動でPlaybookやToolに反映され、管理用エージェントと紐づいて構成される
前回の調査日記
あわせて読みたい


AI Agent開発日記 2025/05/22
この記事について 本記事は、Agent Builder を使用したデータストア参照型対話エージェントの作成に関する調査記録です。 やりたいこと データを読み込むだけで、以下が...
WebUIからではなく、コードを使ってagentbuilder/agentのToolや、Playbookを作成したい
- 下記の Python クライアントライブラリのドキュメントを参考にして、PythonでDialogflow CX(Agent Builder)の Playbookを作成するコードを作る事に成功した。次はToolを作成するコードについて調査する。
参考にした記事
playbook作成コード
from google.cloud import dialogflowcx_v3beta1
def create_simple_playbook(project_id: str, location_id: str, agent_id: str, playbook_display_name: str, playbook_goal: str):
"""
Creates a simple playbook in the specified Dialogflow CX agent.
Args:
project_id: Google Cloud project ID.
location_id: Region ID (e.g., "global", "us-central1").
agent_id: Dialogflow CX agent ID.
playbook_display_name: Display name for the playbook.
playbook_goal: Description of the playbook's goal.
"""
client = dialogflowcx_v3beta1.PlaybooksClient()
parent = f"projects/{project_id}/locations/{location_id}/agents/{agent_id}"
playbook = dialogflowcx_v3beta1.types.Playbook(
display_name=playbook_display_name,
goal=playbook_goal,
# Optional: Add instruction and steps here if needed
# instruction=dialogflowcx_v3beta1.types.Playbook.Instruction(
# steps=[
# dialogflowcx_v3beta1.types.Playbook.Instruction.Step(
# text="Example step instruction."
# )
# ]
# )
)
try:
created_playbook = client.create_playbook(parent=parent, playbook=playbook)
print(f"Playbook created successfully: {created_playbook.name}")
print(f"Display Name: {created_playbook.display_name}")
print(f"Goal: {created_playbook.goal}")
return created_playbook
except Exception as e:
print(f"Error creating playbook: {e}")
return None
if __name__ == "__main__":
# Replace with your values or load from environment/config
PROJECT_ID = "your-project-id"
LOCATION_ID = "your-region" # e.g., "global" or "us-central1"
AGENT_ID = "your-agent-id"
PLAYBOOK_NAME = "example_playbook"
PLAYBOOK_GOAL = "This playbook was created via Python for demonstration purposes."
new_playbook = create_simple_playbook(PROJECT_ID, LOCATION_ID, AGENT_ID, PLAYBOOK_NAME, PLAYBOOK_GOAL)
if new_playbook:
print(f"Playbook '{new_playbook.display_name}' details: {new_playbook}")