Langchain •agent runner


Agent Automation · LangChain
Add CapSolver to your LangChain agent — solve CAPTCHAs in one tool call
CapSolver Agent adds ready-made LangChain BaseTools via get_langchain_tools() to your ReAct or LangGraph agent. When a CAPTCHA appears, it calls the solver, gets a token, and continues—powered by a native SDK for LangChain, browser tooling, and MCP.
Agent CAPTCHA workflow
Detect
CAPTCHA or verification appears
Extract
URL, site key, metadata
Solve
CapSolver task
Return
Solution returned to the agent
Continue
Agent resumes the workflow
Add CAPTCHA solving to your LangChain agents
Built for agent loops
A LangChain CAPTCHA solver is useful when an agentic workflow touches real websites and can be stopped by traffic validation or CAPTCHA challenges.
Tool-native pattern
Expose CapSolver as a callable LangChain tool with clear inputs, so the agent can request CAPTCHA solving only when needed.
Production recovery
Handle retries, errors, request IDs, and timeouts without breaking the agent workflow.
Clear tool boundaries
Your agent controls the workflow. CapSolver handles the solving task and returns the result.
Why LangChain agents need CAPTCHA recovery in production
LangChain is designed for agents that take action through tools. In browser automation workflows this loop is often interrupted by reCAPTCHA or Cloudflare Turnstile. The right solution is not to turn CapSolver into an agent framework — it is to make CapSolver the agent-ready CAPTCHA infrastructure layer every real-world browser agent can call when needed.
Workflow Layer
Role in the LangChain workflow
What CapSolver adds
LangChain agent
Plans the task, selects tools, and maintains state.
A callable CAPTCHA recovery tool that can be invoked only when needed.
CapSolver API
Creates challenge-specific tasks and returns solutions.
Handles reCAPTCHA v2/v3, Cloudflare Challenge /Turnstile, and other supported challenges through the API.
Observability
Tracks tool calls, errors, and workflow status
CAPTCHA task IDs, challenge type, solve status, and error codes / retries.
Architecture
Keep responsibilities clear: LangChain orchestrates, CapSolver solves CAPTCHAs
Use CapSolver as a focused tool in your LangChain workflow. The agent provides the website URL, site key, and challenge details. The tool creates a task, checks the result, and returns the solution. LangChain manages the agent workflow, while CapSolver handles CAPTCHA solving.
Detect
A CAPTCHA challenge is present on the target page.
Extract
Collect websiteURL, websiteKey, and challenge type.
Create
Call CapSolver createTask with the correct task object.
Poll
Check getTaskResult until the task is ready or times out. Use retry delays for rate-limit errors.
Continue
The tool returns a structured token and the LangChain agent resumes the original task.
Observe
Record task ID, status, and error codes / retries.
Quick Start
Build a Python LangChain tool with the CapSolver API
Wrap CapSolver'screateTask+getTaskResultin one tool: structured info goes in, a structured result comes out. Polling uses a fixed interval with an overall timeout.
# pip install "capsolver-agent[langchain]" langchain-openai langgraph
# export CAPSOLVER_API_KEY=CAP-XXXXXX
# export OPENAI_API_KEY=sk-XXXXXX
import asyncio
import os
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from capsolver_agent.schema import create_executor
from _env import load_example_env # demo only: reads repo-root .env
load_example_env()
# 1. Wrap CapSolver as one LangChain tool.
# createTask + result polling are handled inside capsolver-agent.
executor = create_executor() # key from CAPSOLVER_API_KEY
@tool
async def solve_captcha(captcha_type: str, website_url: str, website_key: str) -> dict:
"""Solve a captcha (reCaptchaV2 / reCaptchaV3 / cloudflare) and return its token.
captcha_type: captcha family, e.g. reCaptchaV2
website_url: full URL of the page that loads the captcha
website_key: site key found on that page
"""
result = await executor.execute(
"solve_captcha",
{"captcha_type": captcha_type, "website_url": website_url, "website_key": website_key},
)
if not result.get("success"):
return {"ok": False, "error": result.get("error", "unknown error")}
return {"ok": True, "token": result["solution"]["token"]}
# 2. Any OpenAI-compatible chat model works; the LLM decides when to call the tool.
llm = ChatOpenAI(model=os.environ.get("OPENAI_MODEL", "gpt-4o"), temperature=0)
# 3. Give the tool to a ReAct agent.
agent = create_react_agent(llm, [solve_captcha])
# 4. Run.
PROMPT = (
"Solve the reCaptchaV2 at https://www.google.com/recaptcha/api2/demo "
"with site key 6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ- "
"and report the first 40 characters of the token."
)
result = asyncio.run(agent.ainvoke({"messages": [("user", PROMPT)]}))
print(result["messages"][-1].content)
Add the tools to a LangChain agent
get_langchain_tools()returns standard BaseTools that sit beside the browser, data extraction, or workflow tools your agent already uses.
# pip install "capsolver-agent[langchain]" langchain-openai langgraph
# export CAPSOLVER_API_KEY=CAP-XXXXXX
# export OPENAI_API_KEY=sk-XXXXXX
import asyncio
import os
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from capsolver_agent.langchain_tools import get_langchain_tools
from _env import load_example_env # demo only: reads repo-root .env
load_example_env()
# CapSolver's ready-made LangChain BaseTools, backed by capsolver-core:
# solve_captcha, detect_captchas, solve_on_page, get_balance, get_supported_captchas
tools = get_langchain_tools(api_key=os.environ["CAPSOLVER_API_KEY"])
llm = ChatOpenAI(model=os.environ.get("OPENAI_MODEL", "gpt-4o"), temperature=0)
# The solver tools sit beside the browser / data / workflow tools your agent already uses
agent = create_react_agent(llm, tools)
result = asyncio.run( # CapSolver tools are async, so use ainvoke
agent.ainvoke(
{
"messages": [
{
"role": "user",
"content": "Solve the reCaptchaV2 at "
"https://www.google.com/recaptcha/api2/demo with site key "
"6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ- and report the "
"first 40 characters of the token.",
}
]
}
)
)
print(result["messages"][-1].content)
and import the tools directly — no JavaScript or TypeScript package is required.
Production Best Practices
Build production-ready CAPTCHA solving for LangChain agents
01
Secret management
Store CAPSOLVER_API_KEY in environment variables or a secret manager.
Why
Prevents accidental key exposure in prompts, logs, and repositories.
02
Tool schema
Keep the tool input narrow and typed (website_url, website_key).
Why
Reduces model confusion and unsafe argument generation.
03
Detection
Read the challenge type and site key from the page context.
Why
The model should not guess page parameters from raw text.
04
Poll & retry
Check the task status at set intervals and stop after a timeout. Retry API errors with backoff.
Why
Prevents unnecessary load and runaway agent loops.
05
Logging
Record task_id, challenge type, status, and error codes / retries.
Why
Makes debugging and support easier.
06
Error handling
Stop repeated failures and send the task for human review when needed.
Why
Prevents blind retries on sensitive or uncertain workflows.
07
Compliance
Review site terms, user authorization, privacy requirements, and rate limits.
Why
Keeps automation aligned with approved use cases.
Ecosystem Fit
CapSolver works with your browser infrastructure—it does not replace it
01
Browserbase / Steel
02
Playwright / Puppeteer
03
LangChain / LangGraph
Primary job
Hosted browser execution and session management.
Browser control and DOM interaction.
Agent orchestration and tool use.
Without CapSolver
The browser session can keep running, but a CAPTCHA may stop the workflow.
The automation can detect and interact with the page, but it still needs CAPTCHA-solving logic.
The agent can call tools, but it has no built-in tool for solving CAPTCHAs.
With CapSolver
CapSolver handles the CAPTCHA task while the browser session stays active.
The automation sends the challenge data to CapSolver and uses the returned solution.
The agent calls CapSolver as a tool and continues the workflow with the result.
Best-Fit Use Cases
Built for B2B agent teams running browser workflows in production
Sales Automation
Authorized sales research and CRM workflows may encounter CAPTCHA or verification checks during browser tasks.
HR Technology
Approved recruiting workflows can pause when verification appears during multi-step browser tasks.
QA and Testing Tools
End-to-end tests for signup, checkout, and forms need clear CAPTCHA handling to reduce failed test runs.
RegTech and Compliance
Public registry checks and evidence collection workflows need reliability, audit logs, and clear fallback behavior.
Research Automation
Authorized public-data workflows may pause when a source shows a CAPTCHA or verification check.
Internal RPA
User-authorized repetitive workflows benefit from a clear CAPTCHA recovery layer when traffic validation blocks a task.
Responsible Use
Use CapSolver for lawful and authorized automation
CapSolver is intended for lawful and authorized uses, including approved QA testing, internal RPA, user-authorized agent tasks, and compliant public-data workflows. Before automating a website, review its terms, applicable privacy rules, rate limits, and your organization's compliance requirements.
Authorized QA testing
Approved RPA
Public data workflows
User-authorized agent tasks
Compliance-reviewed automation
E-commerce automation
FAQ
Related Integrations
Explore more CapSolver integrations for your agent stack
Choose another integration to add CAPTCHA solving to your agent or browser workflow.

If your LangChain agent works in demos but stalls in production, add a CAPTCHA recovery layer.
Start with the tool wrapper above, review the CapSolver documentation, and contact the team when you need enterprise support, higher volume, or a native SDK integration path.
