Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
| Date | Stars |
|---|---|
| 2026-07-31 | 1246 |
| 2026-08-06 | 1255 |
Today
+9 stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# weixin-agent-sdk
> 本项目非微信官方项目,代码由 [@tencent-weixin/openclaw-weixin](https://npmx.dev/package/@tencent-weixin/openclaw-weixin) 改造而来,仅供学习交流使用。
微信 AI Agent 桥接框架 —— 通过简单的 Agent 接口,将任意 AI 后端接入微信。
## 项目结构
```
packages/
sdk/ weixin-agent-sdk —— 微信桥接 SDK
weixin-acp/ ACP (Agent Client Protocol) 适配器
example-openai/ 基于 OpenAI 的示例
```
## 通过 ACP 接入 Claude Code, Codex, kimi-cli 等 Agent
[ACP (Agent Client Protocol)](https://agentclientprotocol.com/) 是一个开放的 Agent 通信协议。如果你已有兼容 ACP 的 agent,可以直接通过 [`weixin-acp`](https://www.npmjs.com/package/weixin-acp) 接入微信,无需编写任何代码。
### Claude Code
```bash
npx weixin-acp claude-code
```
### Codex
```bash
npx weixin-acp codex
```
### 其它 ACP Agent
比如 kimi-cli:
```bash
npx weixin-acp start -- kimi acp
```
`--` 后面的部分就是你的 ACP agent 启动命令,`weixin-acp` 会自动以子进程方式启动它,通过 JSON-RPC over stdio 进行通信。
更多 ACP 兼容 agent 请参考 [ACP agent 列表](https://agentclientprotocol.com/get-started/agents)。
## 自定义 Agent
SDK 主要导出三样东西:
- **`Agent`** 接口 —— 实现它就能接入微信
- **`login()`** —— 扫码登录
- **`start(agent)`** —— 启动消息循环,立即返回可主动发消息的 `Bot`
### Agent 接口
```typescript
interface Agent {
chat(request: ChatRequest): Promise<ChatResponse>;
}
interface ChatRequest {
conversationId: string; // 用户标识,可用于维护多轮对话
text: string; // 文本内容
media?: { // 附件(图片/语音/视频/文件)
type: "image" | "audio" | "video" | "file";
filePath: string; // 本地文件路径(已下载解密)
mimeType: string;
fileName?: string;
};
}
interface ChatResponse {
text?: string; // 回复文本(支持 markdown,发送前自动转纯文本)
media?: { // 回复媒体
type: "image" | "video" | "file";
url: string; // 本地路径或 HTTPS URL
fileName?: string;
};
}
```
### 最简示例
```typescript
import { login, start, type Agent } from "weixin-agent-sdk";
const echo: Agent = {
async chat(req) {
return { text: `你说了: ${req.text}` };
},
};
await login();
const bot = start(echo);
await bot.wait();
```
### 完整示例(自己管理对话历史)
```typescript
import { login, start, type Agent } from "weixin-agent-sdk";
const conversations = new Map<string, string[]>();
const myAgent: Agent = {
async chat(req) {
const history = conversations.get(req.conversationId) ?? [];
history.push(req.text);
// 调用你的 AI 服务...
const reply = await callMyAI(history);
history.push(reply);
conversations.set(req.conversationId, history);
return { text: reply };
},
};
await login();
const bot = start(myAgent);
await bot.wait();
```
### 主动发送消息
`start()` 会立即返回 `Bot` 实例。`Bot` 提供了 `sendMessage()`,可以在收到微信消息之外,主动给当前登录用户发送内容;如果是 CLI/脚本程序,可以用 `bot.wait()` 等待消息循环结束。
```typescript
import { login, start, type Agent } from "weixin-agent-sdk";
const agent: Agent = {
async chat(req) {
if (req.text === "ping") {
return { text: "pong" };
}
return { text: `收到:${req.text}` };
},
};
await login();
const bot = start(agent);
setInterval(() => {
void bot.sendMessage("定时提醒:记得查看最新状态");
}, 60_000);
await bot.wait();
```
也可以主动发送完整的 `ChatResponse`,包括图片、视频或文件:
```typescript
await bot.sendMessage({
text: "这是最新报表",
media: {
type: "file",
url: "./reports/daily.pdf",
fileName: "daily.pdf",
},
});
```
注意事项:
- 主动发送依赖微信下发的 `context_token`
- 需要在 `start()` 运行期间,至少先收到过当前账号的一条入站消息
- `context_token` 有时效,可能是 24 小时;过期后需要再次收到新消息才能继续主动发送
### OpenAI 示例
`packages/example-openai/` 是一个完整的 OpenAI Agent 实现,支持多轮对话和图片输入:
```bash
pnpm install
# 扫码登录微信
pnpm run login -w packages/example-openai
# 启动 bot
OPENAI_API_KEY=sk-xxx pnpm run start -w packages/example-openai
```
支持的环境变量:
| 变量 | 必填 | 说明 |
|------|------|------|
| `OPENAI_API_KEY` | 是 | OpenAI API Key |
| `OPENAI_BASE_URL` | 否 | 自定义 API 地址(兼容 OpenAI 接口的第三方服务) |
| `OPENAI_MODEL` | 否 | 模型名称,默认 `gpt-5.4` |
| `SYSTEM_PROMPT` | 否 | 系统提示词 |
## 支持的消息类型
### 接收(微信 → Agent)
| 类型 | `media.type` | 说明 |
|------|-------------|------|
| 文本 | — | `request.text` 直接拿到文字 |
| 图片 | `image` | 自动从 CDN 下载解密,`filePatExcerpt of 5,601 characters
Read on GitHubwong2
45
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:37ecc3d1e86275ca, llm:Repository description (Chinese): '微信Clawbot接入任意Agent' — indicates integrating WeChat (微信) Clawbot with arbitrary agents (Agent integration). Language: TypeScript.
matched fp:37ecc3d1e86275ca, llm:Repository description (Chinese): '微信Clawbot接入任意Agent' — indicates integrating WeChat (微信) Clawbot with arbitrary agents (Agent integration). Language: TypeScript.