Skip to main content

langchain-plivo-tools

PyPI version Python versions License MIT CI

Plivo SMS and voice tools for LangChain agents. An agent sends text messages and places phone calls through Plivo.

Capability Detail
Send SMS An agent sends a text message and receives the Plivo message UUID
Place calls An agent dials a number, with optional text spoken when the call connects
Toolkit PlivoToolkit returns every tool the current configuration supports
Credentials Read from the environment or passed to the constructor, held as SecretStr

Requirements

Requirement Detail
Python 3.10 or later
Plivo account Auth ID and Auth Token from the Plivo console
Plivo number In E.164 format, enabled for SMS, voice, or both
Answer URL Required by PlivoMakeCall only. An endpoint returning Plivo XML, described under The Answer URL contract

Installation

pip install langchain-plivo-tools

Upgrading from 0.1.0

The two tool classes lost their Tool suffix in 0.2.0 to match the naming used across LangChain tool packages.

0.1.0 0.2.0
PlivoSendMessageTool PlivoSendMessage
PlivoMakeCallTool PlivoMakeCall

The old names still import and resolve to the renamed classes, raising a DeprecationWarning. They are scheduled for removal in 0.3.0. The tool names the model sees, plivo_send_message and plivo_make_call, are unchanged, so agent behaviour does not shift on upgrade.

Setup

Set the Plivo credentials as environment variables, or pass them to the tool directly.

export PLIVO_AUTH_ID="your-auth-id"
export PLIVO_AUTH_TOKEN="your-auth-token"
export PLIVO_FROM_NUMBER="+14155551234"

The Auth ID and Auth Token are on the Plivo console dashboard. The from number must be a Plivo phone number in E.164 format, enabled for SMS, voice, or both.

Send an SMS

from langchain_plivo_tools import PlivoSendMessage

tool = PlivoSendMessage()

tool.invoke({"body": "Your order has shipped.", "to": "+14155551234"})

Credentials can also be passed in code instead of the environment.

tool = PlivoSendMessage(
    auth_id="your-auth-id",
    auth_token="your-auth-token",
    from_number="+14155551234",
)

The tool returns the Plivo message UUID on success. Numbers use E.164 format.

Make a call

PlivoMakeCall places a phone call. Plivo answers the call by fetching an Answer URL that returns Plivo XML, so that endpoint has to be hosted separately. Its address goes in PLIVO_ANSWER_URL, alongside the credentials above, or is passed as answer_url to the tool.

from langchain_plivo_tools import PlivoMakeCall

tool = PlivoMakeCall()

tool.invoke({"to": "+14155551234", "message": "Your monitor is down."})

The Answer URL contract

When the call connects, Plivo fetches the Answer URL and expects a Plivo XML document in response. The URL is fetched with GET by default, because the optional message argument is appended to it as a message query parameter. The endpoint reads that parameter and returns XML that speaks it. A minimal response looks like this.

<Response><Speak>{message}</Speak></Response>

Invoking the tool with message="Your monitor is down." makes Plivo request the Answer URL with ?message=Your+monitor+is+down., and the endpoint returns this.

<Response><Speak>Your monitor is down.</Speak></Response>

To receive the parameters as a POST body instead, set the answer method to POST, either through the environment or on the tool.

export PLIVO_ANSWER_METHOD="POST"
tool = PlivoMakeCall(answer_method="POST")

The tool returns the Plivo request UUID on success.

Configuration

Every setting reads from an environment variable, and any of them can be overridden by passing the matching argument to the tool constructor.

Environment variable Constructor argument Used by Purpose
PLIVO_AUTH_ID auth_id both tools Plivo account Auth ID
PLIVO_AUTH_TOKEN auth_token both tools Plivo account Auth Token
PLIVO_FROM_NUMBER from_number both tools Plivo number that sends the SMS or places the call
PLIVO_ANSWER_URL answer_url PlivoMakeCall Endpoint that returns Plivo XML when the call connects
PLIVO_ANSWER_METHOD answer_method PlivoMakeCall HTTP method Plivo uses to fetch the Answer URL, defaults to GET

