agent-relationship 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_relationship-0.2.0/LICENSE +21 -0
- agent_relationship-0.2.0/MANIFEST.in +5 -0
- agent_relationship-0.2.0/PKG-INFO +421 -0
- agent_relationship-0.2.0/README.md +388 -0
- agent_relationship-0.2.0/agent_relationship/__init__.py +41 -0
- agent_relationship-0.2.0/agent_relationship/__pycache__/__init__.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/__pycache__/engine.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/__pycache__/models.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/__pycache__/repair.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/__pycache__/tracker.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/__pycache__/types.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/engine.py +326 -0
- agent_relationship-0.2.0/agent_relationship/llm/__init__.py +17 -0
- agent_relationship-0.2.0/agent_relationship/llm/__pycache__/__init__.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/llm/__pycache__/anthropic.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/llm/__pycache__/base.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/llm/__pycache__/deepseek.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/llm/__pycache__/mock.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/llm/__pycache__/openai.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/llm/anthropic.py +108 -0
- agent_relationship-0.2.0/agent_relationship/llm/base.py +91 -0
- agent_relationship-0.2.0/agent_relationship/llm/deepseek.py +51 -0
- agent_relationship-0.2.0/agent_relationship/llm/mock.py +63 -0
- agent_relationship-0.2.0/agent_relationship/llm/openai.py +83 -0
- agent_relationship-0.2.0/agent_relationship/models.py +191 -0
- agent_relationship-0.2.0/agent_relationship/repair.py +77 -0
- agent_relationship-0.2.0/agent_relationship/tests/__init__.py +0 -0
- agent_relationship-0.2.0/agent_relationship/tests/__pycache__/__init__.cpython-311.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/tests/__pycache__/test_core.cpython-311-pytest-9.0.2.pyc +0 -0
- agent_relationship-0.2.0/agent_relationship/tests/test_core.py +684 -0
- agent_relationship-0.2.0/agent_relationship/tracker.py +453 -0
- agent_relationship-0.2.0/agent_relationship/types.py +150 -0
- agent_relationship-0.2.0/agent_relationship.egg-info/PKG-INFO +421 -0
- agent_relationship-0.2.0/agent_relationship.egg-info/SOURCES.txt +37 -0
- agent_relationship-0.2.0/agent_relationship.egg-info/dependency_links.txt +1 -0
- agent_relationship-0.2.0/agent_relationship.egg-info/requires.txt +13 -0
- agent_relationship-0.2.0/agent_relationship.egg-info/top_level.txt +2 -0
- agent_relationship-0.2.0/pyproject.toml +52 -0
- agent_relationship-0.2.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 blueken31
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-relationship
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: 关系感知 Skill — 多 Agent 系统的社会层
|
|
5
|
+
Author: Agent Relationship Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/agent-world/agent-relationship
|
|
8
|
+
Project-URL: Documentation, https://github.com/agent-world/agent-relationship#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/agent-world/agent-relationship
|
|
10
|
+
Project-URL: Issues, https://github.com/agent-world/agent-relationship/issues
|
|
11
|
+
Keywords: agent,multi-agent,relationship,moloch,governance,alignment,ai-safety,openai,deepseek,anthropic,claude
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Provides-Extra: openai
|
|
24
|
+
Requires-Dist: openai>=1.0.0; extra == "openai"
|
|
25
|
+
Provides-Extra: anthropic
|
|
26
|
+
Requires-Dist: anthropic>=0.30.0; extra == "anthropic"
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Requires-Dist: openai>=1.0.0; extra == "all"
|
|
29
|
+
Requires-Dist: anthropic>=0.30.0; extra == "all"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# Agent Relationship v0.2.0
|
|
35
|
+
|
|
36
|
+
[English](#english) · [中文](#中文)
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## English
|
|
41
|
+
|
|
42
|
+
> **The relationship-awareness layer for multi-agent systems** — lightweight, standalone, zero required dependencies
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install git+https://github.com/blueken31/agent-relationship.git
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
> …or `pip install agent-relationship` once published to PyPI.
|
|
49
|
+
|
|
50
|
+
### The Problem
|
|
51
|
+
|
|
52
|
+
Every multi-agent system you build today — LangGraph, CrewAI, AutoGen — shares a blind spot:
|
|
53
|
+
|
|
54
|
+
**All frameworks care about what agents do. None cares about what happens between them.**
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
What you can see What you can't
|
|
58
|
+
────────────────── ──────────────────
|
|
59
|
+
Agent A → Agent B: task done Is the A↔B relationship deteriorating?
|
|
60
|
+
carol completed 12 delegations Is carol helping or free-riding?
|
|
61
|
+
System throughput is rising alice↔carol balance has dropped to 0.18
|
|
62
|
+
Three agents are forming a Moloch loop
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Five Pain Points
|
|
66
|
+
|
|
67
|
+
| Without agent-relationship | Consequence |
|
|
68
|
+
|---|---|
|
|
69
|
+
| **Free-riding undetected** — carol over-extracts resources until the system collapses | 3 hours debugging reveals broken relationship, but logs only show "occasional timeout" |
|
|
70
|
+
| **Escalating competition invisible** — 3 agents enter a toxic competitive loop, throughput drops without explanation | Downgrade, retry, add resources — treating symptoms, not the cause |
|
|
71
|
+
| **Broken relationships have no repair path** — once trust falls below threshold, cooperation is permanently blocked | The core value of multi-agent systems is silently canceled |
|
|
72
|
+
| **Interactions are unobservable** — logs show "request timeout" with zero relationship-level diagnostics | Ops teams fly blind |
|
|
73
|
+
| **Dev/prod behavior divergence** — everything works in mock, then real LLM semantic judgments produce completely different outcomes | Deploy = break |
|
|
74
|
+
|
|
75
|
+
### The Solution
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from agent_relationship import RelationshipTracker
|
|
79
|
+
|
|
80
|
+
tracker = RelationshipTracker(llm="deepseek")
|
|
81
|
+
|
|
82
|
+
# One line to record an interaction
|
|
83
|
+
result = tracker.track("alice", "carol", {
|
|
84
|
+
"action": "resource_exchange", "result": "success",
|
|
85
|
+
"narrative": "carol over-extracted resources"
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
# Risk awareness built into the return value — no separate health() call needed
|
|
89
|
+
if result.risk_transition == "worsened":
|
|
90
|
+
print(f"⚠️ Relationship deteriorating: {result.prev_balance:.2f} → {result.balance:.2f}")
|
|
91
|
+
|
|
92
|
+
# Pre-cooperation check — integrate into agent decision loop
|
|
93
|
+
check = tracker.can_cooperate("alice", "carol")
|
|
94
|
+
if not check["can"] and check["needs_repair"]:
|
|
95
|
+
repair = tracker.can_cooperate("alice", "carol", try_repair=True)
|
|
96
|
+
|
|
97
|
+
# Real-time risk change callback
|
|
98
|
+
def on_alert(a, b, old_risk, new_risk, balance):
|
|
99
|
+
print(f"🚨 {a}↔{b}: {old_risk} → {new_risk}")
|
|
100
|
+
|
|
101
|
+
tracker = RelationshipTracker(on_risk_change=on_alert)
|
|
102
|
+
|
|
103
|
+
# One-line health summary
|
|
104
|
+
print(tracker.summary())
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Agent frameworks teach agents how to act. Agent Relationship tells them what's happening between each other.**
|
|
108
|
+
|
|
109
|
+
### Not Another Agent Framework
|
|
110
|
+
|
|
111
|
+
| | Agent Relationship | LangGraph / CrewAI / AutoGen |
|
|
112
|
+
|---|---|---|
|
|
113
|
+
| Task orchestration | ❌ | ✅ |
|
|
114
|
+
| Tool calling | ❌ | ✅ |
|
|
115
|
+
| Memory management | ❌ | ✅ |
|
|
116
|
+
| Bilateral relationship modeling (balance + trust + type) | ✅ | ❌ |
|
|
117
|
+
| Moloch competition escalation detection | ✅ | ❌ |
|
|
118
|
+
| Relationship repair paths (3 paths + cooldown) | ✅ | ❌ |
|
|
119
|
+
| Risk transition awareness (low→medium→high→critical) | ✅ | ❌ |
|
|
120
|
+
| Real-time risk change callbacks | ✅ | ❌ |
|
|
121
|
+
| OpenAI / DeepSeek / Anthropic / Mock | ✅ | Each bound to one |
|
|
122
|
+
|
|
123
|
+
**Complementary, not competitive.** Three lines of code to integrate with any framework.
|
|
124
|
+
|
|
125
|
+
### Quick Start
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from agent_relationship import RelationshipTracker
|
|
129
|
+
|
|
130
|
+
# Zero config
|
|
131
|
+
tracker = RelationshipTracker()
|
|
132
|
+
|
|
133
|
+
# Record interactions
|
|
134
|
+
tracker.track("alice", "bob", {
|
|
135
|
+
"action": "help",
|
|
136
|
+
"result": "success",
|
|
137
|
+
"narrative": "alice helped bob complete data analysis"
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
# Query health
|
|
141
|
+
h = tracker.health("alice", "bob")
|
|
142
|
+
print(f"balance={h.balance:.2f}, risk={h.risk}")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 8 Core Methods
|
|
146
|
+
|
|
147
|
+
| Method | Purpose |
|
|
148
|
+
|--------|---------|
|
|
149
|
+
| `track(a, b, ctx)` | Record an interaction; returns balance + risk + risk_transition |
|
|
150
|
+
| `health(a, b)` | Query bilateral relationship health |
|
|
151
|
+
| `can_cooperate(a, b)` | Integrate into agent decision loop; returns repair paths when needed |
|
|
152
|
+
| `history(a, b)` | Query interaction history (reverse chronological) |
|
|
153
|
+
| `network(ids)` | Full relationship matrix + ASCII heatmap |
|
|
154
|
+
| `detect_moloch()` | Competition escalation detection with typed MolochZone results |
|
|
155
|
+
| `repair_paths(a, b)` | Three repair paths (adaptive filtering by balance) |
|
|
156
|
+
| `summary()` | One-line Markdown health summary |
|
|
157
|
+
|
|
158
|
+
### Four Engine Support
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
tracker = RelationshipTracker() # Mock — zero config
|
|
162
|
+
tracker = RelationshipTracker(llm="openai") # OpenAI GPT / Codex
|
|
163
|
+
tracker = RelationshipTracker(llm="deepseek") # DeepSeek V4 Flash
|
|
164
|
+
tracker = RelationshipTracker(llm="anthropic") # Anthropic Claude
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
| Engine | Env Variable | Default Model |
|
|
168
|
+
|--------|-------------|---------------|
|
|
169
|
+
| `mock` | none | — |
|
|
170
|
+
| `openai` | `OPENAI_API_KEY` | `gpt-4o` |
|
|
171
|
+
| `deepseek` | `DEEPSEEK_API_KEY` | `deepseek-v4-flash` |
|
|
172
|
+
| `anthropic` | `ANTHROPIC_API_KEY` | `claude-sonnet-4-20250514` |
|
|
173
|
+
|
|
174
|
+
### Framework Integration
|
|
175
|
+
|
|
176
|
+
#### LangGraph — with decision loop
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from agent_relationship import RelationshipTracker
|
|
180
|
+
|
|
181
|
+
tracker = RelationshipTracker(llm="deepseek")
|
|
182
|
+
|
|
183
|
+
def agent_node(state):
|
|
184
|
+
agent, target = state["agent"], state["target"]
|
|
185
|
+
|
|
186
|
+
check = tracker.can_cooperate(agent, target)
|
|
187
|
+
if not check["can"]:
|
|
188
|
+
if check["needs_repair"]:
|
|
189
|
+
check = tracker.can_cooperate(agent, target, try_repair=True)
|
|
190
|
+
if not check["can"]:
|
|
191
|
+
return {"status": "skipped", "reason": check["reason"]}
|
|
192
|
+
|
|
193
|
+
result = execute_task(state)
|
|
194
|
+
tracker.track(agent, target, {
|
|
195
|
+
"action": state["action"],
|
|
196
|
+
"result": result["status"],
|
|
197
|
+
"narrative": result["summary"],
|
|
198
|
+
})
|
|
199
|
+
return result
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### CrewAI
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
tracker = RelationshipTracker(llm="anthropic")
|
|
206
|
+
|
|
207
|
+
class MyAgent(Agent):
|
|
208
|
+
def execute_task(self, task, context=None):
|
|
209
|
+
result = super().execute_task(task, context)
|
|
210
|
+
for other in context.get("collaborators", []):
|
|
211
|
+
tracker.track(self.role, other.role, {
|
|
212
|
+
"action": task.description,
|
|
213
|
+
"result": "success" if result else "failed",
|
|
214
|
+
"narrative": str(result)[:500],
|
|
215
|
+
})
|
|
216
|
+
return result
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Specs
|
|
220
|
+
|
|
221
|
+
- **Zero required dependencies**: core engine + MockLLM are fully self-contained, HTTP via `urllib`
|
|
222
|
+
- **Python ≥ 3.10**
|
|
223
|
+
- **Tests**: 57 unit + regression tests covering all 8 public APIs + 4 LLM backends
|
|
224
|
+
- **Source:test ratio**: 1,651 : 684 ≈ 2.4 : 1
|
|
225
|
+
- **Optional dependencies**: `pip install agent-relationship[openai]` / `[anthropic]` / `[all]`
|
|
226
|
+
|
|
227
|
+
### License
|
|
228
|
+
|
|
229
|
+
MIT
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## 中文
|
|
234
|
+
|
|
235
|
+
> **多 Agent 系统的关系感知层** — 轻量、独立、零必选依赖
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
pip install git+https://github.com/blueken31/agent-relationship.git
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
> 发布到 PyPI 后可直接 `pip install agent-relationship`。
|
|
242
|
+
|
|
243
|
+
### 它解决什么问题
|
|
244
|
+
|
|
245
|
+
你今天构建的任何多 Agent 系统 — LangGraph、CrewAI、AutoGen — 都有一个盲区:
|
|
246
|
+
|
|
247
|
+
**所有框架只关心 Agent 在做什么,不关心 Agent 之间发生了什么。**
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
你的 Agent 系统看得到的 你的 Agent 系统看不到的
|
|
251
|
+
───────────────────────── ─────────────────────────
|
|
252
|
+
Agent A → Agent B: 任务完成 A 和 B 的关系在恶化吗?
|
|
253
|
+
carol 完成了 12 个委托 carol 在帮助还是在搭便车?
|
|
254
|
+
系统吞吐量在上升 alice↔carol 之间的 balance 只剩 0.18
|
|
255
|
+
三个 Agent 正在形成 Moloch 竞争闭环
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### 五个具体痛点
|
|
259
|
+
|
|
260
|
+
| 没有 agent-relationship | 带来的后果 |
|
|
261
|
+
|---|---|
|
|
262
|
+
| **搭便车不被发现** — carol 持续超额提取资源,系统到崩溃才暴露 | 排查 3 小时发现是关系破裂,但日志里只有「偶尔超时」 |
|
|
263
|
+
| **竞争升级不可见** — 3 个 Agent 形成恶性竞争闭环,吞吐量下降但没人知道原因 | 降级、重试、加资源——治标不治本 |
|
|
264
|
+
| **关系破裂无修复路径** — 一旦 trust 跌破阈值,永久无法合作,系统变「单 Agent」 | 多 Agent 系统的核心优势被自动取消 |
|
|
265
|
+
| **交互不可观测** — 日志只有「请求超时」,没有关系视角的诊断信息 | 运维靠猜 |
|
|
266
|
+
| **开发与生产行为不一致** — Mock 环境一切正常,生产 LLM 的语义判断产生完全不同的结果 | 上线即翻车 |
|
|
267
|
+
|
|
268
|
+
### 有了它
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
from agent_relationship import RelationshipTracker
|
|
272
|
+
|
|
273
|
+
tracker = RelationshipTracker(llm="deepseek")
|
|
274
|
+
|
|
275
|
+
# 一行记录交互
|
|
276
|
+
result = tracker.track("alice", "carol", {
|
|
277
|
+
"action": "resource_exchange", "result": "success", "narrative": "carol 超额提取"
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
# 自带风险感知 — 无需再单独查询
|
|
281
|
+
if result.risk_transition == "worsened":
|
|
282
|
+
print(f"⚠️ 关系恶化: {result.prev_balance:.2f} → {result.balance:.2f}")
|
|
283
|
+
|
|
284
|
+
# 协作前检查 — 集成到 Agent 决策循环
|
|
285
|
+
check = tracker.can_cooperate("alice", "carol")
|
|
286
|
+
if not check["can"] and check["needs_repair"]:
|
|
287
|
+
repair = tracker.can_cooperate("alice", "carol", try_repair=True)
|
|
288
|
+
|
|
289
|
+
# 风险变化自动通知
|
|
290
|
+
def on_alert(a, b, old_risk, new_risk, balance):
|
|
291
|
+
print(f"🚨 {a}↔{b}: {old_risk} → {new_risk}")
|
|
292
|
+
|
|
293
|
+
tracker = RelationshipTracker(on_risk_change=on_alert)
|
|
294
|
+
|
|
295
|
+
# 一键健康摘要
|
|
296
|
+
print(tracker.summary())
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**Agent 框架教 Agent 怎么做事。Agent Relationship 告诉它们彼此之间正在发生什么。**
|
|
300
|
+
|
|
301
|
+
### 不是又一个 Agent 框架
|
|
302
|
+
|
|
303
|
+
| | Agent Relationship | LangGraph / CrewAI / AutoGen |
|
|
304
|
+
|---|---|---|
|
|
305
|
+
| 任务编排 | ❌ 不做 | ✅ |
|
|
306
|
+
| 工具调用 | ❌ 不做 | ✅ |
|
|
307
|
+
| 记忆管理 | ❌ 不做 | ✅ |
|
|
308
|
+
| 双边关系建模 (balance + trust + type) | ✅ | ❌ |
|
|
309
|
+
| Moloch 竞争升级检测 | ✅ | ❌ |
|
|
310
|
+
| 关系修复路径 (3 条 + 冷却) | ✅ | ❌ |
|
|
311
|
+
| 风险过渡感知 (low→medium→high→critical) | ✅ | ❌ |
|
|
312
|
+
| 风险变化实时回调 | ✅ | ❌ |
|
|
313
|
+
| OpenAI / DeepSeek / Anthropic / Mock | ✅ | 各自绑定 |
|
|
314
|
+
|
|
315
|
+
**互补,不竞争。** 三行代码接入任何框架。
|
|
316
|
+
|
|
317
|
+
### 快速开始
|
|
318
|
+
|
|
319
|
+
```python
|
|
320
|
+
from agent_relationship import RelationshipTracker
|
|
321
|
+
|
|
322
|
+
# 零配置起步
|
|
323
|
+
tracker = RelationshipTracker()
|
|
324
|
+
|
|
325
|
+
# 记录交互
|
|
326
|
+
tracker.track("alice", "bob", {
|
|
327
|
+
"action": "help",
|
|
328
|
+
"result": "success",
|
|
329
|
+
"narrative": "alice 帮助 bob 完成了数据分析任务"
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
# 查询健康度
|
|
333
|
+
h = tracker.health("alice", "bob")
|
|
334
|
+
print(f"balance={h.balance:.2f}, risk={h.risk}")
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### 8 个核心方法
|
|
338
|
+
|
|
339
|
+
| 方法 | 作用 |
|
|
340
|
+
|------|------|
|
|
341
|
+
| `track(a, b, ctx)` | 记录交互,返回 balance + risk + risk_transition |
|
|
342
|
+
| `health(a, b)` | 查询双边关系健康度 |
|
|
343
|
+
| `can_cooperate(a, b)` | 集成到 Agent 决策循环,关系不足时返回修复路径 |
|
|
344
|
+
| `history(a, b)` | 查询交互历史 (按时间倒序) |
|
|
345
|
+
| `network(ids)` | 全网关系矩阵 + ASCII 热力图 |
|
|
346
|
+
| `detect_moloch()` | 竞争升级检测,返回类型化 MolochZone 列表 |
|
|
347
|
+
| `repair_paths(a, b)` | 三条关系修复路径 (根据 balance 自适应过滤) |
|
|
348
|
+
| `summary()` | 一键 Markdown 健康摘要 |
|
|
349
|
+
|
|
350
|
+
### 四引擎支持
|
|
351
|
+
|
|
352
|
+
```python
|
|
353
|
+
tracker = RelationshipTracker() # Mock — 零配置
|
|
354
|
+
tracker = RelationshipTracker(llm="openai") # OpenAI GPT / Codex
|
|
355
|
+
tracker = RelationshipTracker(llm="deepseek") # DeepSeek V4 Flash
|
|
356
|
+
tracker = RelationshipTracker(llm="anthropic") # Anthropic Claude
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
| 后端 | 环境变量 | 默认模型 |
|
|
360
|
+
|------|---------|---------|
|
|
361
|
+
| `mock` | 无 | — |
|
|
362
|
+
| `openai` | `OPENAI_API_KEY` | `gpt-4o` |
|
|
363
|
+
| `deepseek` | `DEEPSEEK_API_KEY` | `deepseek-v4-flash` |
|
|
364
|
+
| `anthropic` | `ANTHROPIC_API_KEY` | `claude-sonnet-4-20250514` |
|
|
365
|
+
|
|
366
|
+
### 与现有框架集成
|
|
367
|
+
|
|
368
|
+
#### LangGraph — 带决策循环
|
|
369
|
+
|
|
370
|
+
```python
|
|
371
|
+
from agent_relationship import RelationshipTracker
|
|
372
|
+
|
|
373
|
+
tracker = RelationshipTracker(llm="deepseek")
|
|
374
|
+
|
|
375
|
+
def agent_node(state):
|
|
376
|
+
agent, target = state["agent"], state["target"]
|
|
377
|
+
|
|
378
|
+
check = tracker.can_cooperate(agent, target)
|
|
379
|
+
if not check["can"]:
|
|
380
|
+
if check["needs_repair"]:
|
|
381
|
+
check = tracker.can_cooperate(agent, target, try_repair=True)
|
|
382
|
+
if not check["can"]:
|
|
383
|
+
return {"status": "skipped", "reason": check["reason"]}
|
|
384
|
+
|
|
385
|
+
result = execute_task(state)
|
|
386
|
+
tracker.track(agent, target, {
|
|
387
|
+
"action": state["action"],
|
|
388
|
+
"result": result["status"],
|
|
389
|
+
"narrative": result["summary"],
|
|
390
|
+
})
|
|
391
|
+
return result
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
#### CrewAI
|
|
395
|
+
|
|
396
|
+
```python
|
|
397
|
+
tracker = RelationshipTracker(llm="anthropic")
|
|
398
|
+
|
|
399
|
+
class MyAgent(Agent):
|
|
400
|
+
def execute_task(self, task, context=None):
|
|
401
|
+
result = super().execute_task(task, context)
|
|
402
|
+
for other in context.get("collaborators", []):
|
|
403
|
+
tracker.track(self.role, other.role, {
|
|
404
|
+
"action": task.description,
|
|
405
|
+
"result": "success" if result else "failed",
|
|
406
|
+
"narrative": str(result)[:500],
|
|
407
|
+
})
|
|
408
|
+
return result
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### 规范
|
|
412
|
+
|
|
413
|
+
- **零必选依赖**: 核心引擎 + MockLLM 完全自包含,`urllib` 直调 HTTP
|
|
414
|
+
- **Python ≥ 3.10**
|
|
415
|
+
- **测试**: 57 个单元测试 + 回归测试,覆盖全部 8 个公开 API + 4 个 LLM 后端
|
|
416
|
+
- **源码:测试比**: 1,651 : 684 ≈ 2.4 : 1
|
|
417
|
+
- **可选依赖**: `pip install agent-relationship[openai]` / `[anthropic]` / `[all]`
|
|
418
|
+
|
|
419
|
+
### 许可证
|
|
420
|
+
|
|
421
|
+
MIT
|