🤖

Agent Development Kit 1.12.0で追加された Pythonコード不要でAgentが作成できるAgent Config

に公開

こんにちは、サントリーこと大橋です。

本日(2025/08/21)にAgent Development Kit(以降ADK) 1.12.0がリリースされました。

https://github.com/google/adk-python/releases/tag/v1.12.0

最近は毎週金曜日にリリースされており、油断していたのですが、今回は木曜日リリースでした。
今回のリリースで追加された主な機能は以下です。

[Agent Config] 🌟 NEW FEATURE: Support using config file (YAML) to author agents in addition to python code. See the documentation for details.
[Agent Config] Support deploying config agent to Agent Engine in CLI (b3b7003)
[Tools] Add a dedicated Bigtable toolset to provide an easier, integrated way to interact
with Bigtable for building AI Agent applications(experimental feature) (a953807)
[Tools] Support custom tool_name_prefix in auto-generated GoogleApiToolset (a2832d5) See oauth_calendar_agent as an example.
[CLI] Add build_image option for adk deploy cloud_run CLI (c843503)
[Services] Add setdefault method to the ADK State object (77ed1f5)

  • Agent Configの追加
  • Bigtable Toolsetの追加
  • GoogleApiToolsetにも tool_name_prefix サポート
  • adk deploy cloud_run コマンドに ベースコンテナイメージを指定できる build_image の追加
  • Stateオブジェクトに setdefault メソッド追加

他にもバグフィックスや細々した機能追加やドキュメントの改善が行われています。
今回はこの中でロードマップに記載されており、長らく開発が進められていたAgent Configについて書いていきたいと思います。

課題: AI Agentの作成にコードは必要か

AI Agentを作成していると、その多くの部分はLLMに対する指示である「System Prompt(Instruction)」とLLMが利用するツールを開発する部分がほとんどです。逆を言えば、ツールの開発を除くと、モデル選択とInstructionというコードではない部分の開発が多くを占めることになります。

ADKはLangChainやGenkitなどに比べると、LLMを利用して何かするライブラリ/フレームワークというよりも、AI Agentを作成するためのフレームワークです。
そのため、LLMを利用したデータのPipeline処理などは目指しているゴールが異なっており、多くの複雑なプロセスは必要とせず、少ないコードでAI Agentを作成できる特徴があります

誤解を恐れず言えば、ADKにおいて特殊なケースを除くと、ツール開発を除いて、純粋なAI Agentの作成にコードの記述はあまり必要でないと言えます。

YAMLでAgentを作成するAgent Config機能

Agent Configの概要

そこで登場するのが今回追加された「Agent Config」機能です。
Agent ConfigはYAMLでADKのAgentを作成する機能で、以下のようなYAMLを記述し、読み込みます。

例: 最小のAgent Configサンプル

# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json
name: assistant_agent
model: gemini-2.5-flash
description: A helper agent that can answer users' questions.
instruction: You are an agent to help answer users' various questions.

Agent Configで書かれたAgentの作成

Agent Config機能を利用したAgentを作成するにはadk createコマンドを利用するか自分でファイルを作成します。

adk create コマンドを利用する場合は adk create --type=config agent_name のように --type=configオプションを追加します。
すると以下のように root_agent.yaml が作成されます。

adk create --type=configの実行

$ adk create --config agent_config
Agent created in /path/to/agents/agent_config:

- .env
- __init__.py
- root_agent.yaml

なお作成されたroot_agent.yamlは以下です。

# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json
name: root_agent
description: A helpful assistant for user questions.
instruction: Answer user questions to the best of your knowledge
model: gemini-2.5-flash

直接自分でファイルを作成する場合も、adk create --type=configコマンド同様に agent名ディレクトリ(pythonモジュール)内に root_agent.yamlという名前のファイルを作成してください。

Agent Configで書かれたAgentの実行

Agent Configで書かれたAgentを実行するには、このYAMLファイルを読み込む必要があります。

adk webの場合

adk webを利用する場合は、上記の通りPythonモジュール内にあり、root_agent.yamlという名前でファイルが作成されていれば、特に何もしなくても今までのAgent同様に読み込むことができます。

adk webの実行

 adk web .

AgentLoaderを利用する場合

自前でRunnerを実行しており、Agentインスタンスの作成が必要な場合は少し処理が必要です。
最も簡単な方法はadk webでも利用されているgoogle.adk.cli.utils.agent_loader.AgentLoaderを利用する方法です。

https://github.com/google/adk-python/blob/main/src/google/adk/cli/utils/agent_loader.py#L36

以下のようにAgentLoaderにAgentが存在するディレクトリの親ディレクトリと、Agent名を渡すことで実行できます。

agent_config_runner.py
from google.adk.runners import InMemoryRunner
from google.adk.cli.utils.agent_loader import AgentLoader
from google.genai import types

