A LangChain tool to make a phone call
An agent built with LangChain can plan and search, but it cannot ring a supplier and ask what is on the shelf. Two plain Python functions around the HumanCalls REST API close that gap. One asks a real person to make the call. The other reads back typed answers, a summary, the cost and the recording.
Two functions, one call
The pattern is small. request_call sends a task to POST /v1/calls and returns the new task with its id. get_call_result reads GET /v1/calls/:id and returns the status, plus the answers once the call has finished. A person at HumanCalls dials the business during its local hours, asks your questions and writes down what they hear.
The code below uses only requests. Register each function with whatever tool decorator or tool class your framework version provides. The docstrings become the tool descriptions the model reads, so keep them plain and specific. Before you start, create a key with POST /v1/signup and have the owner verify their email. A verified workspace gets 10 free minutes. The developer docs cover signup in full.
Request a call
import os
import requests
API = 'https://humancalls.ai/v1'
KEY = os.environ['HUMANCALLS_API_KEY']
def request_call(to, business, on_behalf_of, goal, task_key,
collect=None, context=None, max_minutes=10):
"""Ask a real person to phone a US or Canadian business.
Returns the new call task, including its id and status."""
body = {
'to': to,
'business': business,
'on_behalf_of': on_behalf_of,
'goal': goal,
'max_minutes': max_minutes,
'delivery': {'mode': 'polling'},
}
if collect:
body['collect'] = collect
if context:
body['context'] = context
headers = {
'Authorization': f'Bearer {KEY}',
'Idempotency-Key': task_key,
}
r = requests.post(f'{API}/calls', json=body, headers=headers, timeout=30)
if r.status_code == 402:
return {'error': 'insufficient_credits',
'next': 'Lower max_minutes or ask the owner to top up.'}
if r.status_code == 403:
return {'error': 'account_not_verified_or_suspended'}
r.raise_for_status()
return r.json()Pass a task_key that belongs to the agent's job, not a fresh random value on every attempt. If the agent retries the same request, HumanCalls returns the existing task with a 200 instead of creating a second call. Reusing a key with a different body returns 409. New keys need delivery: {mode: 'polling'} unless you have set up a verified webhook connection, which is why it is in the body.
A 402 means no task was queued and nothing was held. A 429 means the account hit a creation limit; wait for the Retry-After header. Return these as plain messages so the agent can tell its user what happened.
Read the result
TERMINAL = {'completed', 'failed', 'no_answer', 'declined', 'canceled'}
def get_call_result(call_id):
"""Read a call task. Returns its status and, once finished,
the typed answers, summary, cost and media links."""
r = requests.get(f'{API}/calls/{call_id}',
headers={'Authorization': f'Bearer {KEY}'}, timeout=30)
r.raise_for_status()
call = r.json()
if call.get('status') not in TERMINAL:
return {'status': call.get('status'), 'done': False}
keys = ['status', 'outcome', 'outcome_notes', 'summary',
'billed_minutes', 'cost_usd', 'recording_url', 'transcript_url']
return {'done': True, **{k: call.get(k) for k in keys}}A task moves from queued to assigned, dialing and in progress, then ends as completed, failed, no_answer, declined or canceled. A call can come back in minutes or the next business morning, so let the agent check later rather than loop tightly. Recording and transcript links can arrive after the call completes. Poll again until they are present, and fetch them with the same bearer key.
Typed collect fields
The collect object tells your caller exactly what to find out and tells your code what shape the answers take. Field names are lower_snake_case, up to 25 per task.
| Type | Example field | Returned as |
|---|---|---|
| boolean | in_stock | true or false |
| number | unit_price | a number |
| date | delivery_date | a date |
| string | contact_name | text |
# Example data
collect = {
'in_stock': {'type': 'boolean', 'required': True},
'unit_price': {'type': 'number', 'description': 'Price per unit in USD'},
'delivery_date': {'type': 'date', 'description': 'Earliest delivery date'},
}
request_call(
to='+15125550142',
business='Harbor Supply Co.',
on_behalf_of='Acme Robotics',
goal='Confirm stock, unit price and earliest delivery for SKU 7712',
task_key='job-4821-harbor',
collect=collect,
)Answers come back in outcome. An optional field the business could not answer is null, and outcome_notes explains why. Treat null as unknown, not false. More on this in typed answers from phone calls.
Limits and cost
- Only US and Canadian business numbers. Calls happen during the business's local hours.
- Callers stay inside the goal. They do not buy, book or agree to anything you did not authorize.
- Sales, debt collection, political calls, cold calls to consumers and sensitive healthcare workflows are declined. See trust and process.
- $1 per connected minute, rounded up. Unanswered, declined and canceled calls cost $0, and reserved credit is released. Details on pricing.
The agent cannot buy credit. If the balance runs low, GET /v1/account returns a top_up_url for the owner to use.
Questions
- Is there a built-in LangChain tool for phone calls?
- This page does not rely on one. Two short Python functions around the REST API work with any framework that can call a function, and you register them with your version's tool helper.
- Is the caller an AI voice?
- No. A real, trained person makes every call. They say who they are and who they are calling for, and tell the business the call is recorded.
- Do I need a webhook?
- No. Pass
delivery: {mode: 'polling'}and have the agent read the task withget_call_result. Webhooks are optional and described in the docs. - Can I use MCP instead of wrapping the API?
- Yes, if your client supports MCP. Point it at https://humancalls.ai/mcp and it gets request_call, get_call and related tools. See the MCP integration.
Related
- A phone call tool for the OpenAI Agents SDKGive an agent built with the OpenAI Agents SDK a phone call tool. Connect its MCP support to HumanCalls, or wrap POST /v1/calls as a function tool.
- A phone call API with a human callerCreate phone calls by REST: POST /v1/calls with typed collect fields, and a real person calls the US or Canadian business. Poll or use a signed webhook.
- How to make an AI agent call a businessThree ways to make an AI agent phone a business: build a voice agent, hand the call to a person over an API, or do it yourself. Includes a worked example.
Try it with 10 free minutes
$1 per connected minute after that, and nothing when nobody picks up.