|
| 1 | +--- |
| 2 | +title: "AgentPhone Toolkit" |
| 3 | +description: "Integrate with the AgentPhone toolkit using LangChain Python." |
| 4 | +--- |
| 5 | + |
| 6 | +[AgentPhone](https://agentphone.to) is a telephony platform for AI agents. The `langchain-agentphone` package provides LangChain tools for sending messages, making AI-powered phone calls, managing phone numbers, and more. |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +### Integration details |
| 11 | + |
| 12 | +| Class | Package | Serializable | [JS support](https://js.langchain.com) | Version | |
| 13 | +|:------|:--------| :---: | :---: | :---: | |
| 14 | +| `AgentPhoneToolkit` | [`langchain-agentphone`](https://pypi.org/project/langchain-agentphone/) | ❌ | ❌ |  | |
| 15 | + |
| 16 | +### Available tools |
| 17 | + |
| 18 | +| Tool | Description | |
| 19 | +|:-----|:------------| |
| 20 | +| `AgentPhoneSendSMS` | Send a text message | |
| 21 | +| `AgentPhoneMakeCall` | Make an AI-powered outbound phone call | |
| 22 | +| `AgentPhoneGetTranscript` | Get the transcript of a phone call | |
| 23 | +| `AgentPhoneListCalls` | List phone calls with optional filters | |
| 24 | +| `AgentPhoneListConversations` | List conversations | |
| 25 | +| `AgentPhoneGetConversation` | Get a conversation with its messages | |
| 26 | +| `AgentPhoneBuyNumber` | Buy a new phone number | |
| 27 | +| `AgentPhoneListNumbers` | List phone numbers on the account | |
| 28 | +| `AgentPhoneCreateAgent` | Create a new AI phone agent | |
| 29 | +| `AgentPhoneListAgents` | List AI phone agents | |
| 30 | +| `AgentPhoneCreateContact` | Create a new contact | |
| 31 | +| `AgentPhoneListContacts` | List contacts | |
| 32 | + |
| 33 | +## Setup |
| 34 | + |
| 35 | +Install the package: |
| 36 | + |
| 37 | +```bash |
| 38 | +pip install -qU langchain-agentphone |
| 39 | +``` |
| 40 | + |
| 41 | +### Credentials |
| 42 | + |
| 43 | +You need an AgentPhone API key. Sign up at [agentphone.to](https://agentphone.to) to get one. |
| 44 | + |
| 45 | +```python |
| 46 | +import getpass |
| 47 | +import os |
| 48 | + |
| 49 | +if not os.environ.get("AGENTPHONE_API_KEY"): |
| 50 | + os.environ["AGENTPHONE_API_KEY"] = getpass.getpass("AgentPhone API key:\n") |
| 51 | +``` |
| 52 | + |
| 53 | +## Instantiation |
| 54 | + |
| 55 | +Use the toolkit to get all tools at once, or select specific ones: |
| 56 | + |
| 57 | +```python |
| 58 | +from langchain_agentphone import AgentPhoneToolkit |
| 59 | + |
| 60 | +# All tools |
| 61 | +toolkit = AgentPhoneToolkit() |
| 62 | +tools = toolkit.get_tools() |
| 63 | + |
| 64 | +# Or select specific tools |
| 65 | +toolkit = AgentPhoneToolkit(selected_tools=["send_sms", "list_numbers", "make_call"]) |
| 66 | +tools = toolkit.get_tools() |
| 67 | +``` |
| 68 | + |
| 69 | +You can also instantiate individual tools directly: |
| 70 | + |
| 71 | +```python |
| 72 | +from langchain_agentphone import AgentPhoneSendSMS, AgentPhoneListNumbers |
| 73 | + |
| 74 | +send_sms = AgentPhoneSendSMS() |
| 75 | +list_numbers = AgentPhoneListNumbers() |
| 76 | +``` |
| 77 | + |
| 78 | +## Invocation |
| 79 | + |
| 80 | +### Invoke directly with args |
| 81 | + |
| 82 | +```python |
| 83 | +from langchain_agentphone import AgentPhoneSendSMS |
| 84 | + |
| 85 | +tool = AgentPhoneSendSMS() |
| 86 | +result = tool.invoke({ |
| 87 | + "number_id": "num_abc123", |
| 88 | + "to_number": "+14155551234", |
| 89 | + "body": "Hello from LangChain!" |
| 90 | +}) |
| 91 | +print(result) |
| 92 | +``` |
| 93 | + |
| 94 | +### Invoke with ToolCall |
| 95 | + |
| 96 | +```python |
| 97 | +model_generated_tool_call = { |
| 98 | + "args": { |
| 99 | + "number_id": "num_abc123", |
| 100 | + "to_number": "+14155551234", |
| 101 | + "body": "Meeting at 3pm confirmed." |
| 102 | + }, |
| 103 | + "id": "1", |
| 104 | + "name": "agentphone_send_sms", |
| 105 | + "type": "tool_call", |
| 106 | +} |
| 107 | +tool_msg = tool.invoke(model_generated_tool_call) |
| 108 | +print(tool_msg.content) |
| 109 | +``` |
| 110 | + |
| 111 | +## Use within an agent |
| 112 | + |
| 113 | +```python |
| 114 | +from langchain_agentphone import AgentPhoneToolkit |
| 115 | +from langchain.chat_models import init_chat_model |
| 116 | +from langgraph.prebuilt import create_react_agent |
| 117 | + |
| 118 | +model = init_chat_model(model="claude-sonnet-4-6", model_provider="anthropic") |
| 119 | + |
| 120 | +toolkit = AgentPhoneToolkit( |
| 121 | + selected_tools=["send_sms", "list_numbers", "list_contacts"] |
| 122 | +) |
| 123 | +agent = create_react_agent(model, toolkit.get_tools()) |
| 124 | + |
| 125 | +response = agent.invoke({ |
| 126 | + "messages": [("user", "List my phone numbers, then send a message to +14155551234 saying 'Hello!'")] |
| 127 | +}) |
| 128 | +``` |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +## API reference |
| 133 | + |
| 134 | +For detailed documentation of the AgentPhone API, visit [docs.agentphone.to](https://docs.agentphone.to). |
0 commit comments