ガイド
CapSolver AI
Agentツール

# エージェント

CapSolver の解決機能を LLM / エージェント フレームワークに組み込みます。 capsolver-agentcapsolver-core エンジン上の薄い層です。コアの solve / detect / solve_on_page メソッドを LLM が呼び出すことができるツールとしてラップし、「モデルが決定し、コアが実行する」境界が自然に定位置に収まるようにします。

分業: モデルはナビゲーションと意思決定を処理し、capsolver-core は解決を処理し、capsolver-agent はその間のツール アダプター層です。モデルは、CAPTCHA 自体をクリックすることなく、「クリック」または「入力」を呼び出すのと同じ方法で「解決」を呼び出します。

1. capsolver-agentcapsolver-core の関係

コア呼び出しコードを直接記述することはほとんどありません。 LLM がツールの呼び出しを決定すると、エージェント層のエグゼキューターが対応するコア メソッドを呼び出し、構造化された結果をモデルに返します。

LLM (decides)
   │  emits a tool call, e.g. solve_captcha(...)

capsolver-agent (schema + executor)   ← tool-adapter layer
   │  executor.execute(...) internally relays to ↓

capsolver-core (solve / detect / solve_on_page)


CapSolver API

各エージェント ツールは 1 つのコア メソッドに直接マップされます。これは、コアがあらゆるシナリオで実際の作業を行う場所です。

エージェントツール基礎となる capsolver-core メソッドブラウザ?
solve_captchacap.solve(info)いいえ
detect_captchascap.detect(page)はい
solve_on_pagecap.solve_on_page(page)はい
get_balancecap.get_balance()いいえ
get_supported_captchascap.get_supported_captchas()いいえ

2. インストール

capsolver-agentcapsolver-core の上に構築され (コアが解決を行います)、実行時にそれに依存します。どちらも GitHub 上のオープンソースであり、まだ PyPI には公開されておらず、capsolver-agent は名前が capsolver-core に依存しています。最初にコアをインストールし、次にエージェントをインストールします。

# 1) Install the core engine first (agent depends on it)
pip install git+https://github.com/capsolver-ai/capsolver-core.git
 
# 2) Then install agent itself
pip install git+https://github.com/capsolver-ai/capsolver-agent.git

必要に応じて追加機能を追加します。

# With LangChain support
pip install "capsolver-agent[langchain] @ git+https://github.com/capsolver-ai/capsolver-agent.git"
# With Playwright (detect / solve_on_page)
pip install "capsolver-agent[browser] @ git+https://github.com/capsolver-ai/capsolver-agent.git"
export CAPSOLVER_API_KEY="your-capsolver-api-key"

3. 使用法: 会話ループへの解決の配線

統合はモデルの「会話 – ツール」ループ内に収まります。 1 ラウンドは次のように実行されます。

1. Hand the tools to the model ───────────────────┐
2. The model answers and decides: do I need a tool here?
   ├─ No  → return the final answer, done         │
   └─ Yes → return a tool_call                    │
3. You execute the call → relay to core → get a result
4. Feed the result back to the model ─────────────┘  back to step 2, next round

実際には、モデルが、どのツールを使用するかどうか、またどのツールを使用するかを決定します。あなたの仕事は、コアをこのループに接続することです。3 つのステップでコアを接続します。→ ツールをモデルに渡します。→ モデルがループ内で返す呼び出しを実行し、それらを作業ループにつなぎます。

3.1 コアの接続: エグゼキューターの作成

実際に解決するのは常に capsolver-coreCapsolver エンジンです。エージェント層は周囲に ToolExecutor を追加するだけです。内部的には Capsolver を保持し、モデルのツール呼び出しをエンジンの対応するメソッドにディスパッチし、戻り値を構造化された結果にラップします。以下では、まずこのラッパーがどのように組み立てられるかを示し、次に 1 行の省略表現を示します。

エグゼキュータがコアをロードする方法 詳細に記述すると 2 行で、最初の行でコアが作成されます。

from capsolver_core import Capsolver               # capsolver-core engine
from capsolver_agent.schema import ToolExecutor
 
cap = Capsolver(api_key="YOUR_CAPSOLVER_KEY")       # the same Capsolver from the "Core SDK" page
executor = ToolExecutor(cap)                        # wrap a "tool call → core method" dispatcher around it

ディスパッチは固定マッピングです。すべてのツール呼び出しは最終的にコア メソッドに到達します。

executor.execute("solve_captcha",  {...})   # → cap.solve(CaptchaInfo(...))
executor.execute("detect_captchas", {...})  # → cap.detect(page)
executor.execute("get_balance",    {})      # → cap.get_balance()

呼び出しごとに、エグゼキューターはツールの引数をコアが期待する形式にアセンブルし、コアを呼び出し、結果 (またはエラー) をモデルに直接フィードバックできる dict にラップします。成功は {"success": True, "solution": {...}} 、失敗は {"success": False, "error": "..."} です。したがって、Core SDK ページで学習したメソッドとパラメーターは、ここでも変更せずに適用されます。

使用方法 上の 2 行には既製のラッパーがあります。日常的に使う場合は、次のように呼び出すだけです。

from capsolver_agent.schema import create_executor
 
executor = create_executor(api_key="YOUR_CAPSOLVER_KEY")   # == Capsolver(...) + ToolExecutor(...)

コアの動作をカスタマイズする場合、 create_executor() に渡された追加のキーワード引数は、そのまま Capsolver(...) に転送されます ( create_executor(api_key=..., default_timeout=180) など)。

3.2 モデルにツールを渡します

get_all_tools() は、すべてのツール定義、つまりコアの機能の外向きの説明を提供します。それらをターゲット フレームワークの形式でエクスポートし、関数呼び出しインターフェイスとしてモデルに渡します。

from capsolver_agent.schema import get_all_tools
 
tools = [t.to_openai_function() for t in get_all_tools()]
# to_openai_function() → {"type": "function", "function": {...}}, the format OpenAI's tools= expects
# you can also use t.to_json_schema() → an MCP-style tool description (name + inputSchema)

3.3 モデルが返す呼び出しを実行し、コアに中継します

モデルがあるステップで tool_call を返すと、それを 3.1 のエグゼキュータに渡します。execute(tool_name, args) は対応するコア メソッド (solve / detect / solve_on_page …) への呼び出しをディスパッチし、構造化された結果を返し、それをモデルにフィードバックします。

result = await executor.execute("solve_captcha", {
    "captcha_type": "reCaptchaV2",
    "website_url": "https://example.com",
    "website_key": "6Le-wvkSAAAAAPBMRT...",
})
# result → {"success": True, "solution": {"token": "03AF...", ...}}

3.4 完全なループに文字列化します。

上記の 3 つのステップをモデルの会話ループに埋め込むと、CAPTCHA を独自に解決する最小限のエージェントが作成されます (例として OpenAI 関数呼び出しを使用)。

import asyncio, json
from openai import OpenAI
from capsolver_agent.schema import get_all_tools, create_executor
 
client = OpenAI()                                       # your LLM client
executor = create_executor(api_key="YOUR_CAPSOLVER_KEY") # 3.1 connect core
tools = [t.to_openai_function() for t in get_all_tools()] # 3.2 hand tools to the model
 
async def run(prompt: str) -> str:
    messages = [{"role": "user", "content": prompt}]
    while True:
        resp = client.chat.completions.create(model="gpt-4o", messages=messages, tools=tools)
        msg = resp.choices[0].message
        messages.append(msg)
 
        if not msg.tool_calls:                          # model no longer calls a tool
            return msg.content                          # → final answer, exit the loop
 
        for call in msg.tool_calls:                     # model wants to call a tool
            result = await executor.execute(            # 3.3 execute → relay to core
                call.function.name,
                json.loads(call.function.arguments),
            )
            messages.append({                           # feed the result back, next round
                "role": "tool",
                "tool_call_id": call.id,
                "content": json.dumps(result),
            })
 
asyncio.run(run("Solve the reCAPTCHA v2 on https://example.com for me; the sitekey is 6Lc..."))

ループ全体を構築するのではなく、ツールを 1 回だけ実行したい場合は、シングルショットで execute_tool(name, args, api_key=...) を呼び出します。

4. フレームワークごと: 同じループ、異なるシェル

上記の 2 つのステップが普遍的なスケルトンです。特定のフレームワークに接続する場合、唯一の違いは、「ツールの呼び出し → 結果のフィードバック」ループを誰が実行するか、およびどのコア機能を使用するかです。既知のサイト パラメーターはトークン モード ( solve() ) を経由し、ページの自律的な駆動はブラウザ モード ( detect() / solve_on_page() ) を経由します。

シナリオ・フレームワーク使用されるコア機能統合方法サンプルファイル
OpenAI 関数呼び出しsolve() (トークンモード)ループを動かすのはあなたです: スキーマをモデルにフィードし、実行者がそれを実行します。openai_function_calling.py
OpenAI エージェント SDKsolve() などランタイムはループを駆動します。 @function_toolexecute_tool をラップします。openai_agents.py
ラングチェーン反応solve() など既製の BaseTool には get_langchain_tools() を使用します。langchain_agent.py
ブラウザの使用detect() / solve_on_page()@tools.action は解決をアクションとして登録します。browser_use_agent.py
劇作家 (LLM なし)detect() / solve_on_page()エージェント層をバイパスして、capsolver-core を直接使用します。playwright_sdk.py

このうち、ブラウザの使用は現実世界の自動化に最も近いです。エージェントは独自にブラウズし、タスクの途中で CAPTCHA に到達すると、解決をアクションとして呼び出します。同じブラウザ セッション内で検出、解決、埋め戻しを行い、結果が得られたら元のフローを中断することなく続行します。

Agent browses the page → hits a CAPTCHA → calls the solve action (core: solve_on_page) → gets a token → continues the task

5. サンプルの実行

上の表のすべてのシナリオには実行可能なサンプルが付属しており、すべてエージェント リポジトリの examples/ の下にあります。クローンを作成し、依存関係をインストールして、実行します。

git clone https://github.com/capsolver-ai/capsolver-agent.git
cd capsolver-agent
uv sync
 
export CAPSOLVER_API_KEY=CAP-XXXXXX
export OPENAI_API_KEY=sk-XXXXXX      # required by the LLM-based examples

各例の追加の依存関係 (capsolver-agent / capsolver-core は GitHub からインストールされます。残りは通常の PyPI パッケージです):

# OpenAI Function Calling
pip install openai
# OpenAI Agents SDK
pip install openai-agents
# LangChain
pip install "capsolver-agent[langchain] @ git+https://github.com/capsolver-ai/capsolver-agent.git" langchain-openai langgraph
# Browser Use
pip install browser-use langchain-openai playwright && playwright install chromium
# Playwright (no LLM)
pip install git+https://github.com/capsolver-ai/capsolver-core.git playwright && playwright install chromium