Using the tools with a LangChain agent

Both tools are standard LangChain tools, so they can be bound to a chat model or handed to an agent.

from langchain.chat_models import init_chat_model
from langgraph.prebuilt import create_react_agent

from langchain_plivo_tools import PlivoMakeCall, PlivoSendMessage

tools = [PlivoSendMessage(), PlivoMakeCall()]

model = init_chat_model("claude-sonnet-4-5-20250929", model_provider="anthropic")
agent = create_react_agent(model, tools)

result = agent.invoke(
    {
        "messages": [
            {
                "role": "user",
                "content": "Text +14155551234 to let them know their order shipped.",
            }
        ]
    }
)
print(result["messages"][-1].content)

Every tool at once with the toolkit

PlivoToolkit hands an agent all of the Plivo tools in one call, which keeps the agent setup unchanged as more tools are added to the package.

from langchain_plivo_tools import PlivoToolkit

agent = create_react_agent(model, PlivoToolkit().get_tools())

The toolkit reads the same environment variables as the individual tools, and any argument passed to it is forwarded to every tool that accepts one.

toolkit = PlivoToolkit(
    auth_id="your-auth-id",
    auth_token="your-auth-token",
    from_number="+14155551234",
    answer_url="https://example.com/answer",
)

A tool whose configuration is incomplete is left out of the returned list rather than raising, because an account that only sends SMS has no reason to set an Answer URL. Each omission raises a warning naming the missing setting, so a tool absent from an agent stays traceable. Nothing being configurable is an error.

# With credentials set but no PLIVO_ANSWER_URL:
PlivoToolkit().get_tools()
# UserWarning: Some Plivo tools are missing from the toolkit.
# PlivoMakeCall (Missing Plivo settings: PLIVO_ANSWER_URL. ...)
# -> [PlivoSendMessage()]

Security

  • The Auth Token is held as a SecretStr, keeping it out of repr() and log output
  • Credentials are read from the environment or passed to the constructor, and this package writes neither to disk
  • Both tools perform billable actions against a number the model supplies. No destination allowlist or rate limit is applied here, so those controls belong in the host application or in Plivo spend limits
  • The message argument reaches the Answer URL as a query parameter. An endpoint placing it into XML has to escape it first, because unescaped input can alter the XML document

Limitations

  • SMS only. MMS and WhatsApp are not covered
  • Number lookup and Verify are not included
  • PlivoMakeCall needs a separately hosted Answer URL, because Plivo does not speak text handed straight to the call API

Development

make install
make test
make lint

Integration tests place a real API call and run only when PLIVO_AUTH_ID, PLIVO_AUTH_TOKEN, PLIVO_FROM_NUMBER and PLIVO_TO_NUMBER are set. Calls also need PLIVO_ANSWER_URL.

make integration_test

License

This project is licensed under the MIT License. See LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_plivo_tools-0.2.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_plivo_tools-0.2.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file langchain_plivo_tools-0.2.0.tar.gz.

File metadata

  • Download URL: langchain_plivo_tools-0.2.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for langchain_plivo_tools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fd1f25c6e70f79a23acb9e22aa0ad6a59ccc8c68aa3094449ea98995315258cf
MD5 e8588f537332961afc2adb67e20963c0
BLAKE2b-256 6b1e4ec81e01c36e359623c4e388621b65bd40e62b85fb9939fa82b018c0395c

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_plivo_tools-0.2.0.tar.gz:

Publisher: release.yml on plivo-dev/langchain-plivo-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_plivo_tools-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_plivo_tools-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f5bd5b9b6dbddc42df41ec826faa811d1ac89d2a529695ba79af8908973e9a9
MD5 b7d16f8f2a490c6509772d18d758b48a
BLAKE2b-256 6313a56a2549c6dc5995919cc5603f137d05d69493f80d5fc29e6ca81b06b13a

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_plivo_tools-0.2.0-py3-none-any.whl:

Publisher: release.yml on plivo-dev/langchain-plivo-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page