2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Web操作AI Agent専用モデル Gemini 2.5 Computer Useについて

Last updated at Posted at 2025-12-15

image.jpeg

はじめに

この記事を読んで分かること

  • Gemini 2.5 Computer Useを使ったAIエージェントの仕組み、実装のポイント
  • Gemini 2.5 Computer UseとClaude computer useの違い

想定読者

  • AIエージェントまたはClaude computer useの仕組みについて理解している
  • Gemini 2.5 Computer Useの概要を知りたい

Gemini 2.5 Computer Use とは

2025年10月にGemini 2.5 Computer Useが登場しました。以下のとおり、Gemini2.5 ProをベースとしたUIを操作するAIエージェント用のモデルです。

Today, we are releasing the Gemini 2.5 Computer Use model, our new specialized model built on Gemini 2.5 Pro’s visual understanding and reasoning capabilities that powers agents capable of interacting with user interfaces (UIs)

Googleの発表では、Online-Mind2WebやWebVoyagerといったWeb操作AIエージェントのパフォーマンスを評価するベンチマークにおいて、他社のモデルよりもよいスコアを示しています。

image.png

一方でOSWorldのレコードで示されているように、他社のモデルとは違いGemini 2.5 Computer UseではOS制御はサポートされていません。 つまり、Webブラウザ操作に特化したモデルと言えます。

Gemini 2.5 Computer Useの使い方

名前が似たものとしてClaude computer useがありますが、Claude computer useは以下のとおりAIエージェントにおけるツールに該当します。

Claude can interact with computer environments through the computer use tool, which provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.

Gemini 2.5 Computer Useは先述した通りAIエージェント用のモデルのため、Webブラウザを操作するためのツールは別途用意する必要があります。用意されているサンプルコードではPlaywrightが使用されていますが、一般的にWeb操作の自動化で使用される以下のようなツールも利用可能です。

  • Cypress
  • Selenium
  • Puppeteer など

AIエージェントにおけるツールの実装に柔軟性がある点は、Claude computer useとの大きな違いとなります。

Gemini 2.5 Computer Useを使ったAIエージェントのデモ環境がBrowserbaseでも提供されており、プロンプトを与えるだけでどのようにWebブラウザが操作されるのかを確認できます。

「明日の天気は?」というプロンプトを与えると、自律的に「明日の天気予報」で検索 → Weather Newsのページにアクセスという操作を行い、ページの内容をもとに天気予報を回答してくれました。

image.png

image.png

Webブラウザ操作エージェント実装のポイント

Gemini 2.5 Computer Useを使った実際のAIエージェントの実装について、公式ドキュメントの説明をもとに整理してみました。以下の3つのポイントに沿ってご紹介します。

  • エージェントループ
  • ツールの実装
  • 内部安全システム

なお、Geminiのモデルを利用するためにGen AI SDKが利用できますが、現在Gemini 2.5 Computer Useはプレビュー中のためPythonのみがサポートされています。

エージェントループ

Gemini 2.5 Computer Useを使ったAIエージェントでは、基本的にタスクを完了するまで以下の処理をループします。

  1. ユーザー:AIエージェントにプロンプトを与える ※初回のみ
  2. AIエージェント:ツールを使ってスクリーンショットを撮影
  3. AIエージェント:スクリーンショットを含めたコンテキストをモデル (Gemini 2.5 Claude Use) に送信
  4. モデル:次のアクションをAIエージェントに回答
  5. AIエージェント:モデルの回答をもとにツールを使用
  6. 2.に戻る

Webブラウザを操作するにあたって、プロンプトやこれまでの実行履歴だけでなくスクリーンショット(画像)を使ってコンテキストを把握するという点が特徴的です。なお、タスクの完了は 4. AIエージェント:モデルの回答をもとにツールを使用 のタイミングで判断します。

Gemini 2.5 Claude Useが返却するレスポンスのうち、function_call で次のアクションが示されます。function_call が空の状態であればタスクが完了した(=次のアクションはない)と解釈できるため、AIエージェント側で function_call をチェックすることでタスクの完了を判断できます。

レスポンスの例:

{
  "content": {
    "parts": [
      {
        "text": "I have evaluated step 2. It seems Google detected unusual traffic and is asking me to verify I'm not a robot. I need to click the 'I'm not a robot' checkbox located near the top left (y=98, x=95).",
      },
      {
        "function_call": {
          "name": "click_at",
          "args": {
            "x": 60,
            "y": 100,
            "safety_decision": {
              "explanation": "I have encountered a CAPTCHA challenge that requires interaction. I need you to complete the challenge by clicking the 'I'm not a robot' checkbox and any subsequent verification steps.",
              "decision": "require_confirmation"
            }
          }
        }
      }
    ]
  }
}

ツールの実装

function_call で表現されるアクションは、以下のような基本的なWeb操作を含めて現在13種類がサポートされています。他のアクションについては公式ドキュメントをご参照ください。

説明
open_web_browser ブラウザを開く
search デフォルトの検索エンジンを使って検索
click_at 特定の座標をクリック
type_text_at 特定の座標にテキストを入力
scroll_document ウェブページ全体をスクロール

先述したとおり、Gemini 2.5 Computer Use自身にはWebブラウザを操作する機能はありません。そのため、これらのアクションに対応するツールは自分で実装する必要があります。

open_web_browser, click_at, type_text_at については、公式ドキュメントにサンプルがありますが、実際に動かす場合はサポートされているアクションについてそれぞれ実装が必要です。

ツールの実装例
from typing import Any, List, Tuple
import time

def denormalize_x(x: int, screen_width: int) -> int:
    """Convert normalized x coordinate (0-1000) to actual pixel coordinate."""
    return int(x / 1000 * screen_width)

def denormalize_y(y: int, screen_height: int) -> int:
    """Convert normalized y coordinate (0-1000) to actual pixel coordinate."""
    return int(y / 1000 * screen_height)

def execute_function_calls(candidate, page, screen_width, screen_height):
    results = []
    function_calls = []
    for part in candidate.content.parts:
        if part.function_call:
            function_calls.append(part.function_call)

    for function_call in function_calls:
        action_result = {}
        fname = function_call.name
        args = function_call.args
        print(f"  -> Executing: {fname}")

        try:
            if fname == "open_web_browser":
                pass # Already open
            elif fname == "click_at":
                actual_x = denormalize_x(args["x"], screen_width)
                actual_y = denormalize_y(args["y"], screen_height)
                page.mouse.click(actual_x, actual_y)
            elif fname == "type_text_at":
                actual_x = denormalize_x(args["x"], screen_width)
                actual_y = denormalize_y(args["y"], screen_height)
                text = args["text"]
                press_enter = args.get("press_enter", False)

                page.mouse.click(actual_x, actual_y)
                # Simple clear (Command+A, Backspace for Mac)
                page.keyboard.press("Meta+A")
                page.keyboard.press("Backspace")
                page.keyboard.type(text)
                if press_enter:
                    page.keyboard.press("Enter")
            else:
                print(f"Warning: Unimplemented or custom function {fname}")

            # Wait for potential navigations/renders
            page.wait_for_load_state(timeout=5000)
            time.sleep(1)

        except Exception as e:
            print(f"Error executing {fname}: {e}")
            action_result = {"error": str(e)}

        results.append((fname, action_result))

    return results

内部安全システム

基本的にタスクが完了するまでは function_call で返却されるアクションを自律的に実行しますが、Gemini 2.5 Computer Useからリスクの高い操作が提案された場合、処理が中断されます。

リスクの高い操作としては、ファイルのアップロードや購買処理などがあります。Gemini 2.5 Computer Useには、内部安全システムが組み込まれており、Gemini 2.5 Computer Useが提案するアクションやそのコンテキストを自動で評価しています。評価結果は function_callsafety_decision に含まれ、以下の値を返します。

  • 安全な場合:
    Regular / allowed / safety_decisionのフィールドが存在しない
  • リスクが高い場合:
    require_confirmation

safety_decisionrequire_confirmation の場合、AIエージェントのループは停止され、ユーザーにそのアクションを実行するか確認を行ないます。人間の承認なしに高リスクと判断されたアクションを実行することは、利用規約に基づき許可されていません*

まとめ

Gemini 2.5 Computer UseはWebブラウザ操作に特化したAIエージェント向けモデルであり、柔軟なツール設計と内部安全システムによるセキュアな自動化を実現できます。
サンプルコードを動したらまた記事にしたいと思います。

2025/12/26 追記 ▶ サンプルコード動かしてみました!

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?