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


AI Agent開発日記 2025/05/24
この記事について 本記事は、Agent Builder を使用したデータストア参照型対話エージェントの作成に関する調査記録です。 やりたいこと データを読み込むだけで、以下が...
WebUIからではなく、コードを使ってagentbuilder/agentのToolや、Playbookを作成したい
- 現状
- 下記の Python クライアントライブラリのドキュメントを参考にして、PythonでDialogflow CX(Agent Builder)のToolを作成するコードを作る事に成功した。
参考記事
Tool作成コード
from google.cloud import dialogflowcx_v3beta1
def create_api_tool(project_id: str, location_id: str, agent_id: str,
tool_display_name: str, tool_description: str, openapi_yaml_string: str):
"""
Creates an API tool in the specified Dialogflow CX agent.
(Based on the help output for dialogflowcx_v3beta1.types.Tool)
"""
client = dialogflowcx_v3beta1.ToolsClient()
parent = f"projects/{project_id}/locations/{location_id}/agents/{agent_id}"
openapi_tool_spec = dialogflowcx_v3beta1.types.Tool.OpenApiTool(
text_schema=openapi_yaml_string
)
tool_config = dialogflowcx_v3beta1.types.Tool(
display_name=tool_display_name,
description=tool_description,
open_api_spec=openapi_tool_spec,
tool_type=dialogflowcx_v3beta1.types.Tool.ToolType.CUSTOMIZED_TOOL
)
try:
created_tool = client.create_tool(parent=parent, tool=tool_config)
print(f"Tool created successfully: {created_tool.name}")
print(f"Display Name: {created_tool.display_name}")
if created_tool.tool_type:
print(f"Tool Type (from response): {dialogflowcx_v3beta1.types.Tool.ToolType(created_tool.tool_type).name}")
else:
print("Tool Type (from response): Not specified or UNSPECIFIED")
print(f"Tool ID: {created_tool.name.split('/')[-1]}")
return created_tool
except Exception as e:
print(f"Error creating tool: {e}")
return None
if __name__ == "__main__":
# Replace these with your actual project details
PROJECT_ID = "your-project-id"
LOCATION_ID = "your-location-id" # e.g., "global" or "us-central1"
AGENT_ID = "your-agent-id" # Format: UUID
TOOL_DISPLAY_NAME = "Sample TODO API Tool"
TOOL_DESCRIPTION = "Fetches a specific TODO item from jsonplaceholder."
OPENAPI_SCHEMA = """
openapi: 3.0.0
info:
title: JSONPlaceholder TODO API
version: v1.0.0
description: A simple API to get a TODO item.
servers:
- url: https://jsonplaceholder.typicode.com
paths:
/todos/{todoId}:
get:
summary: Get a single TODO item by ID
operationId: getTodoById
parameters:
- name: todoId
in: path
required: true
description: ID of the todo to retrieve
schema:
type: integer
default: 1
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
properties:
userId:
type: integer
id:
type: integer
title:
type: string
completed:
type: boolean
default:
description: Error response
"""
new_tool = create_api_tool(PROJECT_ID, LOCATION_ID, AGENT_ID,
TOOL_DISPLAY_NAME, TOOL_DESCRIPTION, OPENAPI_SCHEMA)
if new_tool:
print(f"Tool '{new_tool.display_name}' details: {new_tool}")