◉GEMINI LABEN
●ARGON — gemini-4-argon が 10/13 に GA。複雑なコーディング・エージェント・数学・科学向けです●DEEP RES — deep-research-pro-preview-12-2025 は 10/23 に停止、残り6日。移行先は deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 が GA(10/06)。gemini-3.1-flash-image は非推奨で停止日は未発表です●MCP — ツール結果が 8.5万トークンに膨らんだ事例を、ADK で 310 トークンに包んで抑えた報告が出ています●FLASH — gemini-3.7-flash と 3.5-flash は新しい Flash モデルに自動で回されます(10/08)●NEW — クラッシュ報告を毎回ゼロから読ませない — 既知バグ早見表を先に grep し…●ARGON — gemini-4-argon が 10/13 に GA。複雑なコーディング・エージェント・数学・科学向けです●DEEP RES — deep-research-pro-preview-12-2025 は 10/23 に停止、残り6日。移行先は deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 が GA(10/06)。gemini-3.1-flash-image は非推奨で停止日は未発表です●MCP — ツール結果が 8.5万トークンに膨らんだ事例を、ADK で 310 トークンに包んで抑えた報告が出ています●FLASH — gemini-3.7-flash と 3.5-flash は新しい Flash モデルに自動で回されます(10/08)●NEW — クラッシュ報告を毎回ゼロから読ませない — 既知バグ早見表を先に grep し…
記事一覧/高度な活用
⬡ 高度な活用/2026-03-30上級

Gemini Computer Use で構築する業務自動化ワークフロー — ブラウザ操作AIエージェントの設計と実装

Gemini 2.5 の Computer Use 機能を用いた業務自動化システムの実装方法を詳解。ブラウザ自動化、エージェント設計、エンタープライズ向けユースケース、安全性アーキテクチャ、本番運用パターンを網羅。

Gemini Computer Useブラウザ自動化Playwright業務自動化4AIエージェント4エンタープライズ5RPA

✦ プレミアム記事

AdMob の管理画面を巡回するスクリプトをセレクタ頼みで書いていた頃、ダッシュボードの UI が少し変わるたびにセレクタが壊れ、深夜にエラー通知が鳴る、という経験を何度も繰り返しました。Gemini 2.5 の Computer Use を最初に触ったとき、私が真っ先に確かめたかったのは、この「壊れやすさ」が本当に解消されるのかという 1 点でした。スクリーンショットを見て次の操作を推論するこのモデルは、セレクタ依存から解放される代わりに、座標のズレ・推論の揺れ・トークンコストという別種の不確実性を持ち込みます。その不確実性を本番運用で飼い慣らすための実装パターンを、実際に動かして初めて分かった注意点とあわせて順にご紹介します。

Gemini 2.5 Computer Use:概要と能力

Gemini 2.5 の Computer Use モデルは、画面を「見」、インタラクティブ要素を「操作」する能力を持ちます。これは従来の RPA(Robotic Process Automation)ツールと異なり、画像解析と深い推論を組み合わせることで、予測されない UI レイアウト変更にも対応できます。

コア能力

スクリーンショット認識: ページ全体の画像から、入力フィールド、ボタン、リンク、テーブルなど、インタラクティブ要素を識別します。OCR により、画面上のテキストも自動抽出されます。

座標ベースの操作: マウスクリック、テキスト入力、スクロール、ドラッグ操作を座標で実行します。座標システムは、ブラウザビューポート左上を原点とした相対座標です。

推論とコンテキスト理解: 複数フレームの画像履歴を参考に、現在のページ状態と実行すべき次のアクションを推論します。エラーやポップアップが出現した場合でも、自動的に対応策を選択します。

マルチステップ実行: 複数の操作を順序立てて実行し、各ステップの結果を次のアクション選択に反映します。

アーキテクチャの概念図

┌─────────────────────────────────────────┐
│   ユーザー指示                          │
│  「経費報告書を作成して submit して」    │
└────────────┬────────────────────────────┘
             │
             ▼
