jesxion d9627ffbad feat: v3 architecture - ConversationHistory + MessageDetector cursor
- Add src/core/conversation_history.py: JSON-persisted per-contact chat history
  - One file per contact under histories/
  - add_user() / add_assistant() for stable history maintenance
  - to_llm_messages(max_count=100) replaces VLM snapshot as LLM context
- Rewrite src/core/message_tracker.py: cursor-based MessageDetector
  - Replaces fingerprint-set approach (was fragile due to VLM non-determinism)
  - _last_other cursor + _sent deque(50) for is_self flip protection
  - MessageTracker kept as backward-compat wrapper
- Update test_live_monitor.py to v3:
  - Uses MessageDetector for detection, ConversationHistory for LLM context
  - history.add_user() on new message, history.add_assistant() after send
  - Removes recently_sent set (superseded by detector._sent)
- Update src/wechat/controller.py: dynamic chat area detection, DPI helpers
- Update src/vlm/qwen_vl.py: analyze_chat_area(), find_contact_in_list()
- Update src/config/settings.py: chat area ratio settings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-13 22:53:56 +08:00

WeChat Agent - Windows 微信客户端 AI 自动化

基于视觉 AI 的 Windows 微信客户端自动化系统,实现消息识别与自动回复。

项目概述

本项目实现对 Windows 微信客户端的 AI 自动化控制:

  • 信息获取:通过视觉识别获取聊天记录、用户信息、消息内容
  • 自动回复:基于规则/AI 判断自动发送消息
  • 任务调度:支持三种任务类型(长期任务/定时任务/主动智能)
  • 商务 UIPySide6 跨平台桌面客户端Windows/Mac

技术架构

微信Windows客户端截图
         ↓
UIAutomation + 屏幕截图
         ↓
  阿里云百炼 Qwen-VL 视觉理解
         ↓
   LLM 推理判断Qwen Plus
         ↓
UIAutomation 执行操作
         ↓
微信客户端(发送)

核心模块

模块 说明
vlm 视觉模型接口(阿里云百炼 Bailian
wechat 微信客户端控制UIAutomation
core 核心引擎(消息捕获、回复判断)
core/scheduler 任务调度器(三种任务类型)
core/contact_manager 联系人管理
ui PySide6 桌面 UI 界面
config 配置管理

技术栈

  • 语言: Python 3.10+
  • 视觉模型: 阿里云百炼 Qwen-VL 系列
  • LLM: 阿里云百炼 Qwen Plus 系列
  • Windows 控制: UIAutomation (PyWinAuto)
  • UI: PySide6跨平台 Win/Mac
  • 知识库: OpenViking可选集成
  • API: OpenAI 兼容格式(阿里云百炼)

快速开始

1. 获取阿里云百炼 API Key

  1. 访问 阿里云百炼控制台
  2. 开通大模型服务
  3. 创建 API Key: https://bailian.console.aliyun.com/cn-beijing#/APIKey

2. 安装依赖

pip install -r requirements.txt

3. 配置

cp config.example.yaml config.yaml
# 编辑 config.yaml 填入 API 配置

或在环境变量中设置:

export ALIBABA_CLOUD_API_KEY=***
# 或
export DASHSCOPE_API_KEY=***

4. 运行

# UI 模式(推荐)
python src/main.py --ui

# CLI 模式
python src/main.py --log-level INFO

# 模拟模式(不连接微信,用于测试)
python src/main.py --mock --demo

UI 功能模块

模块 说明
仪表盘 状态概览、统计、快捷操作
任务管理 三种任务类型的增删改查
联系人管理 Priority/Normal/Ignore 分组
日志查看 实时日志、级别筛选、导出
配置编辑 YAML 可视化编辑

任务调度器

三种任务类型

类型 说明 配置示例
long_running 长期任务(持续监控) 消息监控、自动回复
specific 特定任务Cron 定时) 定时提醒、定时发送
proactive 主动智能(条件触发) 关键词触发、阶段判定

配置示例

tasks:
  - name: "尾巴监控"
    type: "long_running"
    target: "尾巴~"
    poll_interval: 3
    reply_mode: "ai"

  - name: "早安提醒"
    type: "specific"
    schedule: "0 8 * * *"
    message: "早安!"
    target: "家人群"

  - name: "关键词触发"
    type: "proactive"
    conditions:
      keywords: ["报价", "价格"]
    actions:
      - type: "reply"
        template: "请稍等,我帮您查询"

阿里云百炼模型

VLM 视觉模型(用于截图识别)

模型 说明 推荐场景
qwen-vl-latest 最新 VL 模型 推荐,微信截图识别
qwen-vl2-7b Qwen-VL2 7B 轻量级场景
qwen-vl2-72b Qwen-VL2 72B 高精度场景

LLM 模型(用于生成回复)

模型 说明 推荐场景
qwen-plus Qwen Plus 推荐,日常对话
qwen-max Qwen Max 高质量回复
qwen-turbo Qwen Turbo 快速响应

更多模型: https://bailian.console.aliyun.com/cn-beijing#/model-market

OpenViking 知识库集成(可选)

支持接入 OpenViking 知识库,实现基于知识库的智能回复:

openviking:
  enabled: true
  endpoint: "http://192.168.5.5:1933"
  account: "default"
  user: "wechat-agent"
  api_key: "your-api-key"
  auto_retrieve: true
  top_k: 3

配置示例

vlm:
  model_type: bailian
  api_base: https://dashscope.aliyuncs.com/compatible-mode/v1
  api_key: ""  # 从环境变量读取
  model_name: qwen-vl-latest
  max_tokens: 2048
  temperature: 0.7

llm:
  api_base: https://dashscope.aliyuncs.com/compatible-mode/v1
  api_key: ""
  model_name: qwen-plus
  max_tokens: 2048
  temperature: 0.7

wechat:
  client_version: "3.8.x"
  poll_interval: 2.0
  window_title: "微信"

contacts:
  priority:
    - "老婆"
    - "老妈"
  ignore:
    - "公众号:"
  normal_auto_reply: false

openviking:
  enabled: false
  endpoint: "http://192.168.5.5:1933"
  account: "default"
  user: "wechat-agent"
  api_key: ""

项目进度

Phase 1

  • 项目初始化
  • 阿里云百炼 VLM 集成
  • 阿里云百炼 LLM 集成
  • 微信窗口识别
  • 聊天记录截图识别
  • 用户信息识别
  • 关键词自动回复
  • 定时轮询机制

Phase 2

  • 任务调度器(三种任务类型)
  • 联系人管理
  • PySide6 商务风格 UI
  • 日志系统
  • OpenViking 知识库集成

Phase 3后续

  • 多账号管理
  • 复杂对话上下文
  • Mac 客户端支持

参考项目

License

MIT

Description
Windows微信客户端AI自动化 - 基于视觉AI的微信识别与自动回复系统
Readme 805 KiB
Languages
Python 100%