async def main():

    loader = AgentLoader("../") # agentが格納されているディレクトリを指定
    agent = loader.load_agent("agent_config") # agent名を渡す

    runner = InMemoryRunner(agent=agent, app_name="test")
    await runner.session_service.create_session(app_name="test", user_id="user_id", session_id="session")
    for event in runner.run(user_id="user_id", session_id="session", new_message=types.UserContent(parts="こんにちは")):
        if event.is_final_response():
            print(event.content.parts[0].text)

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

※このコードは、agent_configディレクトリの1つ上の階層で実行することを想定しています。

$ ADK_SUPPRESS_EXPERIMENTAL_FEATURE_WARNINGS=TRUE uv run agent_config/__main__.py
こんにちは!何かお手伝いできることはありますか?

config_agent_utils.from_configを利用する場合

AgentLoaderの内部を見ると、実際にAgentの読み込みを行っているのは、google.adk.agents.config_agent_utils.from_config関数 です。
ただし、AgentLoaderではAgentディレクトリ(Agentが置かれているPythonモジュール)に置かれている .envファイルの読み込み処理も行っています。 adk webなどの動作と同様にしたい場合は.envファイルの読み込み処理も必要です。
AgentLoaderの場合は google.adk.cli.utils.envs.load_dotenv_for_agentを利用して.envの読み込みを行っています。

実際のサンプルコードが以下です。

agent_config_runner.py
from google.adk.runners import InMemoryRunner
from google.adk.agents import config_agent_utils
from google.adk.cli.utils import envs
from google.genai import types

async def main():

    # agent directory内の .env を読み込み
    envs.load_dotenv_for_agent("agent_config", "./")

    # agent configの読み込み
    agent = config_agent_utils.from_config("./agent_config/root_agent.yaml") # agent yamlのpathを指定

    runner = InMemoryRunner(agent=agent, app_name="test")
    await runner.session_service.create_session(app_name="test", user_id="user_id", session_id="session")
    for event in runner.run(user_id="user_id", session_id="session", new_message=types.UserContent(parts="こんにちは")):
        if event.is_final_response():
            print(event.content.parts[0].text)

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

Agent Configのシンタックス & チートシート

上記まででAgent Configがどのような機能か理解できたかと思いますが、ここからはAgent Configで今まで書いてきたAgentをどのように書いていけばよいか書いていきます。

なお実際に動いているサンプルを見たい場合はADKのサンプルリポジトリを見るとよいでしょう。

https://github.com/search?q=repo%3Agoogle%2Fadk-python+path%3A%2F^contributing\%2Fsamples\%2F%2F+root_agent.yaml&type=code

Agent Configのシンタックスは以下で参照できます。

https://google.github.io/adk-docs/api-reference/agentconfig/

ただ個人的にはAPIリファレンスが読みにくいので、
とりあえず使いそうなパターンを網羅したチートシートを作成してみました。

チートシート

# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json

# This is an Agent Config Cheat Sheet

# 最もシンプルなAgent
name: root_agent
instruction: Answer user questions to the best of your knowledge
model: gemini-2.5-flash

---
# ツールなどを持たないLlmAgentのフルパターン 基本的に設定できるパラメータはLlmAgentのパラメータと同じ
name: full_llm_agent
description: Agentの説明
instruction: システム指示
model: gemini-2.5-flash
generate_content_config: # GenerateContentConfigも設定可能
  temperature: 0.1
  frequencyPenalty: -1
disallow_transfer_to_parent: true
disallow_transfer_to_peers: true
output_key: "state.key.name"
# input_schema、output_schemaのようなPythonのクラスや関数を指定しているプロパティでは CodeConfig というスキーマ形式で指定する
# 基本的には name プロパティに対象Pythonリソースのフルパス、後述しますが nameに関数を指定している場合 args プロパティも指定できる argsプロパティは CodeConfigの配列形式
output_schema:
  name: mymodule.schema.PydanticOutputModel
input_schema:
  name: mymodule.schema.PydanticInputModel
include_contents: default
---
# ツールの利用
name: tool_agent
description: Agent Configでtoolを利用する場合
instruction: システム指示
model: gemini-2.5-flash
# toolsプロパティを配列で指定する 設定するのは 上記のCodeConfig形式
tools:
  # 独自関数の場合
  - name: mymodule.tools.mytool.now_tool

  # adkのbuild-in tools
  - name: google_search
  - name: load_artifacts
  - name: url_context
  - name: exit_loop
  - name: preload_memory
  - name: get_user_choice
  - name: enterprise_web_search
  - name: load_web_page
    args:
      url: "https://www.google.com"

  # LongRunningFunctionTool
  - name: LongRunningFunctionTool
    args:
      func: mymodule.tools.mytool.long_running_tool

  # Agent Tool
  - name: AgentTool
    args:
      agent:
        # Agentが引数になる場合 AgentRefConfig 型を指定する
        # AgentRefConfigは AgentConfigのパスを設定する config_path プロパティ または agentインスタンスのフルパスを指定する code プロパティを設定する
        config_path: ./web_search_agent.yaml
      skip_summarization: False
  - name: AgentTool
    args:
      agent:
        code: mymodule.agents.root_agent
      skip_summarization: False
  # MCP
  - name: MCPToolset
    args:
      # MCPを設定する場合はPythonコード同様に MCPToolset を指定し、MCPToolsetの引数を設定する
      stdio_server_params:
        command: "npx"
        args:
          - "-y"
          - "@notionhq/notion-mcp-server"
        env:
          OPENAPI_MCP_HEADERS: "{'Authorization': 'Bearer fake_notion_api_key', 'Notion-Version': '2022-06-28'}"
  # その他 VertexAiSearchTool、CrewaiTool、LangchainTool、ExampleToolは利用できる
  # LangGraphAgent と A2aAgentは未対応
