AI and automation
How do LLMs call external tools and APIs?
Through tool calling. You describe each tool with a name, a purpose and a JSON schema for its arguments; the model replies with a request to call one; your program executes it and sends the result back to the model.
The short answer
A language model only produces text. To "use" an API, it produces a specially structured message that says which tool to call and with which arguments. Your application, not the model, makes the real HTTP request, then passes the response back as a new message. The model reads it and either calls another tool or writes its final answer. This loop is what agent frameworks automate, and the Model Context Protocol standardizes how tools are described and served to models.
The loop step by step
- Your app sends the conversation plus a list of tool definitions.
- The model decides a tool is needed and returns a tool call: the tool name and JSON arguments.
- Your app validates the arguments, runs the tool (an HTTP request, a database query, a browser action) and captures the result.
- Your app sends the result back as a tool result message linked to that call.
- The model continues, possibly calling more tools, until it returns a normal answer.
What a tool definition looks like
The exact wrapper differs between model providers, but the core is a JSON Schema. A tool that solves a reCAPTCHA v2 widget through GateSolver could be described like this:
{
"name": "solve_recaptcha_v2",
"description": "Get a reCAPTCHA v2 token for a page. Use only when the page shows a reCAPTCHA checkbox or invisible widget.",
"input_schema": {
"type": "object",
"properties": {
"page_url": { "type": "string", "description": "Full URL of the page with the widget" },
"site_key": { "type": "string", "description": "The data-sitekey value" },
"invisible": { "type": "boolean", "description": "True if there is no checkbox" }
},
"required": ["page_url", "site_key"]
}
}
The description matters as much as the schema: the model uses it to decide when the tool applies. Clear, narrow descriptions lead to fewer wrong calls.
The code side
When the model returns a call to solve_recaptcha_v2, your handler maps the arguments to an API request: it creates a ReCaptchaV2TaskProxyLess task with websiteURL and websiteKey, polls getTaskResult every three seconds, and returns the token (or a short error) as the tool result. The model never sees your API key, because the key lives in your handler. A complete Python version of such a tool is on building an agent tool for CAPTCHAs.
Frameworks and protocols
- Provider SDKs expose tool calling directly; you write the loop.
- Agent frameworks such as LangChain and the OpenAI Agents SDK run the loop and convert Python functions into tool definitions.
- MCP servers package tools behind a standard protocol so any compatible client can use them. You can write your own small MCP server that wraps an API; the MCP guide shows how to do that for GateSolver.
Design rules for good tools
- Keep secrets out of arguments. Keys and passwords belong in the handler, never in what the model sees or writes.
- Validate everything. Models produce malformed or invented values at times; check types, URLs and ranges before calling anything.
- Return compact results. Send the fields the model needs, not a full raw response, to save context and reduce confusion.
- Make errors readable. A short message like "site key missing" lets the model correct itself.
- Limit side effects. Tools that spend money or change data deserve confirmation steps or strict scopes.
Parallel and chained calls
Models can request several tool calls in one turn when the calls are independent, for example looking up two prices at once. Your loop should run them, return each result linked to its call id, and only then ask the model to continue. Long chains of dependent calls are where costs and errors grow, so give the model tools that do a meaningful unit of work each, rather than many tiny steps.
Why this matters for web automation
Browser agents use the same mechanism for every action: open a page, click, type, read. When they meet a challenge, a dedicated tool that returns a token is far more reliable than asking the model to interact with the widget, which is the problem discussed in can AI agents solve CAPTCHAs. Use such tools only for permitted automation, such as testing, accessibility and public data collection.
Common questions
Does the model make the HTTP request itself?
No. It outputs a structured tool call; your code performs the request and returns the result.
What format are tool arguments in?
JSON that matches the schema you provided for the tool.
Can the model see my API key?
It should not. Keep the key in your tool handler and never include it in prompts or tool results.
What is MCP in this context?
A protocol for packaging tools so different AI clients can discover and call them in the same way.
Does GateSolver ship its own MCP server?
No. You can write a small one that wraps the HTTP API, as our MCP guide shows.
Keep reading
- Model Context Protocol (MCP)The open protocol that lets AI assistants discover and call tools and data sources through a standard server interface.
- How do I give an AI agent a CAPTCHA tool?Wrap createTask and getTaskResult in one function with a clear schema, register it as a tool, and let the agent call it.
- MCP serverWrite your own small Python MCP server that gives any MCP client CAPTCHA solve and balance tools over the HTTP API.
- AI browser agentLanguage model driven programs that open pages, click and type in a real browser, and what happens when they reach a CAPTCHA.