本文中の「ADK エージェントの定義」にある下記の部分のコードを修正します。
また、このエージェントを実行するための AdkApp オブジェクトを次のように定義します。
def artifact_builder():
return GcsArtifactService(bucket_name=BUCKET_NAME)
adk_app = AdkApp(
agent=root_agent,
app_name='smartphone_maps_qa_app',
artifact_service_builder=artifact_builder,
)上記のコードを次の内容に置き換えてください。
from google.adk.plugins import BasePlugin
class GcsArtifactPlugin(BasePlugin):
def __init__(self):
super().__init__(name='GcsArtifactPlugin')
async def before_agent_callback(
self, *, agent, callback_context
):
callback_context._invocation_context.artifact_service = GcsArtifactService(
bucket_name=BUCKET_NAME
)
return None
def artifact_builder():
return GcsArtifactService(bucket_name=BUCKET_NAME)
adk_app = AdkApp(
agent=root_agent,
app_name='smartphone_maps_qa_app',
artifact_service_builder=artifact_builder,
plugins=[GcsArtifactPlugin()],
)