An integration package connecting Plivo and LangChain
Project description
langchain-plivo-tools
This package connects Plivo to LangChain, so agents can send SMS messages and place voice calls through Plivo as tools.
Installation
pip install langchain-plivo-tools
Setup
Set your 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"
You can find the Auth ID and Auth Token on the Plivo console dashboard. The from number must be a Plivo phone number in E.164 format that is enabled for the service you are using, either SMS or voice.
Send an SMS
from langchain_plivo_tools import PlivoSendMessageTool
tool = PlivoSendMessageTool()
tool.invoke({"body": "Your order has shipped.", "to": "+14155551234"})
Credentials can also be passed in code instead of the environment.
tool = PlivoSendMessageTool(
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
PlivoMakeCallTool places a phone call. Plivo answers the call by fetching an Answer URL that returns Plivo XML, so you must host an endpoint that returns that XML and set PLIVO_ANSWER_URL in addition to the credentials above, or pass answer_url to the tool.
from langchain_plivo_tools import PlivoMakeCallTool
tool = PlivoMakeCallTool()
tool.invoke({"to": "+14155551234", "message": "Your monitor is down."})
The Answer URL contract
When the call connects, Plivo fetches your Answer URL and expects a Plivo XML document in response. By default the URL is fetched with GET, because the optional message you pass is appended to the Answer URL as a message query parameter. Your endpoint reads that parameter and returns XML that speaks it. A minimal response looks like this.
<Response><Speak>{message}</Speak></Response>
For example, when you invoke the tool with message="Your monitor is down.", Plivo requests your Answer URL with ?message=Your+monitor+is+down. and your endpoint should return this.
<Response><Speak>Your monitor is down.</Speak></Response>
To have your endpoint 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 = PlivoMakeCallTool(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 |
PlivoMakeCallTool |
Endpoint that returns Plivo XML when the call connects |
PLIVO_ANSWER_METHOD |
answer_method |
PlivoMakeCallTool |
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 you can bind them to a chat model or hand them to an agent.
from langchain.chat_models import init_chat_model
from langgraph.prebuilt import create_react_agent
from langchain_plivo_tools import PlivoMakeCallTool, PlivoSendMessageTool
tools = [PlivoSendMessageTool(), PlivoMakeCallTool()]
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)
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_plivo_tools-0.1.0.tar.gz.
File metadata
- Download URL: langchain_plivo_tools-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af4c28628cc253ef52e3f6fd02a0512e47321aeb4ab9ff1c1614dd6f528d37db
|
|
| MD5 |
4da31d132b8bda90ec2e883da849c97d
|
|
| BLAKE2b-256 |
91824c893c4ea01980760707844a952a76fae49845ca9824f5a58cc1b85c5883
|
Provenance
The following attestation bundles were made for langchain_plivo_tools-0.1.0.tar.gz:
Publisher:
release.yml on plivo-dev/langchain-plivo-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_plivo_tools-0.1.0.tar.gz -
Subject digest:
af4c28628cc253ef52e3f6fd02a0512e47321aeb4ab9ff1c1614dd6f528d37db - Sigstore transparency entry: 2291429702
- Sigstore integration time:
-
Permalink:
plivo-dev/langchain-plivo-tools@209cac7cd6a1b21c6bb6b8da7ef2e65f5a25286f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/plivo-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@209cac7cd6a1b21c6bb6b8da7ef2e65f5a25286f -
Trigger Event:
release
-
Statement type:
File details
Details for the file langchain_plivo_tools-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_plivo_tools-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c815ae8cd6106dbc73a7e02416e877c97344362a230dab99092cbf3357e6121
|
|
| MD5 |
96100530cdb1c5a8002f0f8171b82593
|
|
| BLAKE2b-256 |
299c0c0c1f57240c74cc84f8ab7a5b46f8c5d2fccf80178dcd0b8de9eccc8bcd
|
Provenance
The following attestation bundles were made for langchain_plivo_tools-0.1.0-py3-none-any.whl:
Publisher:
release.yml on plivo-dev/langchain-plivo-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_plivo_tools-0.1.0-py3-none-any.whl -
Subject digest:
0c815ae8cd6106dbc73a7e02416e877c97344362a230dab99092cbf3357e6121 - Sigstore transparency entry: 2291429732
- Sigstore integration time:
-
Permalink:
plivo-dev/langchain-plivo-tools@209cac7cd6a1b21c6bb6b8da7ef2e65f5a25286f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/plivo-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@209cac7cd6a1b21c6bb6b8da7ef2e65f5a25286f -
Trigger Event:
release
-
Statement type: