new-agent-memory 0.1.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.
- new_agent_memory-0.1.0/.dockerignore +13 -0
- new_agent_memory-0.1.0/.env.example +11 -0
- new_agent_memory-0.1.0/.env.local_llm +16 -0
- new_agent_memory-0.1.0/.gitattributes +1 -0
- new_agent_memory-0.1.0/.github/workflows/publish.yml +45 -0
- new_agent_memory-0.1.0/.github/workflows/tests.yml +75 -0
- new_agent_memory-0.1.0/.gitignore +9 -0
- new_agent_memory-0.1.0/AGENT_CONNECT.md +287 -0
- new_agent_memory-0.1.0/Dockerfile +28 -0
- new_agent_memory-0.1.0/LICENSE +661 -0
- new_agent_memory-0.1.0/PKG-INFO +552 -0
- new_agent_memory-0.1.0/README.md +530 -0
- new_agent_memory-0.1.0/adapters/__init__.py +13 -0
- new_agent_memory-0.1.0/adapters/autonomous_bridge.py +149 -0
- new_agent_memory-0.1.0/adapters/base_adapter.py +394 -0
- new_agent_memory-0.1.0/adapters/claude_adapter.py +287 -0
- new_agent_memory-0.1.0/adapters/claude_code_bridge.py +138 -0
- new_agent_memory-0.1.0/adapters/cli.py +159 -0
- new_agent_memory-0.1.0/adapters/cli_bridge.py +102 -0
- new_agent_memory-0.1.0/adapters/client_bridge.py +238 -0
- new_agent_memory-0.1.0/adapters/codex_adapter.py +287 -0
- new_agent_memory-0.1.0/adapters/hermes_connector.py +208 -0
- new_agent_memory-0.1.0/adapters/hub_sub_agent.py +204 -0
- new_agent_memory-0.1.0/adapters/polling_adapter.py +140 -0
- new_agent_memory-0.1.0/adapters/webhook_adapter.py +84 -0
- new_agent_memory-0.1.0/core/__init__.py +81 -0
- new_agent_memory-0.1.0/core/agent_system.py +542 -0
- new_agent_memory-0.1.0/core/attention_system.py +620 -0
- new_agent_memory-0.1.0/core/audit_logger.py +262 -0
- new_agent_memory-0.1.0/core/bm25_retriever.py +192 -0
- new_agent_memory-0.1.0/core/cognitive_runtime.py +512 -0
- new_agent_memory-0.1.0/core/cognitive_state.py +711 -0
- new_agent_memory-0.1.0/core/consolidation_engine.py +343 -0
- new_agent_memory-0.1.0/core/context_compressor.py +254 -0
- new_agent_memory-0.1.0/core/data_manager.py +205 -0
- new_agent_memory-0.1.0/core/dense_retriever.py +211 -0
- new_agent_memory-0.1.0/core/emotion_engine.py +288 -0
- new_agent_memory-0.1.0/core/entity_extractor.py +302 -0
- new_agent_memory-0.1.0/core/json_store.py +146 -0
- new_agent_memory-0.1.0/core/llm_planner.py +886 -0
- new_agent_memory-0.1.0/core/local_llm.py +172 -0
- new_agent_memory-0.1.0/core/memory_extractor.py +421 -0
- new_agent_memory-0.1.0/core/memory_spec.py +143 -0
- new_agent_memory-0.1.0/core/persona_layer.py +416 -0
- new_agent_memory-0.1.0/core/pii_handler.py +156 -0
- new_agent_memory-0.1.0/core/query_planner.py +233 -0
- new_agent_memory-0.1.0/core/rrf_fusion.py +98 -0
- new_agent_memory-0.1.0/core/sqlite_store.py +376 -0
- new_agent_memory-0.1.0/core/store.py +168 -0
- new_agent_memory-0.1.0/core/weight_system.py +578 -0
- new_agent_memory-0.1.0/docker-compose.yml +37 -0
- new_agent_memory-0.1.0/docs/LINUX_DOCKER.md +90 -0
- new_agent_memory-0.1.0/docs/multi_agent_guide.md +380 -0
- new_agent_memory-0.1.0/examples/attention_workspace.py +45 -0
- new_agent_memory-0.1.0/examples/cognitive_agent.py +56 -0
- new_agent_memory-0.1.0/examples/forgotten_recall.py +31 -0
- new_agent_memory-0.1.0/examples/llm_planner.py +53 -0
- new_agent_memory-0.1.0/examples/local_llm_extraction.py +117 -0
- new_agent_memory-0.1.0/examples/openai_compatible_agent.py +31 -0
- new_agent_memory-0.1.0/examples/persona_adaptation.py +23 -0
- new_agent_memory-0.1.0/examples/reflective_cognition.py +29 -0
- new_agent_memory-0.1.0/examples/simple_memory.py +30 -0
- new_agent_memory-0.1.0/experiments/OPTIMIZATION_REPORT.md +192 -0
- new_agent_memory-0.1.0/experiments/final_comparison.py +186 -0
- new_agent_memory-0.1.0/experiments/optimization1_sparse_assoc.py +233 -0
- new_agent_memory-0.1.0/experiments/optimization3_v2.py +465 -0
- new_agent_memory-0.1.0/forgotten_layer.py +342 -0
- new_agent_memory-0.1.0/hub/__init__.py +6 -0
- new_agent_memory-0.1.0/hub/cli.py +117 -0
- new_agent_memory-0.1.0/hub/memory_bridge.py +46 -0
- new_agent_memory-0.1.0/hub/models.py +292 -0
- new_agent_memory-0.1.0/hub/server.py +371 -0
- new_agent_memory-0.1.0/hub/sse.py +70 -0
- new_agent_memory-0.1.0/hub/web_ui.py +617 -0
- new_agent_memory-0.1.0/hub_data/QUICK_START.md +141 -0
- new_agent_memory-0.1.0/hub_data/README.md +283 -0
- new_agent_memory-0.1.0/hub_data/agent_example.py +102 -0
- new_agent_memory-0.1.0/hub_data/auto_claude.py +266 -0
- new_agent_memory-0.1.0/hub_data/messages/claude_auto_state.json +15 -0
- new_agent_memory-0.1.0/hub_data/messages/codex_inbox.json +10 -0
- new_agent_memory-0.1.0/hub_data/messages/queue/codex/msg_97142f6389_1781802154.json +8 -0
- new_agent_memory-0.1.0/hub_data/messages/queue/codex/processed.json +7 -0
- new_agent_memory-0.1.0/hub_data/queue_protocol.py +355 -0
- new_agent_memory-0.1.0/main.py +679 -0
- new_agent_memory-0.1.0/memory_chunk.py +263 -0
- new_agent_memory-0.1.0/memory_layer_core.py +569 -0
- new_agent_memory-0.1.0/new_agent_memory/__init__.py +83 -0
- new_agent_memory-0.1.0/new_agent_memory/cli.py +215 -0
- new_agent_memory-0.1.0/pyproject.toml +52 -0
- new_agent_memory-0.1.0/retrieval.py +591 -0
- new_agent_memory-0.1.0/scripts/bench/benchmark_runner.py +259 -0
- new_agent_memory-0.1.0/scripts/bench/datasets/retrieval.json +52 -0
- new_agent_memory-0.1.0/scripts/bench/metrics.py +209 -0
- new_agent_memory-0.1.0/scripts/bench/run_benchmark.py +102 -0
- new_agent_memory-0.1.0/scripts/linux_chat.sh +14 -0
- new_agent_memory-0.1.0/scripts/migrate/json_to_sqlite.py +243 -0
- new_agent_memory-0.1.0/tests/test_agent_system.py +98 -0
- new_agent_memory-0.1.0/tests/test_attention_system.py +60 -0
- new_agent_memory-0.1.0/tests/test_auto_claude.py +39 -0
- new_agent_memory-0.1.0/tests/test_cli.py +94 -0
- new_agent_memory-0.1.0/tests/test_cognitive_runtime.py +152 -0
- new_agent_memory-0.1.0/tests/test_cognitive_state.py +76 -0
- new_agent_memory-0.1.0/tests/test_extraction.py +225 -0
- new_agent_memory-0.1.0/tests/test_hub.py +203 -0
- new_agent_memory-0.1.0/tests/test_hub_sub_agent.py +51 -0
- new_agent_memory-0.1.0/tests/test_hybrid_retrieval.py +287 -0
- new_agent_memory-0.1.0/tests/test_llm_planner.py +437 -0
- new_agent_memory-0.1.0/tests/test_memory_system.py +90 -0
- new_agent_memory-0.1.0/tests/test_multi_agent.py +267 -0
- new_agent_memory-0.1.0/tests/test_queue_protocol.py +40 -0
- new_agent_memory-0.1.0/tests/test_security.py +303 -0
- new_agent_memory-0.1.0/tests/test_store.py +415 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Copy this file to .env and fill in your OpenAI-compatible endpoint.
|
|
2
|
+
# Do not commit .env.
|
|
3
|
+
|
|
4
|
+
OPENAI_API_KEY=your-key-or-local-placeholder
|
|
5
|
+
OPENAI_BASE_URL=https://api.openai.com/v1
|
|
6
|
+
OPENAI_MODEL=gpt-4.1-mini
|
|
7
|
+
|
|
8
|
+
OPENAI_TEMPERATURE=0.1
|
|
9
|
+
OPENAI_MAX_TOKENS=800
|
|
10
|
+
OPENAI_TIMEOUT=60
|
|
11
|
+
OPENAI_USE_ENV_PROXY=false
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# 本地 LLM 配置示例
|
|
2
|
+
# 将此文件复制为 .env 并修改配置
|
|
3
|
+
|
|
4
|
+
# 远程 API(用于 LLMPlanner)
|
|
5
|
+
OPENAI_API_KEY=your-api-key
|
|
6
|
+
OPENAI_BASE_URL=https://api.openai.com/v1
|
|
7
|
+
OPENAI_MODEL=gpt-4
|
|
8
|
+
|
|
9
|
+
# 本地 4B 模型(用于 MemoryExtractor)
|
|
10
|
+
# 修改为你的本地模型 API 地址
|
|
11
|
+
LOCAL_LLM_API_BASE=http://localhost:8080/v1
|
|
12
|
+
LOCAL_LLM_API_KEY=not-needed
|
|
13
|
+
LOCAL_LLM_MODEL=your-4b-model
|
|
14
|
+
LOCAL_LLM_TEMPERATURE=0.1
|
|
15
|
+
LOCAL_LLM_MAX_TOKENS=1000
|
|
16
|
+
LOCAL_LLM_TIMEOUT=60
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write # Required for Trusted Publisher
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
name: Build
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
- name: Install build tools
|
|
20
|
+
run: pip install build
|
|
21
|
+
- name: Build package
|
|
22
|
+
run: python -m build
|
|
23
|
+
- name: Upload artifacts
|
|
24
|
+
uses: actions/upload-artifact@v4
|
|
25
|
+
with:
|
|
26
|
+
name: dist
|
|
27
|
+
path: dist/
|
|
28
|
+
|
|
29
|
+
publish:
|
|
30
|
+
name: Publish to PyPI
|
|
31
|
+
needs: build
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
environment:
|
|
34
|
+
name: pypi
|
|
35
|
+
url: https://pypi.org/p/new-agent-memory
|
|
36
|
+
permissions:
|
|
37
|
+
id-token: write
|
|
38
|
+
steps:
|
|
39
|
+
- name: Download artifacts
|
|
40
|
+
uses: actions/download-artifact@v4
|
|
41
|
+
with:
|
|
42
|
+
name: dist
|
|
43
|
+
path: dist/
|
|
44
|
+
- name: Publish to PyPI
|
|
45
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
name: tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, codex/*]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
name: Lint
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- name: Install linters
|
|
19
|
+
run: pip install ruff
|
|
20
|
+
- name: Run ruff
|
|
21
|
+
run: ruff check core/ main.py adapters/ hub/
|
|
22
|
+
|
|
23
|
+
test:
|
|
24
|
+
name: Test (Python ${{ matrix.python-version }})
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
strategy:
|
|
27
|
+
matrix:
|
|
28
|
+
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v4
|
|
31
|
+
- uses: actions/setup-python@v5
|
|
32
|
+
with:
|
|
33
|
+
python-version: ${{ matrix.python-version }}
|
|
34
|
+
- name: Install package
|
|
35
|
+
run: python -m pip install -e ".[dev]"
|
|
36
|
+
- name: Run tests with coverage
|
|
37
|
+
run: python -m pytest --cov=core --cov=main --cov-report=xml -q
|
|
38
|
+
- name: Upload coverage
|
|
39
|
+
if: matrix.python-version == '3.12'
|
|
40
|
+
uses: codecov/codecov-action@v4
|
|
41
|
+
with:
|
|
42
|
+
file: ./coverage.xml
|
|
43
|
+
|
|
44
|
+
security:
|
|
45
|
+
name: Security
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
steps:
|
|
48
|
+
- uses: actions/checkout@v4
|
|
49
|
+
- uses: actions/setup-python@v5
|
|
50
|
+
with:
|
|
51
|
+
python-version: "3.12"
|
|
52
|
+
- name: Install security tools
|
|
53
|
+
run: pip install bandit pip-audit
|
|
54
|
+
- name: Run bandit
|
|
55
|
+
run: bandit -r core/ main.py -ll -ii
|
|
56
|
+
- name: Run pip-audit
|
|
57
|
+
run: pip-audit
|
|
58
|
+
|
|
59
|
+
benchmark:
|
|
60
|
+
name: Benchmark
|
|
61
|
+
runs-on: ubuntu-latest
|
|
62
|
+
steps:
|
|
63
|
+
- uses: actions/checkout@v4
|
|
64
|
+
- uses: actions/setup-python@v5
|
|
65
|
+
with:
|
|
66
|
+
python-version: "3.12"
|
|
67
|
+
- name: Install package
|
|
68
|
+
run: python -m pip install -e ".[dev]"
|
|
69
|
+
- name: Run benchmark
|
|
70
|
+
run: python scripts/bench/run_benchmark.py --output benchmark_report.md
|
|
71
|
+
- name: Upload report
|
|
72
|
+
uses: actions/upload-artifact@v4
|
|
73
|
+
with:
|
|
74
|
+
name: benchmark-report
|
|
75
|
+
path: benchmark_report.md
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# Agent 接入指南
|
|
2
|
+
|
|
3
|
+
## 快速开始
|
|
4
|
+
|
|
5
|
+
### 1. 启动 Hub 服务器
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
python3 -m hub.cli start
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
服务器默认运行在 http://localhost:8420
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
### 2. Agent 接入
|
|
16
|
+
|
|
17
|
+
#### 方式 1: 直接读写文件(最简单)
|
|
18
|
+
|
|
19
|
+
**文件位置:**
|
|
20
|
+
```
|
|
21
|
+
hub_data/messages/
|
|
22
|
+
├── claude_inbox.json # Claude 收到的消息
|
|
23
|
+
├── claude_outbox.json # Claude 发送的回复
|
|
24
|
+
├── codex_inbox.json # Codex 收到的消息
|
|
25
|
+
├── codex_outbox.json # Codex 发送的回复
|
|
26
|
+
└── ...
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**读取消息:**
|
|
30
|
+
```bash
|
|
31
|
+
# 读取你的消息
|
|
32
|
+
cat hub_data/messages/你的名字_inbox.json
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**写入回复:**
|
|
36
|
+
```bash
|
|
37
|
+
# 写入你的回复
|
|
38
|
+
echo '{"content": "你的回复内容"}' > hub_data/messages/你的名字_outbox.json
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
#### 方式 2: 使用示例脚本
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# 运行 Claude 自动回复机器人
|
|
47
|
+
python3 hub_data/agent_example.py
|
|
48
|
+
|
|
49
|
+
# 运行 Codex 自动回复机器人
|
|
50
|
+
AGENT_NAME=codex python3 hub_data/agent_example.py
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
#### 方式 3: 使用 CLI
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# 启动 Claude 适配器
|
|
59
|
+
python3 -m adapters.cli claude --name "Claude"
|
|
60
|
+
|
|
61
|
+
# 启动 Codex 适配器
|
|
62
|
+
python3 -m adapters.cli codex --name "Codex"
|
|
63
|
+
|
|
64
|
+
# 启动人类客户端
|
|
65
|
+
python3 -m adapters.cli human --name "User"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 消息格式
|
|
71
|
+
|
|
72
|
+
### 收到的消息
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"id": "msg_xxx",
|
|
77
|
+
"channel_id": "general",
|
|
78
|
+
"sender_id": "agent_xxx",
|
|
79
|
+
"sender_name": "Claude",
|
|
80
|
+
"content": "消息内容",
|
|
81
|
+
"message_type": "text",
|
|
82
|
+
"metadata": {},
|
|
83
|
+
"created_at": 1234567890.0
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 发送的回复
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"content": "你的回复内容"
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 消息类型
|
|
98
|
+
|
|
99
|
+
| 类型 | 说明 | 示例 |
|
|
100
|
+
|------|------|------|
|
|
101
|
+
| `text` | 普通消息 | `"你好,我是 Claude"` |
|
|
102
|
+
| `task` | 任务消息 | `"请重构 main.py"` |
|
|
103
|
+
| `task_result` | 任务结果 | `"任务完成"` |
|
|
104
|
+
| `correction` | 纠错消息 | `"这里有除零错误"` |
|
|
105
|
+
| `error` | 错误消息 | `"执行失败"` |
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## @提及
|
|
110
|
+
|
|
111
|
+
如果消息中包含 `@你的名字`,表示在@你:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"content": "@Codex 帮我看看这段代码"
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 任务分配
|
|
122
|
+
|
|
123
|
+
如果收到任务消息:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"message_type": "task",
|
|
128
|
+
"content": "请重构 main.py",
|
|
129
|
+
"metadata": {
|
|
130
|
+
"assignee": "agent_xxx",
|
|
131
|
+
"priority": "high",
|
|
132
|
+
"context": {
|
|
133
|
+
"file": "main.py",
|
|
134
|
+
"line": 42
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 纠错消息
|
|
143
|
+
|
|
144
|
+
如果收到纠错消息:
|
|
145
|
+
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"message_type": "correction",
|
|
149
|
+
"content": "@Codex 这里有除零错误",
|
|
150
|
+
"metadata": {
|
|
151
|
+
"issue": "这里有除零错误",
|
|
152
|
+
"suggestion": "检查分母是否为零",
|
|
153
|
+
"code_fix": "if denominator != 0:\n result = numerator / denominator"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Python 代码示例
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
import json
|
|
164
|
+
import os
|
|
165
|
+
import time
|
|
166
|
+
|
|
167
|
+
# 配置
|
|
168
|
+
AGENT_NAME = "claude" # 修改为你的 agent 名称
|
|
169
|
+
HUB_DATA_DIR = "hub_data/messages"
|
|
170
|
+
INBOX_FILE = os.path.join(HUB_DATA_DIR, f"{AGENT_NAME}_inbox.json")
|
|
171
|
+
OUTBOX_FILE = os.path.join(HUB_DATA_DIR, f"{AGENT_NAME}_outbox.json")
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def read_inbox():
|
|
175
|
+
"""读取消息"""
|
|
176
|
+
if not os.path.exists(INBOX_FILE):
|
|
177
|
+
return None
|
|
178
|
+
try:
|
|
179
|
+
with open(INBOX_FILE, encoding="utf-8") as f:
|
|
180
|
+
msg = json.load(f)
|
|
181
|
+
os.remove(INBOX_FILE)
|
|
182
|
+
return msg
|
|
183
|
+
except:
|
|
184
|
+
return None
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def send_reply(content):
|
|
188
|
+
"""发送回复"""
|
|
189
|
+
with open(OUTBOX_FILE, "w", encoding="utf-8") as f:
|
|
190
|
+
json.dump({"content": content}, f, ensure_ascii=False)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
# 主循环
|
|
194
|
+
while True:
|
|
195
|
+
msg = read_inbox()
|
|
196
|
+
if msg:
|
|
197
|
+
print(f"收到: {msg['content']}")
|
|
198
|
+
|
|
199
|
+
# 自动回复
|
|
200
|
+
if f"@{AGENT_NAME}" in msg["content"].lower():
|
|
201
|
+
send_reply("收到!我来看看...")
|
|
202
|
+
else:
|
|
203
|
+
send_reply("嗯嗯,了解了~")
|
|
204
|
+
|
|
205
|
+
time.sleep(1)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Hub API
|
|
211
|
+
|
|
212
|
+
### 获取状态
|
|
213
|
+
```bash
|
|
214
|
+
curl http://localhost:8420/api/stats
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 获取 Agent 列表
|
|
218
|
+
```bash
|
|
219
|
+
curl http://localhost:8420/api/agents
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### 获取频道列表
|
|
223
|
+
```bash
|
|
224
|
+
curl http://localhost:8420/api/channels
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### 获取消息
|
|
228
|
+
```bash
|
|
229
|
+
curl http://localhost:8420/api/channels/general/messages
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### 发送消息
|
|
233
|
+
```bash
|
|
234
|
+
curl -X POST http://localhost:8420/api/channels/general/messages \
|
|
235
|
+
-H "Content-Type: application/json" \
|
|
236
|
+
-d '{"sender_name": "MyAgent", "content": "你好!"}'
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Web UI
|
|
242
|
+
|
|
243
|
+
访问 http://localhost:8420/ui 查看 Web 界面
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 常见问题
|
|
248
|
+
|
|
249
|
+
### Q: 如何知道有新消息?
|
|
250
|
+
A: 检查 `hub_data/messages/你的名字_inbox.json` 是否存在
|
|
251
|
+
|
|
252
|
+
### Q: 如何回复消息?
|
|
253
|
+
A: 写入 `hub_data/messages/你的名字_outbox.json`
|
|
254
|
+
|
|
255
|
+
### Q: 如何@某个 agent?
|
|
256
|
+
A: 在消息中包含 `@agent名字`
|
|
257
|
+
|
|
258
|
+
### Q: 如何查看所有 agent?
|
|
259
|
+
A: 访问 http://localhost:8420/api/agents
|
|
260
|
+
|
|
261
|
+
### Q: 消息被覆盖了怎么办?
|
|
262
|
+
A: 每条消息都会覆盖上一条,需要及时处理
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## 文件结构
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
new-agent-memory/
|
|
270
|
+
├── hub_data/
|
|
271
|
+
│ ├── README.md # Hub 数据说明
|
|
272
|
+
│ ├── agent_example.py # 自动回复示例
|
|
273
|
+
│ └── messages/ # 消息目录
|
|
274
|
+
│ ├── claude_inbox.json
|
|
275
|
+
│ ├── claude_outbox.json
|
|
276
|
+
│ ├── codex_inbox.json
|
|
277
|
+
│ ├── codex_outbox.json
|
|
278
|
+
│ └── ...
|
|
279
|
+
├── adapters/
|
|
280
|
+
│ ├── base_adapter.py # 统一基类
|
|
281
|
+
│ ├── claude_adapter.py # Claude 适配器
|
|
282
|
+
│ ├── codex_adapter.py # Codex 适配器
|
|
283
|
+
│ └── cli.py # CLI 入口
|
|
284
|
+
└── hub/
|
|
285
|
+
├── server.py # Hub 服务器
|
|
286
|
+
└── ...
|
|
287
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
FROM python:3.11-slim
|
|
2
|
+
|
|
3
|
+
ENV PYTHONDONTWRITEBYTECODE=1
|
|
4
|
+
ENV PYTHONUNBUFFERED=1
|
|
5
|
+
ENV PIP_NO_CACHE_DIR=1
|
|
6
|
+
|
|
7
|
+
WORKDIR /app
|
|
8
|
+
|
|
9
|
+
COPY pyproject.toml README.md LICENSE ./
|
|
10
|
+
COPY core ./core
|
|
11
|
+
COPY new_agent_memory ./new_agent_memory
|
|
12
|
+
COPY hub ./hub
|
|
13
|
+
COPY adapters ./adapters
|
|
14
|
+
COPY forgotten_layer.py main.py memory_chunk.py memory_layer_core.py retrieval.py ./
|
|
15
|
+
|
|
16
|
+
RUN python -m pip install --upgrade pip \
|
|
17
|
+
&& python -m pip install -e .
|
|
18
|
+
|
|
19
|
+
RUN useradd --create-home --shell /bin/bash agent \
|
|
20
|
+
&& mkdir -p /app/memory_data \
|
|
21
|
+
&& chown -R agent:agent /app
|
|
22
|
+
|
|
23
|
+
USER agent
|
|
24
|
+
|
|
25
|
+
VOLUME ["/app/memory_data"]
|
|
26
|
+
|
|
27
|
+
ENTRYPOINT ["new-agent-memory"]
|
|
28
|
+
CMD ["chat", "--runtime", "--max-steps", "4"]
|