はじめに
七尾百合子さん、お誕生日 140日目 おめでとうございます! nikkieです。
Today I Learnedです。
目次
adk run
に見つけた2つのオプション
uvx --from google-adk adk run --help
(ADK 1.9.0)
--save_session
Whether to save the session to a json file on exit.
--session_id
を指定してもよいですが、指定しない場合は「exit」するときにセッションIDを入力します。
「hoge」と入力するとhoge.session.json
というファイルが作られます。
--resume
--save_session
で保存したセッション(JSONファイル)を指定します。
The previous session will be re-displayed.
And user can continue to interact with the agent.
セッションを読み込んだ後で、エージェントとのやり取りを続けられます。
過去に作ったエージェントでお試し
refine-loop
というエージェントを作っていました。
% adk run refine-loop --save_session
% adk run refine-loop --resume refine-loop/hoge.session.json [user]: こんにちは [human_as_agent]: いえーい!ビビッといっくよーー!! [critique_agent]: This sentence is not formal at all. <ダメ出しの詳細は省略> [human_as_agent]: 開始いたします。 [critique_agent]: No major issues found. [user]:
続きから再開できます!
宿題事項
(1)--replay
は動かせていない
The json file that contains the initial state of the session and user queries.
A new session will be created using this state.
And user queries are run againt the newly created session. (ママ)
Users cannot continue to interact with the agent.
initial stateということなので、セッション全体の保存とはどうやら違うようです。
https://github.com/google/adk-python/blob/v.1.9.0/src/google/adk/cli/cli.py#L59 でエラー送出
pydantic_core._pydantic_core.ValidationError: 1 validation error for InputFile queries Field required [type=missing, input_value={'id': '98e9035f-8dca-461...ime': 1754315814.425355}, input_type=dict] For further information visit https://errors.pydantic.dev/2.11/v/missing
https://github.com/google/adk-python/blob/v.1.9.0/src/google/adk/cli/cli.py#L37-L39
class InputFile(BaseModel): state: dict[str, object] queries: list[str]
(2)resumeはユーザからで、エージェントの途中からは再開できなさそう
保存したJSONファイルを加工してみたのですが、ユーザ入力からの再開となりそうです。
[user]: こんにちは [human_as_agent]: いえーい!ビビッといっくよーー!! [user]: hello
human_as_agent
の入力はフォーマルでないのでcritique_agent
から指摘がほしいところですが、userの入力からの再開でした。
これらの宿題、ソースコードを読んでいくことになりそうです1。
終わりに
adk run
の--resume
オプションを知り、過去に作ったエージェントで試しました。
保存したセッションを読み込んでユーザ入力から再開できるので、チャットボットのような開発では便利そうです。
一方、ユーザがやり取りするエージェントが複数のエージェントからなる場合、途中のエージェントから再開する方法はまだ見つけられていません。
先日聞いた「Mastering Async Agents」でもreplayへの言及があり2、「ADKには備わっているのかな」と調べていて存在を知りました。
adk web
から保存したセッションやadk api_server
の返り値も読み込めるかなど、気になることはまだまだあり、やや期待しています。
- ドキュメントはほとんどなさそうでした。例えば「replay」はこちらのページのみ https://google.github.io/adk-docs/observability/agentops/↩
- Cognitionのセッションでした ↩