deepseek-agent-2026 3.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.
Files changed (23) hide show
  1. deepseek_agent_2026-3.1.0/PKG-INFO +110 -0
  2. deepseek_agent_2026-3.1.0/README.md +80 -0
  3. deepseek_agent_2026-3.1.0/pyproject.toml +57 -0
  4. deepseek_agent_2026-3.1.0/setup.cfg +4 -0
  5. deepseek_agent_2026-3.1.0/src/deepseek_agent/__init__.py +9 -0
  6. deepseek_agent_2026-3.1.0/src/deepseek_agent/__main__.py +68 -0
  7. deepseek_agent_2026-3.1.0/src/deepseek_agent/agent.py +182 -0
  8. deepseek_agent_2026-3.1.0/src/deepseek_agent/cli.py +305 -0
  9. deepseek_agent_2026-3.1.0/src/deepseek_agent/colors.py +84 -0
  10. deepseek_agent_2026-3.1.0/src/deepseek_agent/config.py +102 -0
  11. deepseek_agent_2026-3.1.0/src/deepseek_agent/environment.py +47 -0
  12. deepseek_agent_2026-3.1.0/src/deepseek_agent/history.py +123 -0
  13. deepseek_agent_2026-3.1.0/src/deepseek_agent/mirrors.py +183 -0
  14. deepseek_agent_2026-3.1.0/src/deepseek_agent/prompts.py +55 -0
  15. deepseek_agent_2026-3.1.0/src/deepseek_agent/rules.py +79 -0
  16. deepseek_agent_2026-3.1.0/src/deepseek_agent/tools.py +397 -0
  17. deepseek_agent_2026-3.1.0/src/deepseek_agent/workspace.py +24 -0
  18. deepseek_agent_2026-3.1.0/src/deepseek_agent_2026.egg-info/PKG-INFO +110 -0
  19. deepseek_agent_2026-3.1.0/src/deepseek_agent_2026.egg-info/SOURCES.txt +21 -0
  20. deepseek_agent_2026-3.1.0/src/deepseek_agent_2026.egg-info/dependency_links.txt +1 -0
  21. deepseek_agent_2026-3.1.0/src/deepseek_agent_2026.egg-info/entry_points.txt +2 -0
  22. deepseek_agent_2026-3.1.0/src/deepseek_agent_2026.egg-info/requires.txt +5 -0
  23. deepseek_agent_2026-3.1.0/src/deepseek_agent_2026.egg-info/top_level.txt +1 -0
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.4
2
+ Name: deepseek-agent-2026
3
+ Version: 3.1.0
4
+ Summary: DeepSeek AI Agent - 智能终端助手,支持 JSON 模式工具调用、文件精确编辑、后台任务处理、对话历史
5
+ Author: 我是个人
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/user/deepseek-agent
8
+ Project-URL: Repository, https://github.com/user/deepseek-agent.git
9
+ Project-URL: Issues, https://github.com/user/deepseek-agent/issues
10
+ Keywords: deepseek,ai,agent,termux,terminal,assistant,cli
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: Android
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Terminals
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ Requires-Dist: openai==0.28.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7; extra == "dev"
29
+ Requires-Dist: pytest-cov; extra == "dev"
30
+
31
+ # DeepSeek AI Agent v3.1
32
+
33
+ 智能终端助手 —— 专为 Termux 环境设计的 AI Agent,基于 DeepSeek API。
34
+
35
+ ## 功能特性
36
+
37
+ - JSON 模式工具调用 —— 自动执行 shell 命令、读写文件、访问网页
38
+ - 文件精确编辑 —— replace_in_file 只替换需要改的部分
39
+ - 后台任务处理 —— 自动识别服务启动命令并加 `&` 后台运行
40
+ - 对话历史 —— 实时保存,下次启动可继续对话
41
+ - 用户自定义规则 —— 嵌入系统提示词,个性化 AI 行为
42
+ - 国内镜像源 —— 支持阿里云/清华源/中科大/自定义四种模式
43
+ - Termux 环境检测 —— 启动时自动验证运行环境
44
+
45
+ ## 安装
46
+
47
+ ### 从 PyPI 安装(推荐)
48
+
49
+ ```bash
50
+ pip install deepseek-agent
51
+ ```
52
+
53
+ ### 从源码安装
54
+
55
+ ```bash
56
+ git clone https://github.com/user/deepseek-agent.git
57
+ cd deepseek-agent
58
+ pip install -e .
59
+ ```
60
+
61
+ ## 快速开始
62
+
63
+ 安装后直接运行:
64
+
65
+ ```bash
66
+ deepseek-agent
67
+ ```
68
+
69
+ 或者作为 Python 模块运行:
70
+
71
+ ```bash
72
+ python -m deepseek_agent
73
+ ```
74
+
75
+ 首次运行需要:
76
+ 1. 同意用户协议与隐私政策
77
+ 2. 输入 DeepSeek API Key(可从 https://platform.deepseek.com 获取)
78
+
79
+ ## 可用工具
80
+
81
+ | 工具 | 功能 |
82
+ |------|------|
83
+ | run_shell | 执行系统命令 |
84
+ | read_file | 读取文件(带行号) |
85
+ | write_file | 安全写入文件 |
86
+ | replace_in_file | 精确替换文件内容 |
87
+ | mkdir | 创建目录 |
88
+ | fetch_webpage | 访问网页(Lynx) |
89
+ | ask_user | 向用户提问 |
90
+
91
+ ## 特殊命令
92
+
93
+ | 命令 | 功能 |
94
+ |------|------|
95
+ | help / 帮助 | 显示帮助信息 |
96
+ | setting / 设置 | 打开设置菜单 |
97
+ | clear | 清屏 |
98
+ | reset | 重置对话并删除历史 |
99
+ | exit / 退出 | 保存并退出 |
100
+
101
+ ## 系统要求
102
+
103
+ - Android 设备
104
+ - Termux 应用([GitHub](https://github.com/termux/termux-app) 或 [F-Droid](https://f-droid.org/packages/com.termux/))
105
+ - Python 3.8+
106
+ - DeepSeek API Key
107
+
108
+ ## 许可证
109
+
110
+ MIT License
@@ -0,0 +1,80 @@
1
+ # DeepSeek AI Agent v3.1
2
+
3
+ 智能终端助手 —— 专为 Termux 环境设计的 AI Agent,基于 DeepSeek API。
4
+
5
+ ## 功能特性
6
+
7
+ - JSON 模式工具调用 —— 自动执行 shell 命令、读写文件、访问网页
8
+ - 文件精确编辑 —— replace_in_file 只替换需要改的部分
9
+ - 后台任务处理 —— 自动识别服务启动命令并加 `&` 后台运行
10
+ - 对话历史 —— 实时保存,下次启动可继续对话
11
+ - 用户自定义规则 —— 嵌入系统提示词,个性化 AI 行为
12
+ - 国内镜像源 —— 支持阿里云/清华源/中科大/自定义四种模式
13
+ - Termux 环境检测 —— 启动时自动验证运行环境
14
+
15
+ ## 安装
16
+
17
+ ### 从 PyPI 安装(推荐)
18
+
19
+ ```bash
20
+ pip install deepseek-agent
21
+ ```
22
+
23
+ ### 从源码安装
24
+
25
+ ```bash
26
+ git clone https://github.com/user/deepseek-agent.git
27
+ cd deepseek-agent
28
+ pip install -e .
29
+ ```
30
+
31
+ ## 快速开始
32
+
33
+ 安装后直接运行:
34
+
35
+ ```bash
36
+ deepseek-agent
37
+ ```
38
+
39
+ 或者作为 Python 模块运行:
40
+
41
+ ```bash
42
+ python -m deepseek_agent
43
+ ```
44
+
45
+ 首次运行需要:
46
+ 1. 同意用户协议与隐私政策
47
+ 2. 输入 DeepSeek API Key(可从 https://platform.deepseek.com 获取)
48
+
49
+ ## 可用工具
50
+
51
+ | 工具 | 功能 |
52
+ |------|------|
53
+ | run_shell | 执行系统命令 |
54
+ | read_file | 读取文件(带行号) |
55
+ | write_file | 安全写入文件 |
56
+ | replace_in_file | 精确替换文件内容 |
57
+ | mkdir | 创建目录 |
58
+ | fetch_webpage | 访问网页(Lynx) |
59
+ | ask_user | 向用户提问 |
60
+
61
+ ## 特殊命令
62
+
63
+ | 命令 | 功能 |
64
+ |------|------|
65
+ | help / 帮助 | 显示帮助信息 |
66
+ | setting / 设置 | 打开设置菜单 |
67
+ | clear | 清屏 |
68
+ | reset | 重置对话并删除历史 |
69
+ | exit / 退出 | 保存并退出 |
70
+
71
+ ## 系统要求
72
+
73
+ - Android 设备
74
+ - Termux 应用([GitHub](https://github.com/termux/termux-app) 或 [F-Droid](https://f-droid.org/packages/com.termux/))
75
+ - Python 3.8+
76
+ - DeepSeek API Key
77
+
78
+ ## 许可证
79
+
80
+ MIT License
@@ -0,0 +1,57 @@
1
+ [build-system]
2
+ requires = ["setuptools>=64", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "deepseek-agent-2026"
7
+ version = "3.1.0"
8
+ description = "DeepSeek AI Agent - 智能终端助手,支持 JSON 模式工具调用、文件精确编辑、后台任务处理、对话历史"
9
+ authors = [
10
+ {name = "我是个人"}
11
+ ]
12
+ license = {text = "MIT"}
13
+ readme = "README.md"
14
+ requires-python = ">=3.8"
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: Android",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.8",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Topic :: Terminals",
28
+ "Topic :: Software Development :: Libraries :: Python Modules",
29
+ ]
30
+ keywords = ["deepseek", "ai", "agent", "termux", "terminal", "assistant", "cli"]
31
+ dependencies = [
32
+ "openai==0.28.0",
33
+ ]
34
+
35
+ [project.optional-dependencies]
36
+ dev = [
37
+ "pytest>=7",
38
+ "pytest-cov",
39
+ ]
40
+
41
+ [project.urls]
42
+ Homepage = "https://github.com/user/deepseek-agent"
43
+ Repository = "https://github.com/user/deepseek-agent.git"
44
+ Issues = "https://github.com/user/deepseek-agent/issues"
45
+
46
+ [project.scripts]
47
+ deepseek-agent-2026 = "deepseek_agent.__main__:main"
48
+
49
+ [tool.setuptools]
50
+ package-dir = {"" = "src"}
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["src"]
54
+
55
+ [tool.pytest.ini_options]
56
+ testpaths = ["tests"]
57
+ python_files = ["test_*.py"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,9 @@
1
+ """
2
+ DeepSeek AI Agent - 智能终端助手 v3.1
3
+
4
+ Termux AI Agent with JSON-mode tool calling, file editing,
5
+ background task handling, conversation history, and user rules.
6
+ """
7
+
8
+ __version__ = "3.1.0"
9
+ __author__ = "我是个人"
@@ -0,0 +1,68 @@
1
+ """入口点 —— 可通过 python -m deepseek_agent 启动"""
2
+
3
+ import sys
4
+
5
+ from .environment import ensure_termux
6
+ from .colors import print_banner, print_status, Colors
7
+ from .config import load_config, load_api_key, save_api_key
8
+ from .mirrors import apply_mirror_source, install_pkg_with_retry, install_pip_package, check_command
9
+ from .workspace import create_work_dir
10
+ from .cli import check_agreement, first_run_agreement
11
+
12
+
13
+ def main():
14
+ """主入口函数"""
15
+ # 先加载配置(必须在 apply_mirror_source 之前)
16
+ load_config()
17
+
18
+ # 首次运行:显示协议并要求用户同意
19
+ if not check_agreement():
20
+ if not first_run_agreement():
21
+ sys.exit(0)
22
+
23
+ print_banner()
24
+
25
+ # 应用镜像源(在 load_config 之后,使用用户保存的选择)
26
+ print_status("正在初始化环境,切换至国内镜像源...", "info")
27
+ apply_mirror_source()
28
+
29
+ # 安装必要的依赖
30
+ if not check_command("lynx"):
31
+ install_pkg_with_retry("lynx")
32
+
33
+ try:
34
+ import openai
35
+ except ImportError:
36
+ if not install_pip_package("openai==0.28.0"):
37
+ print_status("openai 安装失败,请检查网络后重试", "error")
38
+ sys.exit(1)
39
+ try:
40
+ import openai
41
+ except ImportError:
42
+ print_status("openai 导入失败,请重启脚本", "error")
43
+ sys.exit(1)
44
+
45
+ # 创建工作目录
46
+ work_dir = create_work_dir()
47
+ print_status(f"工作目录: {work_dir}", "success")
48
+
49
+ saved_key = load_api_key()
50
+
51
+ if saved_key:
52
+ print(f" {Colors.DIM}🔑 已加载 API Key{Colors.RESET}")
53
+ api_key = saved_key
54
+ else:
55
+ print(f"\n{Colors.BRIGHT_YELLOW} 🔑 请输入 DeepSeek API Key{Colors.RESET}")
56
+ api_key = input(f"\n{Colors.BOLD}{Colors.BRIGHT_WHITE} Key{Colors.RESET} {Colors.BRIGHT_BLUE}»{Colors.RESET} ").strip()
57
+ if not api_key:
58
+ sys.exit(1)
59
+ save = input(f"\n{Colors.DIM}保存 Key?(Y/n): {Colors.RESET}").strip().lower()
60
+ if save in ["", "y", "yes"]:
61
+ save_api_key(api_key)
62
+
63
+ from .agent import start
64
+ start(api_key, work_dir, openai)
65
+
66
+
67
+ if __name__ == "__main__":
68
+ main()
@@ -0,0 +1,182 @@
1
+ """AI Agent 主循环 —— 与 DeepSeek API 交互的核心逻辑"""
2
+
3
+ import os
4
+ import json
5
+ import sys
6
+
7
+ from . import config
8
+ from .colors import print_status, Colors
9
+ from .prompts import build_system_prompt
10
+ from .tools import FUNC_MAP, ICON_MAP, TOOLS, ask_user
11
+ from .history import save_history, save_conversation_history, load_history, clear_history, get_history_summary
12
+
13
+
14
+ def start(api_key, work_dir, openai_module):
15
+ """启动 AI Agent 主循环"""
16
+ openai_module.api_key = api_key
17
+ openai_module.api_base = config.BASE_URL
18
+
19
+ messages = None
20
+
21
+ # 尝试加载历史记录
22
+ saved_messages = load_history()
23
+ if saved_messages:
24
+ summary = get_history_summary(saved_messages)
25
+ if summary:
26
+ print(f"\n {Colors.BRIGHT_YELLOW}📜 发现上次对话记录({summary['total']}条消息,{summary['user_count']}轮对话){Colors.RESET}")
27
+ print(f" {Colors.DIM}首条: {summary['first']}{Colors.RESET}")
28
+ print(f" {Colors.DIM}末条: {summary['last']}{Colors.RESET}")
29
+ choice = input(f"\n {Colors.BRIGHT_WHITE}是否继续上次对话?{Colors.RESET}\n {Colors.DIM}(输入 y 继续 / 直接回车开启新对话并删除记录): {Colors.RESET}").strip().lower()
30
+ if choice in ["y", "yes"]:
31
+ messages = saved_messages
32
+ print_status(f"已加载上次对话记录,继续对话", "success")
33
+ else:
34
+ clear_history()
35
+ print_status("已开启新对话,旧记录已删除", "info")
36
+
37
+ if messages is None:
38
+ messages = [{"role": "system", "content": build_system_prompt(work_dir)}]
39
+
40
+ from .rules import get_user_rules_status
41
+ from .workspace import HISTORY_DIR
42
+
43
+ user_rules_status = get_user_rules_status()
44
+ print(f"""
45
+ {Colors.BRIGHT_GREEN} ✨ 就绪 - 输入需求开始对话{Colors.RESET}
46
+ {Colors.DIM}配置: 超时{config.CMD_TIMEOUT}s | 轮次{config.MAX_TASK_ROUNDS} | 输出{config.MAX_TOKENS} tokens | {config.MODEL}{Colors.RESET}
47
+ {Colors.DIM}工作目录: {work_dir}{Colors.RESET}
48
+ {Colors.DIM}历史记录: {HISTORY_DIR}{Colors.RESET}
49
+ {Colors.DIM}特殊命令:help | setting | 退出 | clear | reset{Colors.RESET}
50
+ {Colors.DIM}提示:Ctrl+C 可安全中断当前执行的命令{Colors.RESET}
51
+ {Colors.DIM}用户规则:{user_rules_status}{Colors.RESET}
52
+ """)
53
+
54
+ while True:
55
+ try:
56
+ user_input = input(f"\n{Colors.BOLD}{Colors.BRIGHT_WHITE}你{Colors.RESET} {Colors.BRIGHT_BLUE}»{Colors.RESET} ").strip()
57
+ except (EOFError, KeyboardInterrupt):
58
+ save_history(messages)
59
+ save_conversation_history(messages, work_dir)
60
+ print(f"\n\n{Colors.BRIGHT_YELLOW} 👋 再见!对话已保存,下次启动可继续{Colors.RESET}\n")
61
+ break
62
+
63
+ if user_input.lower() in ["exit", "退出"]:
64
+ save_history(messages)
65
+ save_conversation_history(messages, work_dir)
66
+ print(f"\n{Colors.BRIGHT_YELLOW} 👋 再见!对话已保存,下次启动可继续{Colors.RESET}\n")
67
+ break
68
+ elif user_input.lower() in ["setting", "设置"]:
69
+ # 延迟导入避免循环依赖
70
+ from .cli import settings_menu
71
+ settings_menu()
72
+ messages = [{"role": "system", "content": build_system_prompt(work_dir)}]
73
+ continue
74
+ elif user_input.lower() == "clear":
75
+ os.system("clear")
76
+ from .colors import print_banner
77
+ print_banner()
78
+ continue
79
+ elif user_input.lower() == "reset":
80
+ clear_history()
81
+ messages = [{"role": "system", "content": build_system_prompt(work_dir)}]
82
+ print_status("对话已完全重置,历史记录已删除", "success")
83
+ continue
84
+ elif user_input.lower() in ["help", "帮助"]:
85
+ from .colors import print_help
86
+ print_help()
87
+ continue
88
+ elif not user_input:
89
+ continue
90
+
91
+ messages.append({"role": "user", "content": user_input})
92
+
93
+ for round_num in range(config.MAX_TASK_ROUNDS):
94
+ try:
95
+ resp = openai_module.ChatCompletion.create(
96
+ model=config.MODEL,
97
+ messages=messages,
98
+ max_tokens=config.MAX_TOKENS,
99
+ temperature=0.1,
100
+ tools=TOOLS,
101
+ tool_choice="auto"
102
+ )
103
+ assistant_msg = resp["choices"][0]["message"]
104
+ except Exception as e:
105
+ print_status(f"API 错误: {str(e)[:100]}", "error")
106
+ break
107
+
108
+ tool_calls_data = assistant_msg.get("tool_calls")
109
+
110
+ if tool_calls_data:
111
+ messages.append(assistant_msg)
112
+
113
+ for tc in tool_calls_data:
114
+ if tc["type"] != "function":
115
+ continue
116
+
117
+ fname = tc["function"]["name"]
118
+ try:
119
+ args = json.loads(tc["function"]["arguments"])
120
+ except json.JSONDecodeError:
121
+ print_status(f"参数解析失败", "error")
122
+ continue
123
+
124
+ if fname not in FUNC_MAP:
125
+ print_status(f"未知工具: {fname}", "error")
126
+ continue
127
+
128
+ icon = ICON_MAP.get(fname, "exec")
129
+ if fname in ("run_shell", "mkdir"):
130
+ display = str(args.get('cmd', args.get('path', '')))[:80].replace('\n', '\\n')
131
+ elif fname == "ask_user":
132
+ display = str(args.get('question', ''))[:80]
133
+ elif fname == "replace_in_file":
134
+ display = f"path={args.get('path', '')}"
135
+ else:
136
+ display = str(args)[:80]
137
+ print_status(f"{fname}: {display}...", icon)
138
+
139
+ if fname == "ask_user":
140
+ result = ask_user(args.get("question", ""))
141
+ else:
142
+ try:
143
+ result = FUNC_MAP[fname](**args)
144
+ except Exception as e:
145
+ result = f"执行失败: {e}"
146
+
147
+ if fname == "read_file":
148
+ try:
149
+ data = json.loads(result)
150
+ print_status(f"读取: {data.get('path', '')} ({data.get('size', 0)}字节, {data.get('line_count', 0)}行)", "success")
151
+ except Exception:
152
+ print_status(f"{result[:50]}", "warning" if "不存在" in result else "success")
153
+ elif fname == "write_file":
154
+ msg = "写入成功" if "✅" in result else "写入失败"
155
+ print_status(f"{msg}: {args.get('path', '')}", "success" if "✅" in result else "error")
156
+ elif fname == "replace_in_file":
157
+ msg = "替换成功" if "✅" in result else "替换失败"
158
+ print_status(f"{msg}: {args.get('path', '')}", "success" if "✅" in result else "error")
159
+ elif fname == "ask_user":
160
+ print_status(result, "info")
161
+
162
+ messages.append({
163
+ "role": "tool",
164
+ "tool_call_id": tc["id"],
165
+ "name": fname,
166
+ "content": result
167
+ })
168
+
169
+ save_history(messages)
170
+ save_conversation_history(messages, work_dir)
171
+ continue
172
+
173
+ content = assistant_msg.get("content", "").strip()
174
+ if content:
175
+ print(f"\n{Colors.BRIGHT_GREEN}助手{Colors.RESET} {Colors.BRIGHT_BLUE}»{Colors.RESET} {content}\n")
176
+ messages.append({"role": "assistant", "content": content})
177
+ save_history(messages)
178
+ save_conversation_history(messages, work_dir)
179
+ break
180
+
181
+ if round_num >= config.MAX_TASK_ROUNDS - 1:
182
+ print_status("达到最大轮次", "warning")