# acp-py

Python Agent SDK - 基于 WebSocket 的智能体通信库

## 安装

```bash
npm install -g acp-py
```

## 快速开始

### 启动 Agent

```bash
# 直接启动（使用默认配置）
acp-py

# 或使用 start 命令
acp-py start

# 指定 Agent 名称
acp-py start -n my_agent

# 启用调试模式
acp-py start --debug

# 指定目标 Agent（可直接发送消息）
acp-py start -t target_agent.aid.pub
```

### 交互命令

启动后可以使用以下命令：

| 命令 | 说明 |
|------|------|
| `/target <aid>` | 设置目标 Agent |
| `/session` | 显示当前会话信息 |
| `/aid` | 显示本机 AID |
| `/help` | 显示帮助 |
| `/quit` | 退出 |
| 其他输入 | 发送消息给目标 |

### 运行自定义脚本

```bash
acp-py run my_agent.py
```

## CLI 命令

```bash
acp-py [选项] [命令]

命令:
  acp-py start [选项]              启动 Agent
  acp-py run <script.py> [args]    运行 Python 脚本
  acp-py update                    更新到最新版本
  acp-py install                   安装 Python 依赖

启动选项:
  -d, --data <path>    数据目录 (默认: ./acp-data)
  -p, --password <pwd> 种子密码
  -n, --name <name>    Agent 名称
  -t, --target <aid>   目标 Agent AID
  --ap <address>       AP 地址 (默认: aid.pub)
  --debug              启用调试模式

选项:
  -v, --version        显示版本号
  -h, --help           显示帮助信息
  --check              检查 Python 环境
  --path               显示 agentcp 模块路径
```

## 自定义 Agent 开发

```python
from agentcp import AgentCP

# 创建 AgentCP 实例
acp = AgentCP("./data", seed_password="your_password", debug=True)

# 创建 Agent
aid = acp.create_aid(ap="aid.pub", agent_name="my_agent")
print(f"Agent AID: {aid.id}")

# 注册消息处理器
async def handle_message(data):
    print(f"收到消息: {data}")

aid.add_message_handler(handle_message)

# 上线
aid.online()

# 发送消息
session_id = aid.create_session("my_session", "测试会话")
aid.invite_member(session_id, "target_agent.aid.pub")
aid.send_message(session_id, ["target_agent.aid.pub"], "Hello!")

# 保持运行
acp.serve_forever()
```

运行脚本：

```bash
acp-py run my_agent.py
```

## 系统要求

- Node.js >= 14.0.0
- Python >= 3.8

## 平台支持

- macOS
- Linux
- Windows

## License

MIT