┌─────────────────────────────────────────┐
│ Gemini Computer Use エージェント        │
│ ├─ スクリーンショット取得              │
│ ├─ 画面解析・推論                      │
│ ├─ 操作を決定                          │
│ └─ 結果を評価                          │
└────────┬────────────────────────────────┘
         │
         ├─→ 操作1: ブラウザナビゲーション
         │
         ├─→ 操作2: フォーム入力
         │
         ├─→ 操作3: スクリーンショット評価
         │
         └─→ 操作N: 目標達成確認

API 実装:Computer Use Tool の統合

Gemini API から Computer Use を呼び出すには、専用の computer_use tool を定義します。

基本的な API 呼び出し

import Anthropic from "@anthropic-ai/sdk";
import * as fs from "fs";
import * as path from "path";
 
const client = new Anthropic();
 
interface ToolResult {
  type: "tool_result";
  tool_use_id: string;
  content: string;
}
 
interface ToolUse {
  type: "tool_use";
  id: string;
  name: string;
  input: Record<string, any>;
}
 
async function takeScreenshot(): Promise<string> {
  // Playwright または Puppeteer でスクリーンショット取得
  const screenshot = await page.screenshot({ encoding: "base64" });
  return screenshot;
}
 
async function executeComputerUseAgent(
  userInstruction: string
): Promise<string> {
  let messages: Anthropic.MessageParam[] = [
    {
      role: "user",
      content: userInstruction
    }
  ];
 
  let response = await client.messages.create({
    model: "claude-opus-4-1",  // Computer Use サポートモデル
    max_tokens: 4096,
    tools: [
      {
        name: "computer_use",
        description: "Use the computer to complete tasks",
        input_schema: {
          type: "object",
          properties: {
            action: {
              type: "string",
              enum: ["screenshot", "click", "type", "scroll", "drag"],
              description: "The action to perform"
            },
            coordinate: {
              type: "array",
              items: { type: "number" },
              description: "[x, y] coordinates for click/drag actions"
            },
            text: {
              type: "string",
              description: "Text to type"
            },
            direction: {
              type: "string",
              enum: ["up", "down", "left", "right"],
              description: "Scroll direction"
            },
            amount: {
              type: "number",
              description: "Scroll distance in pixels"
            },
            start_coordinate: {
              type: "array",
              items: { type: "number" },
              description: "Start coordinates for drag"
            },
            end_coordinate: {
              type: "array",
              items: { type: "number" },
              description: "End coordinates for drag"
            }
          },
          required: ["action"]
        }
      }
    ],
    system: `You are an AI assistant with the ability to control a computer. You can take screenshots and interact with web pages and applications using mouse clicks, keyboard input, scrolling, and dragging.
 
Always start by taking a screenshot to see the current state of the screen. Analyze what you see and determine the next action to fulfill the user's request.
 
When you encounter web forms, be careful to:
1. Identify all required fields
2. Fill them with appropriate data
3. Look for validation messages
4. Follow any multi-step processes
 
For complex tasks, break them down into smaller steps and execute them sequentially.`
  });
 
  // Agentic loop: tool use に対応
  while (response.stop_reason === "tool_use") {
    const assistantMessage = response.content;
    messages.push({ role: "assistant", content: assistantMessage });
 
    const toolResults: ToolResult[] = [];
 
    for (const block of assistantMessage) {
      if (block.type === "tool_use") {
        const toolUse = block as ToolUse;
 
        let result: string;
        switch (toolUse.input.action) {
          case "screenshot": {
            const screenshot = await takeScreenshot();
            result = `Screenshot taken:\n<image>\ndata:image/png;base64,${screenshot}\n</image>`;
            break;
          }
 
          case "click": {
            const [x, y] = toolUse.input.coordinate;
            await page.mouse.click(x, y);
            result = `Clicked at coordinates (${x}, ${y})`;
            break;
          }
 
          case "type": {
            await page.keyboard.type(toolUse.input.text);
            result = `Typed text: "${toolUse.input.text}"`;
            break;
          }
 
          case "scroll": {
            const direction = toolUse.input.direction;
            const amount = toolUse.input.amount || 300;
 
            if (direction === "down" || direction === "up") {
              await page.evaluate(
                (pixels: number) => window.scrollBy(0, pixels),
                direction === "down" ? amount : -amount
              );
            } else {
              await page.evaluate(
                (pixels: number) => window.scrollBy(pixels, 0),
                direction === "right" ? amount : -amount
              );
            }
            result = `Scrolled ${direction} by ${amount}px`;
            break;
          }
 
          case "drag": {
            const [startX, startY] = toolUse.input.start_coordinate;
            const [endX, endY] = toolUse.input.end_coordinate;
 
            await page.mouse.move(startX, startY);
            await page.mouse.down();
            await page.mouse.move(endX, endY);
            await page.mouse.up();
 
            result = `Dragged from (${startX}, ${startY}) to (${endX}, ${endY})`;
            break;
          }
 
          default:
            result = `Unknown action: ${toolUse.input.action}`;
        }
 
        toolResults.push({
          type: "tool_result",
          tool_use_id: toolUse.id,
          content: result
        });
      }
    }
 
    messages.push({
      role: "user",
      content: toolResults
    });
 
    // 次のレスポンスを取得
    response = await client.messages.create({
      model: "claude-opus-4-1",
      max_tokens: 4096,
      tools: [
        {
          name: "computer_use",
          description: "Use the computer to complete tasks",
          input_schema: {
            // 前述と同じ
          }
        }
      ],
      messages
    });
  }
 
  // 最終結果を抽出
  const finalText = response.content
    .filter((block) => block.type === "text")
    .map((block) => (block as any).text)
    .join("\n");
 
  return finalText;
}
✦

