coomi-agent 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.
- coomi_agent-0.1.0/LICENSE +21 -0
- coomi_agent-0.1.0/PKG-INFO +258 -0
- coomi_agent-0.1.0/README.md +224 -0
- coomi_agent-0.1.0/coomi/__init__.py +8 -0
- coomi_agent-0.1.0/coomi/__main__.py +5 -0
- coomi_agent-0.1.0/coomi/async_utils.py +10 -0
- coomi_agent-0.1.0/coomi/cli.py +28 -0
- coomi_agent-0.1.0/coomi/engine/__init__.py +37 -0
- coomi_agent-0.1.0/coomi/engine/checkpoint.py +147 -0
- coomi_agent-0.1.0/coomi/engine/loop.py +681 -0
- coomi_agent-0.1.0/coomi/engine/loop_runner.py +472 -0
- coomi_agent-0.1.0/coomi/engine/retry_policy.py +108 -0
- coomi_agent-0.1.0/coomi/engine/session.py +335 -0
- coomi_agent-0.1.0/coomi/engine/spec_parser.py +96 -0
- coomi_agent-0.1.0/coomi/engine/tool_executor.py +393 -0
- coomi_agent-0.1.0/coomi/first_run.py +206 -0
- coomi_agent-0.1.0/coomi/security/__init__.py +17 -0
- coomi_agent-0.1.0/coomi/security/bash_safety.py +83 -0
- coomi_agent-0.1.0/coomi/security/hooks.py +51 -0
- coomi_agent-0.1.0/coomi/security/permissions.py +143 -0
- coomi_agent-0.1.0/coomi/services/__init__.py +8 -0
- coomi_agent-0.1.0/coomi/services/context/__init__.py +11 -0
- coomi_agent-0.1.0/coomi/services/context/cache.py +218 -0
- coomi_agent-0.1.0/coomi/services/context/compressor.py +305 -0
- coomi_agent-0.1.0/coomi/services/context/message_guard.py +136 -0
- coomi_agent-0.1.0/coomi/services/llm/__init__.py +6 -0
- coomi_agent-0.1.0/coomi/services/llm/anthropic.py +241 -0
- coomi_agent-0.1.0/coomi/services/llm/config.py +281 -0
- coomi_agent-0.1.0/coomi/services/llm/deepseek.py +46 -0
- coomi_agent-0.1.0/coomi/services/llm/factory.py +90 -0
- coomi_agent-0.1.0/coomi/services/llm/generic.py +347 -0
- coomi_agent-0.1.0/coomi/services/llm/llm.py +32 -0
- coomi_agent-0.1.0/coomi/services/llm/openai.py +184 -0
- coomi_agent-0.1.0/coomi/services/llm/provider.py +64 -0
- coomi_agent-0.1.0/coomi/services/llm/text_tool_calls.py +1133 -0
- coomi_agent-0.1.0/coomi/services/memory/__init__.py +7 -0
- coomi_agent-0.1.0/coomi/services/memory/extractor.py +150 -0
- coomi_agent-0.1.0/coomi/services/memory/manager.py +349 -0
- coomi_agent-0.1.0/coomi/services/memory/recall.py +293 -0
- coomi_agent-0.1.0/coomi/services/memory/types.py +95 -0
- coomi_agent-0.1.0/coomi/services/session_history.py +259 -0
- coomi_agent-0.1.0/coomi/tools/__init__.py +5 -0
- coomi_agent-0.1.0/coomi/tools/agent/__init__.py +4 -0
- coomi_agent-0.1.0/coomi/tools/agent/agent.py +48 -0
- coomi_agent-0.1.0/coomi/tools/base.py +69 -0
- coomi_agent-0.1.0/coomi/tools/browser/__init__.py +1 -0
- coomi_agent-0.1.0/coomi/tools/config/__init__.py +4 -0
- coomi_agent-0.1.0/coomi/tools/config/config.py +57 -0
- coomi_agent-0.1.0/coomi/tools/file_ops/__init__.py +6 -0
- coomi_agent-0.1.0/coomi/tools/file_ops/edit.py +86 -0
- coomi_agent-0.1.0/coomi/tools/file_ops/read.py +57 -0
- coomi_agent-0.1.0/coomi/tools/file_ops/write.py +48 -0
- coomi_agent-0.1.0/coomi/tools/registry.py +160 -0
- coomi_agent-0.1.0/coomi/tools/search/__init__.py +5 -0
- coomi_agent-0.1.0/coomi/tools/search/glob.py +53 -0
- coomi_agent-0.1.0/coomi/tools/search/grep.py +134 -0
- coomi_agent-0.1.0/coomi/tools/shell/__init__.py +5 -0
- coomi_agent-0.1.0/coomi/tools/shell/bash.py +148 -0
- coomi_agent-0.1.0/coomi/tools/shell/powershell.py +125 -0
- coomi_agent-0.1.0/coomi/tools/task/__init__.py +4 -0
- coomi_agent-0.1.0/coomi/tools/task/todo.py +65 -0
- coomi_agent-0.1.0/coomi/tools/user/__init__.py +4 -0
- coomi_agent-0.1.0/coomi/tools/user/ask_question.py +105 -0
- coomi_agent-0.1.0/coomi/tools/web/__init__.py +5 -0
- coomi_agent-0.1.0/coomi/tools/web/fetch.py +150 -0
- coomi_agent-0.1.0/coomi/tools/web/search.py +442 -0
- coomi_agent-0.1.0/coomi/tools/workspace/__init__.py +4 -0
- coomi_agent-0.1.0/coomi/tools/workspace/plan_mode.py +110 -0
- coomi_agent-0.1.0/coomi/types.py +153 -0
- coomi_agent-0.1.0/coomi/ui/__init__.py +12 -0
- coomi_agent-0.1.0/coomi/ui/events.py +115 -0
- coomi_agent-0.1.0/coomi/ui/screens/__init__.py +1 -0
- coomi_agent-0.1.0/coomi/ui/screens/command_palette.py +135 -0
- coomi_agent-0.1.0/coomi/ui/screens/main_screen.py +139 -0
- coomi_agent-0.1.0/coomi/ui/screens/provider_edit_screen.py +180 -0
- coomi_agent-0.1.0/coomi/ui/screens/provider_list_screen.py +108 -0
- coomi_agent-0.1.0/coomi/ui/screens/settings_screen.py +73 -0
- coomi_agent-0.1.0/coomi/ui/status_line.py +132 -0
- coomi_agent-0.1.0/coomi/ui/tcss/coomi.tcss +218 -0
- coomi_agent-0.1.0/coomi/ui/textual_app.py +1705 -0
- coomi_agent-0.1.0/coomi/ui/tool_formatter.py +94 -0
- coomi_agent-0.1.0/coomi/ui/widgets/__init__.py +17 -0
- coomi_agent-0.1.0/coomi/ui/widgets/command_autocomplete.py +92 -0
- coomi_agent-0.1.0/coomi/ui/widgets/command_list.py +77 -0
- coomi_agent-0.1.0/coomi/ui/widgets/context_picker.py +84 -0
- coomi_agent-0.1.0/coomi/ui/widgets/custom_header.py +179 -0
- coomi_agent-0.1.0/coomi/ui/widgets/model_picker.py +102 -0
- coomi_agent-0.1.0/coomi/ui/widgets/plan_panel.py +186 -0
- coomi_agent-0.1.0/coomi/ui/widgets/prompt_text_area.py +54 -0
- coomi_agent-0.1.0/coomi/ui/widgets/selectable_rich_log.py +253 -0
- coomi_agent-0.1.0/coomi/ui/widgets/status_panel.py +185 -0
- coomi_agent-0.1.0/coomi/ui/widgets/streaming_preview.py +126 -0
- coomi_agent-0.1.0/coomi/ui/widgets/tool_call_banner.py +97 -0
- coomi_agent-0.1.0/coomi/ui/widgets/welcome_panel.py +309 -0
- coomi_agent-0.1.0/coomi_agent.egg-info/PKG-INFO +258 -0
- coomi_agent-0.1.0/coomi_agent.egg-info/SOURCES.txt +106 -0
- coomi_agent-0.1.0/coomi_agent.egg-info/dependency_links.txt +1 -0
- coomi_agent-0.1.0/coomi_agent.egg-info/entry_points.txt +2 -0
- coomi_agent-0.1.0/coomi_agent.egg-info/requires.txt +14 -0
- coomi_agent-0.1.0/coomi_agent.egg-info/top_level.txt +1 -0
- coomi_agent-0.1.0/pyproject.toml +65 -0
- coomi_agent-0.1.0/setup.cfg +4 -0
- coomi_agent-0.1.0/tests/test_context_reliability.py +1313 -0
- coomi_agent-0.1.0/tests/test_memory_latency.py +100 -0
- coomi_agent-0.1.0/tests/test_session_history.py +130 -0
- coomi_agent-0.1.0/tests/test_ui_selection.py +95 -0
- coomi_agent-0.1.0/tests/test_web_fetch.py +51 -0
- coomi_agent-0.1.0/tests/test_web_search.py +167 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Septemc and Flowby
|
|
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,258 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: coomi-agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 一款纯净的自主 Agent 系统。
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/Septemc/Coomi
|
|
7
|
+
Project-URL: Repository, https://github.com/Septemc/Coomi
|
|
8
|
+
Project-URL: Issues, https://github.com/Septemc/Coomi/issues
|
|
9
|
+
Keywords: ai,agent,cli,tui,coding-assistant
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: openai>=1.6.0
|
|
22
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
23
|
+
Requires-Dist: rich>=13.0.0
|
|
24
|
+
Requires-Dist: textual>=1.0.0
|
|
25
|
+
Requires-Dist: httpx>=0.25.0
|
|
26
|
+
Provides-Extra: anthropic
|
|
27
|
+
Requires-Dist: anthropic>=0.104.0; extra == "anthropic"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
32
|
+
Requires-Dist: mypy>=1.7.0; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# Coomi Agent
|
|
36
|
+
|
|
37
|
+
一个比较纯净的 AI Agent项目。基于CLI的自主 Agent,能读取文件、编辑代码、执行命令、管理任务。
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
## 特性
|
|
42
|
+
|
|
43
|
+
- **纯净 Agent 设计** — 以开发学习为目标,流程透明,模块边界清晰,便于观察、复盘和二次改造。
|
|
44
|
+
- **核心能力完整** — 覆盖文件操作、搜索、Shell、网页、任务、子 Agent 、 Plan 模式和Loop模式等基础工具链。
|
|
45
|
+
- **可切换的 LLM Provider** — 支持 DeepSeek、OpenAI、Anthropic 和兼容 OpenAI API 的通用服务。
|
|
46
|
+
- **上下文与记忆机制** — 提供上下文压缩、记忆管理、语义召回和工具结果缓存等基础工程能力。
|
|
47
|
+
- **流式终端界面** — 基于 Textual 的 TUI,支持流式输出、工具调用提示和状态信息展示。
|
|
48
|
+
|
|
49
|
+
## 快速开始
|
|
50
|
+
|
|
51
|
+
### 环境要求
|
|
52
|
+
|
|
53
|
+
- Python >= 3.9
|
|
54
|
+
|
|
55
|
+
### 安装
|
|
56
|
+
|
|
57
|
+
#### 从 PyPI 安装(推荐)
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install coomi-agent
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### 从源码安装
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
git clone https://github.com/Septemc/Coomi.git
|
|
67
|
+
cd Coomi
|
|
68
|
+
pip install -e .
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Python 环境说明
|
|
72
|
+
|
|
73
|
+
> **注意**:如果你的系统有多个 Python 环境,`pip install -e .` 会安装到当前 shell 激活的 Python 环境中。
|
|
74
|
+
|
|
75
|
+
**推荐安装位置**:默认 Python 环境对应的库目录,也就是当前 Python 解释器的 `site-packages`。
|
|
76
|
+
|
|
77
|
+
| 环境类型 | 常见安装位置 |
|
|
78
|
+
| ----------- | ------------------------------------- |
|
|
79
|
+
| 系统 Python | `Python 安装目录\Lib\site-packages` |
|
|
80
|
+
| Conda 环境 | `环境目录\Lib\site-packages` |
|
|
81
|
+
| 虚拟环境 | `项目目录\.venv\Lib\site-packages` |
|
|
82
|
+
|
|
83
|
+
**验证当前环境**:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# 查看 Python 路径
|
|
87
|
+
which python
|
|
88
|
+
# 或 Windows:
|
|
89
|
+
where python
|
|
90
|
+
|
|
91
|
+
# 查看 pip 目标路径
|
|
92
|
+
python -m pip show coomi-agent | grep Location
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**推荐安装方式**:
|
|
96
|
+
|
|
97
|
+
先激活你希望使用的默认 Python 环境,再执行:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
python -m pip install -e .
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 更新
|
|
104
|
+
|
|
105
|
+
#### 从 PyPI 更新(推荐)
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install --upgrade coomi-agent
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### 从源码更新
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
cd Coomi
|
|
115
|
+
git pull origin main
|
|
116
|
+
pip install -e .
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**注意**:从源码安装(`pip install -e .`)时,代码会指向你的本地目录,每次 `git pull` 后无需重新安装。只有当 `pyproject.toml` 中的依赖发生变化时才需要重新执行 `pip install -e .`。
|
|
120
|
+
|
|
121
|
+
### 首次运行
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
coomi
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
首次运行时,Coomi 会自动引导你配置 LLM Provider。配置优先级:
|
|
128
|
+
|
|
129
|
+
1. **环境变量** — 自动检测 `DEEPSEEK_API_KEY`、`OPENAI_API_KEY`、`ANTHROPIC_API_KEY`
|
|
130
|
+
2. **.env 文件** — 项目根目录的 `.env` 文件,用于开发学习使用
|
|
131
|
+
3. **交互式配置** — 终端交互引导
|
|
132
|
+
|
|
133
|
+
### 配置文件
|
|
134
|
+
|
|
135
|
+
所有模型配置存储在 `~/.coomi/config/providers.json`:
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"version": 1,
|
|
140
|
+
"active": "default",
|
|
141
|
+
"providers": {
|
|
142
|
+
"default": {
|
|
143
|
+
"type": "deepseek",
|
|
144
|
+
"display": "DeepSeek V4",
|
|
145
|
+
"api_key": "sk-xxx",
|
|
146
|
+
"base_url": "https://api.deepseek.com",
|
|
147
|
+
"model": "deepseek-v4-pro",
|
|
148
|
+
"fast_model": "deepseek-v4-flash"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
支持的 Provider 类型:`deepseek`、`openai`、`anthropic`、`generic`(任意兼容 OpenAI API 的服务)。
|
|
155
|
+
|
|
156
|
+
### 运行方式
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# CLI 命令(推荐)
|
|
160
|
+
coomi
|
|
161
|
+
|
|
162
|
+
# 模块运行
|
|
163
|
+
python -m coomi
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## 内置命令
|
|
167
|
+
|
|
168
|
+
| 命令 | 说明 |
|
|
169
|
+
| --------------------------- | ----------------------------------------------- |
|
|
170
|
+
| `/model` | 列出所有可用模型 |
|
|
171
|
+
| `/model <id>` | 切换到指定 Provider |
|
|
172
|
+
| `/context` | 显示当前上下文窗口大小 |
|
|
173
|
+
| `/context 256k` | 设置上下文窗口(如 `128k`、`512k`、`1m`) |
|
|
174
|
+
| `/memory list` | 列出所有记忆 |
|
|
175
|
+
| `/memory add <内容>` | 添加新记忆 |
|
|
176
|
+
| `/memory search <关键词>` | 搜索记忆 |
|
|
177
|
+
| `/memory delete <名称>` | 删除记忆 |
|
|
178
|
+
| `/clear` | 清除当前会话 |
|
|
179
|
+
| `exit` / `quit` | 退出 |
|
|
180
|
+
|
|
181
|
+
## 架构
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
coomi/ # 主包
|
|
185
|
+
├── __init__.py # 版本信息
|
|
186
|
+
├── __main__.py # python -m coomi 入口
|
|
187
|
+
├── cli.py # CLI 入口(coomi 命令)
|
|
188
|
+
├── setup.py # 首次配置引导
|
|
189
|
+
├── types.py # Message, Session, ToolCall, LLMResponse
|
|
190
|
+
├── engine/
|
|
191
|
+
│ ├── loop.py # AgentLoop — 感知-决策-执行循环
|
|
192
|
+
│ └── session.py # SessionManager,System Prompt 构建器
|
|
193
|
+
├── services/
|
|
194
|
+
│ ├── llm/ # Provider 层(抽象基类 + 4 种实现)
|
|
195
|
+
│ │ ├── provider.py # LLMProvider 抽象基类
|
|
196
|
+
│ │ ├── generic.py # GenericOpenAIProvider(配置驱动)
|
|
197
|
+
│ │ ├── deepseek.py # DeepSeekProvider(thinking mode)
|
|
198
|
+
│ │ ├── openai.py # OpenAIProvider
|
|
199
|
+
│ │ ├── anthropic.py # AnthropicProvider(可选依赖)
|
|
200
|
+
│ │ ├── factory.py # Provider 工厂 + Flash 模型降级
|
|
201
|
+
│ │ └── config.py # ConfigManager(~/.coomi/config/providers.json)
|
|
202
|
+
│ ├── context/
|
|
203
|
+
│ │ ├── compressor.py # 三层压缩
|
|
204
|
+
│ │ └── cache.py # 工具结果磁盘缓存
|
|
205
|
+
│ └── memory/
|
|
206
|
+
│ ├── manager.py # 三层记忆存储
|
|
207
|
+
│ ├── extractor.py # 对话自动提取
|
|
208
|
+
│ └── recall.py # 语义记忆召回
|
|
209
|
+
├── tools/ # 15+ 内置工具
|
|
210
|
+
│ ├── file_ops/ # Read, Write, Edit
|
|
211
|
+
│ ├── search/ # Glob, Grep
|
|
212
|
+
│ ├── shell/ # Bash, PowerShell
|
|
213
|
+
│ ├── web/ # WebFetch, WebSearch
|
|
214
|
+
│ ├── task/ # TodoWrite
|
|
215
|
+
│ ├── agent/ # 子 Agent 委托
|
|
216
|
+
│ ├── user/ # AskUserQuestion
|
|
217
|
+
│ └── workspace/ # Plan 模式(进入/退出)
|
|
218
|
+
└── ui/ # Textual TUI 界面
|
|
219
|
+
├── textual_app.py # 主应用
|
|
220
|
+
├── status_line.py # 状态栏(模型 + Token 用量)
|
|
221
|
+
├── tool_formatter.py # 工具调用详情格式化
|
|
222
|
+
├── screens/ # 屏幕
|
|
223
|
+
└── widgets/ # 组件
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## 上下文压缩
|
|
227
|
+
|
|
228
|
+
三层压缩,当前估算 Token 数超过上下文窗口 90% 时触发:
|
|
229
|
+
|
|
230
|
+
1. **Microcompact(微清理)** — 将超出保留数量(6 条)的旧工具结果内容替换为 `[cleared]` 标记。零 API 开销。
|
|
231
|
+
2. **消息裁剪** — 保留第一条消息 + 最近 8 条消息。零 API 开销。
|
|
232
|
+
3. **LLM 摘要** — 生成 9 段结构化摘要(核心需求、关键概念、文件与代码、错误与修复、问题解决、用户消息、待办任务、当前工作、建议下一步)。使用当前模型。
|
|
233
|
+
|
|
234
|
+
## 记忆系统
|
|
235
|
+
|
|
236
|
+
三层存储,优先级逐级递减:
|
|
237
|
+
|
|
238
|
+
1. `.coomi/memory/` — 项目本地(最高优先级)
|
|
239
|
+
2. `~/.coomi/projects/{hash}/memory/` — 项目全局
|
|
240
|
+
3. `~/.coomi/memory/` — 全局(所有项目共享)
|
|
241
|
+
|
|
242
|
+
记忆类型:`user`(用户偏好)、`feedback`(反馈纠正)、`project`(项目上下文)、`reference`(外部引用)。
|
|
243
|
+
|
|
244
|
+
MemoryExtractor 自动分析对话并保存相关记忆。MemoryRecall 执行语义选择,将相关记忆注入 System Prompt。
|
|
245
|
+
|
|
246
|
+
## 项目参考来源
|
|
247
|
+
|
|
248
|
+
本项目在工程复现和实现思路上参考了以下项目(或源码实现,或界面交互体验):
|
|
249
|
+
|
|
250
|
+
- Claude Code
|
|
251
|
+
- Codex
|
|
252
|
+
- OpenCode
|
|
253
|
+
|
|
254
|
+
参考重点主要是 Agent 主循环、工具调用编排、上下文管理和终端交互方式,不代表与原项目具有相同实现或功能范围。
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
MIT,详见 [LICENSE](LICENSE)
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Coomi Agent
|
|
2
|
+
|
|
3
|
+
一个比较纯净的 AI Agent项目。基于CLI的自主 Agent,能读取文件、编辑代码、执行命令、管理任务。
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- **纯净 Agent 设计** — 以开发学习为目标,流程透明,模块边界清晰,便于观察、复盘和二次改造。
|
|
10
|
+
- **核心能力完整** — 覆盖文件操作、搜索、Shell、网页、任务、子 Agent 、 Plan 模式和Loop模式等基础工具链。
|
|
11
|
+
- **可切换的 LLM Provider** — 支持 DeepSeek、OpenAI、Anthropic 和兼容 OpenAI API 的通用服务。
|
|
12
|
+
- **上下文与记忆机制** — 提供上下文压缩、记忆管理、语义召回和工具结果缓存等基础工程能力。
|
|
13
|
+
- **流式终端界面** — 基于 Textual 的 TUI,支持流式输出、工具调用提示和状态信息展示。
|
|
14
|
+
|
|
15
|
+
## 快速开始
|
|
16
|
+
|
|
17
|
+
### 环境要求
|
|
18
|
+
|
|
19
|
+
- Python >= 3.9
|
|
20
|
+
|
|
21
|
+
### 安装
|
|
22
|
+
|
|
23
|
+
#### 从 PyPI 安装(推荐)
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install coomi-agent
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### 从源码安装
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/Septemc/Coomi.git
|
|
33
|
+
cd Coomi
|
|
34
|
+
pip install -e .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Python 环境说明
|
|
38
|
+
|
|
39
|
+
> **注意**:如果你的系统有多个 Python 环境,`pip install -e .` 会安装到当前 shell 激活的 Python 环境中。
|
|
40
|
+
|
|
41
|
+
**推荐安装位置**:默认 Python 环境对应的库目录,也就是当前 Python 解释器的 `site-packages`。
|
|
42
|
+
|
|
43
|
+
| 环境类型 | 常见安装位置 |
|
|
44
|
+
| ----------- | ------------------------------------- |
|
|
45
|
+
| 系统 Python | `Python 安装目录\Lib\site-packages` |
|
|
46
|
+
| Conda 环境 | `环境目录\Lib\site-packages` |
|
|
47
|
+
| 虚拟环境 | `项目目录\.venv\Lib\site-packages` |
|
|
48
|
+
|
|
49
|
+
**验证当前环境**:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# 查看 Python 路径
|
|
53
|
+
which python
|
|
54
|
+
# 或 Windows:
|
|
55
|
+
where python
|
|
56
|
+
|
|
57
|
+
# 查看 pip 目标路径
|
|
58
|
+
python -m pip show coomi-agent | grep Location
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**推荐安装方式**:
|
|
62
|
+
|
|
63
|
+
先激活你希望使用的默认 Python 环境,再执行:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
python -m pip install -e .
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 更新
|
|
70
|
+
|
|
71
|
+
#### 从 PyPI 更新(推荐)
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install --upgrade coomi-agent
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### 从源码更新
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
cd Coomi
|
|
81
|
+
git pull origin main
|
|
82
|
+
pip install -e .
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**注意**:从源码安装(`pip install -e .`)时,代码会指向你的本地目录,每次 `git pull` 后无需重新安装。只有当 `pyproject.toml` 中的依赖发生变化时才需要重新执行 `pip install -e .`。
|
|
86
|
+
|
|
87
|
+
### 首次运行
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
coomi
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
首次运行时,Coomi 会自动引导你配置 LLM Provider。配置优先级:
|
|
94
|
+
|
|
95
|
+
1. **环境变量** — 自动检测 `DEEPSEEK_API_KEY`、`OPENAI_API_KEY`、`ANTHROPIC_API_KEY`
|
|
96
|
+
2. **.env 文件** — 项目根目录的 `.env` 文件,用于开发学习使用
|
|
97
|
+
3. **交互式配置** — 终端交互引导
|
|
98
|
+
|
|
99
|
+
### 配置文件
|
|
100
|
+
|
|
101
|
+
所有模型配置存储在 `~/.coomi/config/providers.json`:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"version": 1,
|
|
106
|
+
"active": "default",
|
|
107
|
+
"providers": {
|
|
108
|
+
"default": {
|
|
109
|
+
"type": "deepseek",
|
|
110
|
+
"display": "DeepSeek V4",
|
|
111
|
+
"api_key": "sk-xxx",
|
|
112
|
+
"base_url": "https://api.deepseek.com",
|
|
113
|
+
"model": "deepseek-v4-pro",
|
|
114
|
+
"fast_model": "deepseek-v4-flash"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
支持的 Provider 类型:`deepseek`、`openai`、`anthropic`、`generic`(任意兼容 OpenAI API 的服务)。
|
|
121
|
+
|
|
122
|
+
### 运行方式
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# CLI 命令(推荐)
|
|
126
|
+
coomi
|
|
127
|
+
|
|
128
|
+
# 模块运行
|
|
129
|
+
python -m coomi
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 内置命令
|
|
133
|
+
|
|
134
|
+
| 命令 | 说明 |
|
|
135
|
+
| --------------------------- | ----------------------------------------------- |
|
|
136
|
+
| `/model` | 列出所有可用模型 |
|
|
137
|
+
| `/model <id>` | 切换到指定 Provider |
|
|
138
|
+
| `/context` | 显示当前上下文窗口大小 |
|
|
139
|
+
| `/context 256k` | 设置上下文窗口(如 `128k`、`512k`、`1m`) |
|
|
140
|
+
| `/memory list` | 列出所有记忆 |
|
|
141
|
+
| `/memory add <内容>` | 添加新记忆 |
|
|
142
|
+
| `/memory search <关键词>` | 搜索记忆 |
|
|
143
|
+
| `/memory delete <名称>` | 删除记忆 |
|
|
144
|
+
| `/clear` | 清除当前会话 |
|
|
145
|
+
| `exit` / `quit` | 退出 |
|
|
146
|
+
|
|
147
|
+
## 架构
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
coomi/ # 主包
|
|
151
|
+
├── __init__.py # 版本信息
|
|
152
|
+
├── __main__.py # python -m coomi 入口
|
|
153
|
+
├── cli.py # CLI 入口(coomi 命令)
|
|
154
|
+
├── setup.py # 首次配置引导
|
|
155
|
+
├── types.py # Message, Session, ToolCall, LLMResponse
|
|
156
|
+
├── engine/
|
|
157
|
+
│ ├── loop.py # AgentLoop — 感知-决策-执行循环
|
|
158
|
+
│ └── session.py # SessionManager,System Prompt 构建器
|
|
159
|
+
├── services/
|
|
160
|
+
│ ├── llm/ # Provider 层(抽象基类 + 4 种实现)
|
|
161
|
+
│ │ ├── provider.py # LLMProvider 抽象基类
|
|
162
|
+
│ │ ├── generic.py # GenericOpenAIProvider(配置驱动)
|
|
163
|
+
│ │ ├── deepseek.py # DeepSeekProvider(thinking mode)
|
|
164
|
+
│ │ ├── openai.py # OpenAIProvider
|
|
165
|
+
│ │ ├── anthropic.py # AnthropicProvider(可选依赖)
|
|
166
|
+
│ │ ├── factory.py # Provider 工厂 + Flash 模型降级
|
|
167
|
+
│ │ └── config.py # ConfigManager(~/.coomi/config/providers.json)
|
|
168
|
+
│ ├── context/
|
|
169
|
+
│ │ ├── compressor.py # 三层压缩
|
|
170
|
+
│ │ └── cache.py # 工具结果磁盘缓存
|
|
171
|
+
│ └── memory/
|
|
172
|
+
│ ├── manager.py # 三层记忆存储
|
|
173
|
+
│ ├── extractor.py # 对话自动提取
|
|
174
|
+
│ └── recall.py # 语义记忆召回
|
|
175
|
+
├── tools/ # 15+ 内置工具
|
|
176
|
+
│ ├── file_ops/ # Read, Write, Edit
|
|
177
|
+
│ ├── search/ # Glob, Grep
|
|
178
|
+
│ ├── shell/ # Bash, PowerShell
|
|
179
|
+
│ ├── web/ # WebFetch, WebSearch
|
|
180
|
+
│ ├── task/ # TodoWrite
|
|
181
|
+
│ ├── agent/ # 子 Agent 委托
|
|
182
|
+
│ ├── user/ # AskUserQuestion
|
|
183
|
+
│ └── workspace/ # Plan 模式(进入/退出)
|
|
184
|
+
└── ui/ # Textual TUI 界面
|
|
185
|
+
├── textual_app.py # 主应用
|
|
186
|
+
├── status_line.py # 状态栏(模型 + Token 用量)
|
|
187
|
+
├── tool_formatter.py # 工具调用详情格式化
|
|
188
|
+
├── screens/ # 屏幕
|
|
189
|
+
└── widgets/ # 组件
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## 上下文压缩
|
|
193
|
+
|
|
194
|
+
三层压缩,当前估算 Token 数超过上下文窗口 90% 时触发:
|
|
195
|
+
|
|
196
|
+
1. **Microcompact(微清理)** — 将超出保留数量(6 条)的旧工具结果内容替换为 `[cleared]` 标记。零 API 开销。
|
|
197
|
+
2. **消息裁剪** — 保留第一条消息 + 最近 8 条消息。零 API 开销。
|
|
198
|
+
3. **LLM 摘要** — 生成 9 段结构化摘要(核心需求、关键概念、文件与代码、错误与修复、问题解决、用户消息、待办任务、当前工作、建议下一步)。使用当前模型。
|
|
199
|
+
|
|
200
|
+
## 记忆系统
|
|
201
|
+
|
|
202
|
+
三层存储,优先级逐级递减:
|
|
203
|
+
|
|
204
|
+
1. `.coomi/memory/` — 项目本地(最高优先级)
|
|
205
|
+
2. `~/.coomi/projects/{hash}/memory/` — 项目全局
|
|
206
|
+
3. `~/.coomi/memory/` — 全局(所有项目共享)
|
|
207
|
+
|
|
208
|
+
记忆类型:`user`(用户偏好)、`feedback`(反馈纠正)、`project`(项目上下文)、`reference`(外部引用)。
|
|
209
|
+
|
|
210
|
+
MemoryExtractor 自动分析对话并保存相关记忆。MemoryRecall 执行语义选择,将相关记忆注入 System Prompt。
|
|
211
|
+
|
|
212
|
+
## 项目参考来源
|
|
213
|
+
|
|
214
|
+
本项目在工程复现和实现思路上参考了以下项目(或源码实现,或界面交互体验):
|
|
215
|
+
|
|
216
|
+
- Claude Code
|
|
217
|
+
- Codex
|
|
218
|
+
- OpenCode
|
|
219
|
+
|
|
220
|
+
参考重点主要是 Agent 主循环、工具调用编排、上下文管理和终端交互方式,不代表与原项目具有相同实现或功能范围。
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
MIT,详见 [LICENSE](LICENSE)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Coomi Agent CLI 入口"""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
"""主入口函数"""
|
|
11
|
+
# 检查是否首次运行(无配置文件)
|
|
12
|
+
config_dir = Path.home() / ".coomi" / "config"
|
|
13
|
+
config_path = config_dir / "providers.json"
|
|
14
|
+
|
|
15
|
+
if not config_path.exists():
|
|
16
|
+
# 首次运行:引导配置
|
|
17
|
+
from .first_run import run_first_time_setup
|
|
18
|
+
if not run_first_time_setup():
|
|
19
|
+
sys.exit(0)
|
|
20
|
+
|
|
21
|
+
# 启动 TUI
|
|
22
|
+
from .ui.textual_app import CoomiApp
|
|
23
|
+
app = CoomiApp()
|
|
24
|
+
app.run()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# 引擎层 - Agent大脑
|
|
2
|
+
from ..types import Message, ToolCall, LLMResponse, Session, TokenUsage, Spec, LoopSession, Checkpoint, LoopStatus, StepResult
|
|
3
|
+
from .session import SessionManager, add_user_message, add_assistant_message, add_tool_result, update_token_usage, build_system_prompt
|
|
4
|
+
from .loop import AgentLoop
|
|
5
|
+
from .spec_parser import parse_spec_file
|
|
6
|
+
from .checkpoint import create_loop_dir, save_state, save_checkpoint, append_issue, load_state
|
|
7
|
+
from .retry_policy import RetryPolicy, RetryAction
|
|
8
|
+
from .loop_runner import LoopRunner
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Message",
|
|
12
|
+
"ToolCall",
|
|
13
|
+
"LLMResponse",
|
|
14
|
+
"Session",
|
|
15
|
+
"TokenUsage",
|
|
16
|
+
"Spec",
|
|
17
|
+
"LoopSession",
|
|
18
|
+
"Checkpoint",
|
|
19
|
+
"LoopStatus",
|
|
20
|
+
"StepResult",
|
|
21
|
+
"SessionManager",
|
|
22
|
+
"add_user_message",
|
|
23
|
+
"add_assistant_message",
|
|
24
|
+
"add_tool_result",
|
|
25
|
+
"update_token_usage",
|
|
26
|
+
"build_system_prompt",
|
|
27
|
+
"AgentLoop",
|
|
28
|
+
"parse_spec_file",
|
|
29
|
+
"create_loop_dir",
|
|
30
|
+
"save_state",
|
|
31
|
+
"save_checkpoint",
|
|
32
|
+
"append_issue",
|
|
33
|
+
"load_state",
|
|
34
|
+
"RetryPolicy",
|
|
35
|
+
"RetryAction",
|
|
36
|
+
"LoopRunner",
|
|
37
|
+
]
|