File size: 2,486 Bytes
ba62abd
 
 
 
 
 
 
 
 
 
 
 
 
 
2712605
ba62abd
 
 
2712605
 
 
 
 
ba62abd
 
 
 
 
 
 
 
 
 
 
 
2712605
 
 
 
 
ba62abd
 
 
2712605
 
ba62abd
 
2712605
 
 
 
 
 
 
 
 
 
ba62abd
 
2712605
 
 
ba62abd
 
 
 
 
 
0f3d019
ba62abd
 
 
 
 
0f3d019
ba62abd
 
 
 
 
 
 
 
 
 
 
0f3d019
2712605
ba62abd
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
language:
  - zh
  - en
tags:
  - preference-learning
  - qlora
  - agent
  - personalization
  - peft
  - association-engine
pipeline_tag: text-generation
base_model: Qwen/Qwen2.5-7B-Instruct
---

# Hermes — 联想引擎 / Association Engine

为任意 AI agent 提供基于 **QLoRA 微调**的隐式偏好学习能力。

Agent 推理时主动检索用户历史偏好并默认应用,减少重复沟通成本,同时作为多 agent 协作的共享偏好池。

## 核心机制

| 机制 | 说明 |
|------|------|
| **联想 (Association)** | 不等用户开口,主动检索历史偏好 → 注入推理上下文 |
| **动态语义聚类** | 偏好自动聚合为生活切面(scope),不预设类型和数量 |
| **QLoRA 微调** | 闲时低资源训练,每个 scope 独立 LoRA 权重 |
| **维度递增约束** | 同 scope 内偏好描述精度必须递增,防止信息退化 |

## 架构

```
Agent → CLI / Python SDK → Hermes Daemon (SQLite + QLoRA 训练沙箱)
```

## 快速开始

```bash
pip install -e .
hermes init          # 一键初始化(下载模型、验证环境)
hermes demo          # 交互演示
hermes start         # 后台启动 daemon
```

### Python SDK

```python
from hermes_core import HermesClient

client = HermesClient(user_id="u_alex", agent_id="my-agent")

# 推理前查询偏好
prefs = client.query("帮我写个用户登录接口")

# Agent 自主记录偏好
client.record("后端开发", [
    {"key": "language", "value": "TypeScript", "context": "默认语言"},
    {"key": "framework", "value": "Express", "context": "默认框架"},
])
```

### CLI

```bash
# 记录偏好
hermes record --user u_alex --scope-desc "后端开发" \
  --dimensions '[{"key":"language","value":"TypeScript"}]'

# 查询偏好
hermes query --user u_alex --text "帮我写个API"

# 查看状态
hermes status
```

## 训练 LoRA 权重

每个 scope 独立训练 LoRA 适配器,基于 `Qwen/Qwen2.5-7B-Instruct````bash
# 手动触发训练
hermes train --user u_alex --scope <scope_id>

# 或让 daemon 闲时自动训练
hermes start
```

训练完成后,LoRA 权重保存在 `~/.hermes/data/users/{user_id}/checkpoints/{scope_id}/v{version}/`## 项目结构

```
hermes/
├── hermes_core/    # 核心逻辑(Python SDK)
├── cli/            # Click 命令行壳
├── daemon/         # 后台训练守护进程
├── tests/          # 40 个单元测试全部通过
└── pyproject.toml
```