---
name: callback_agent
description: Agent Configでcallbackを利用する場合
instruction: システム指示
model: gemini-2.5-flash
# *_callbacksプロパティを配列で指定する 設定するのは 上記のCodeConfig形式
before_agent_callbacks:
  - name: mymodule.callbacks.before_agent_callback1
  - name: mymodule.callbacks.before_agent_callback2
  - name: mymodule.callbacks.before_agent_callback3
after_agent_callbacks:
  - name: mymodule.callbacks.after_agent_callback1
  - name: mymodule.callbacks.after_agent_callback2
  - name: mymodule.callbacks.after_agent_callback3
before_model_callbacks:
  - name: mymodule.callbacks.before_model_callback
after_model_callbacks:
  - name: mymodule.callbacks.after_model_callback
before_tool_callbacks:
  - name: mymodule.callbacks.before_tool_callback1
  - name: mymodule.callbacks.before_tool_callback2
  - name: mymodule.callbacks.before_tool_callback3
after_tool_callbacks:
  - name: mymodule.callbacks.after_tool_callback1
  - name: mymodule.callbacks.after_tool_callback2
  - name: mymodule.callbacks.after_tool_callback3

---
# Sub Agents
name: parent_agent
model: gemini-2.0-flash
description: Root Agent
instruction: instruction

# sub_agentsにAgentRefConfig 型の配列を指定する
sub_agents:
  # Agent Configの場合は config_path
  - config_path: ./work_agent.yaml
  # Pythonの場合は code を設定
  - code: sub_agents_config.life_agent.agent

---
# Workflow Agent等LlmAgent以外のAgentクラスを利用する場合は agent_class を指定する
# Workflow Agent: Sequential Agent
agent_class: SequentialAgent
name: sequential_agent
description: Sequential Agent
sub_agents:
  - config_path: sub_agents/code_writer_agent.yaml
  - config_path: sub_agents/code_reviewer_agent.yaml
  - config_path: sub_agents/code_refactorer_agent.yaml

---
# Workflow Agent: Loop Agent
agent_class: LoopAgent
name: RefinementLoop
description: Refinement loop agent.
max_iterations: 5
sub_agents:
  - config_path: writer_agents/critic_agent.yaml
  - config_path: writer_agents/refiner_agent.yaml

---
# Workflow Agent: Parallel Agent
agent_class: ParallelAgent
name: parallel_agent
description: 並列処理
sub_agents:
  - config_path: agent1.yaml
  - config_path: agent2.yaml
---
# Workflow Agent: Base Agent
# BaseAgentを継承していれば独自クラスも利用可能
agent_class: mymodule.agents.SemaphoreParallelAgent
name: parallel_agent
description: 並列処理
# 独自クラスの場合は任意のpydantic fieldも設定できる
concurrency: 10
sub_agents:
  - config_path: agent3.yaml
  - config_path: agent4.yaml

Agent Configの制約

ここまででAgent Configの利点を理解していただけたと思いますが、
Agent Configはまだ実験的な機能であり制約も存在します。

Agent Configの制約

  • 利用できるモデルはGeminiのみ
  • Pythonでのみ利用可能
  • build-in tools/Toolクラスで利用できるものが限られる

特に利用可能なモデルがGeminiのみなのは大きな制約なので、今後の更新に期待したいです。

まとめ

今回は 1.12.0で追加されたAgent Configについて解説しました。
YAMLでAI Agentを構築できるようになり非常にコードレスで開発が可能になりました。
そのうちUIツールなどで構築できるようになったり、Agent EngineへのAgentの作成がUIのみで完結できるようになりそうですね。


お知らせ/宣伝

先日、ADKユーザー向けのイベント「ADK UG #0」が開催され、ADK開発者が集う日本語のDiscordコミュニティが誕生しました。ADKに関する情報交換や議論に興味がある方は、ぜひご参加ください!

https://discord.gg/BKpGRzjtqZ

また、ADKの最新のコミットログやリリースノートを分かりやすく解説するPodcastを、月・水・金に配信しています。ADKの動向を追いかけたい方は、ぜひ聴いてみてください。

https://www.youtube.com/playlist?list=PL0Zc2RFDZsM_MkHOzWNJpaT4EH5fQxA8n

Discussion