> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AgentPhone 工具包

> 使用 LangChain Python 集成 AgentPhone 工具包。

[AgentPhone](https://agentphone.to) 是一个面向 AI 代理的电话平台。`langchain-agentphone` 包提供了 LangChain 工具，用于发送消息、进行 AI 驱动的电话呼叫、管理电话号码等。

## 概述

### 集成详情

| 类                   | 包                                                                        | 可序列化 | [JS 支持](https://js.langchain.com) |                                                 版本                                                 |
| :------------------ | :----------------------------------------------------------------------- | :--: | :-------------------------------: | :------------------------------------------------------------------------------------------------: |
| `AgentPhoneToolkit` | [`langchain-agentphone`](https://pypi.org/project/langchain-agentphone/) |   ❌  |                 ❌                 | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-agentphone?style=flat-square\&label=%20) |

### 可用工具

| 工具                            | 描述             |
| :---------------------------- | :------------- |
| `AgentPhoneSendSMS`           | 发送短信           |
| `AgentPhoneMakeCall`          | 进行 AI 驱动的外呼电话  |
| `AgentPhoneGetTranscript`     | 获取电话通话记录       |
| `AgentPhoneListCalls`         | 列出电话通话，支持可选过滤器 |
| `AgentPhoneListConversations` | 列出对话           |
| `AgentPhoneGetConversation`   | 获取对话及其消息       |
| `AgentPhoneBuyNumber`         | 购买新电话号码        |
| `AgentPhoneListNumbers`       | 列出账户上的电话号码     |
| `AgentPhoneCreateAgent`       | 创建新的 AI 电话代理   |
| `AgentPhoneListAgents`        | 列出 AI 电话代理     |
| `AgentPhoneCreateContact`     | 创建新联系人         |
| `AgentPhoneListContacts`      | 列出联系人          |

## 设置

安装包：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU langchain-agentphone
```

### 凭证

您需要一个 AgentPhone API 密钥。请在 [agentphone.to](https://agentphone.to) 注册以获取。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import getpass
import os

if not os.environ.get("AGENTPHONE_API_KEY"):
    os.environ["AGENTPHONE_API_KEY"] = getpass.getpass("AgentPhone API key:\n")
```

## 实例化

使用工具包一次性获取所有工具，或选择特定工具：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_agentphone import AgentPhoneToolkit

# 所有工具
toolkit = AgentPhoneToolkit()
tools = toolkit.get_tools()

# 或选择特定工具
toolkit = AgentPhoneToolkit(selected_tools=["send_sms", "list_numbers", "make_call"])
tools = toolkit.get_tools()
```

您也可以直接实例化单个工具：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_agentphone import AgentPhoneSendSMS, AgentPhoneListNumbers

send_sms = AgentPhoneSendSMS()
list_numbers = AgentPhoneListNumbers()
```

## 调用

### 使用参数直接调用

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_agentphone import AgentPhoneSendSMS

tool = AgentPhoneSendSMS()
result = tool.invoke({
    "number_id": "num_abc123",
    "to_number": "+14155551234",
    "body": "Hello from LangChain!"
})
print(result)
```

### 使用 ToolCall 调用

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
model_generated_tool_call = {
    "args": {
        "number_id": "num_abc123",
        "to_number": "+14155551234",
        "body": "Meeting at 3pm confirmed."
    },
    "id": "1",
    "name": "agentphone_send_sms",
    "type": "tool_call",
}
tool_msg = tool.invoke(model_generated_tool_call)
print(tool_msg.content)
```

## 在代理中使用

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_agentphone import AgentPhoneToolkit
from langchain.chat_models import init_chat_model
from langgraph.prebuilt import create_react_agent

model = init_chat_model(model="claude-sonnet-4-6", model_provider="anthropic")

toolkit = AgentPhoneToolkit(
    selected_tools=["send_sms", "list_numbers", "list_contacts"]
)
agent = create_react_agent(model, toolkit.get_tools())

response = agent.invoke({
    "messages": [("user", "List my phone numbers, then send a message to +14155551234 saying 'Hello!'")]
})
```

***

## API 参考

有关 AgentPhone API 的详细文档，请访问 [docs.agentphone.to](https://docs.agentphone.to)。

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs) 通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/agentphone.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