ここまでお読みいただきありがとうございます。

この記事の続きを読む

この先には、実装コードやベンチマーク結果など、実務でお役に立てる内容をご用意しています。このサイトは広告を掲載しておらず、サーバーや開発にかかる費用はメンバーの皆様のご支援で成り立っています。もしお役に立てていましたら、ご支援いただけますと大変ありがたいです。

この記事で得られること
✦セレクタ依存の RPA から Computer Use へ移行する際、最初に必ずぶつかる座標ズレ(DPR)を正規化する実コード
✦スクリーンショット解像度とトークンコスト・クリック精度の実測トレードオフ(768px 幅で約40%削減)
✦破壊的操作をモデルの判断任せにしないための allowlist ゲートと、毎ステップの遷移検証チェックリスト
Stripe による安全な決済 · いつでもキャンセル可能
✦

この記事を購入する

この先の内容をすべてお読みいただけます。一度のご購入で、いつでも何度でもアクセスできます。このサイトは広告を掲載しておらず、皆さまのご支援がサーバー費用などの運営を支えています。

または
メンバーシップなら全記事が読み放題 →
シェア

お読みいただきありがとうございます

Gemini Lab は広告なしで運営しており、サーバー費用などの運営コストはメンバーシップのご支援で賄っています。実装コード・ベンチマーク・本番設計パターンなど、実務でお役立ていただける記事を毎日更新しています。もし読んでよかったと感じていただけましたら、ぜひご覧ください。

  • ✦コピー&ペーストで使える実装コード付き
  • ✦毎日新しい上級ガイドを追加
  • ✦¥580/月 または ¥1,480 の永久アクセス
メンバーシップを見る →

関連記事

⬡ 高度な活用2026-10-14
PC では直るのに Safari でだけ画像が読み込まれない — AI に診断を頼む前に、手元で揃えておく 4 つの材料
並べ替えのあとで画像が二度と読み込まれない不具合が、iPhone の Safari でだけ起きました。PC のブラウザでは再現しない不具合を Gemini などの AI に診断してもらうとき、先に手元で揃えておく材料と、そのまま使える依頼文をまとめます。
⬡ 高度な活用2026-10-10
家計や健康の相談を履歴に残さない — Gemini の一時チャットと設定を確認する順番
家計の見直しや体調の相談を Gemini に持ちかける前に、一時チャットと「アクティビティ」設定をどの順で確かめればよいかを整理しました。残す話と残さない話を、ご自身で選べるようになるための最初の一歩です。
⬡ 高度な活用2026-09-24
Gemini に「合っていますか」と聞くのをやめ、答えを伏せたまま分類し直してもらう設計に変えました
自分で付けたラベルの確認を Gemini に頼むと、頷く答えが返りがちです。確認型・反論指示型・伏せ型の三つを比べて伏せ型を選んだ理由と、答えが漏れる経路の塞ぎ方、食い違いだけを人が見る振り分けのコードまで書き残します。