tina-python 0.7.0__tar.gz → 0.7.2__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 (62) hide show
  1. {tina_python-0.7.0/tina_python.egg-info → tina_python-0.7.2}/PKG-INFO +116 -67
  2. {tina_python-0.7.0 → tina_python-0.7.2}/README.md +113 -64
  3. {tina_python-0.7.0 → tina_python-0.7.2}/pyproject.toml +5 -3
  4. {tina_python-0.7.0 → tina_python-0.7.2}/setup.py +1 -1
  5. {tina_python-0.7.0 → tina_python-0.7.2}/tina/__init__.py +1 -1
  6. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/agent.py +29 -3
  7. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/tools.py +5 -2
  8. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/multimodal_agent.py +3 -1
  9. {tina_python-0.7.0 → tina_python-0.7.2}/tina/llm/__init__.py +1 -2
  10. {tina_python-0.7.0 → tina_python-0.7.2}/tina/llm/base_api.py +28 -0
  11. {tina_python-0.7.0 → tina_python-0.7.2}/tina/llm/files_api.py +14 -7
  12. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/__init__.py +4 -0
  13. tina_python-0.7.2/tina/utils/coding_context.py +253 -0
  14. tina_python-0.7.2/tina/utils/coding_tools.py +689 -0
  15. tina_python-0.7.2/tina/utils/session_store.py +331 -0
  16. {tina_python-0.7.0 → tina_python-0.7.2/tina_python.egg-info}/PKG-INFO +116 -67
  17. {tina_python-0.7.0 → tina_python-0.7.2}/tina_python.egg-info/SOURCES.txt +3 -1
  18. {tina_python-0.7.0 → tina_python-0.7.2}/tina_python.egg-info/requires.txt +2 -2
  19. tina_python-0.7.0/tina/utils/system_tools.py +0 -547
  20. {tina_python-0.7.0 → tina_python-0.7.2}/LICENSE +0 -0
  21. {tina_python-0.7.0 → tina_python-0.7.2}/MANIFEST.in +0 -0
  22. {tina_python-0.7.0 → tina_python-0.7.2}/setup.cfg +0 -0
  23. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/__init__.py +0 -0
  24. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/__init__.py +0 -0
  25. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/agent_response.py +0 -0
  26. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/agent_runtime.py +0 -0
  27. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/context_manager.py +0 -0
  28. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/events.py +0 -0
  29. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/executor.py +0 -0
  30. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/keyword_actions.py +0 -0
  31. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/prompt.py +0 -0
  32. {tina_python-0.7.0 → tina_python-0.7.2}/tina/agent/core/state.py +0 -0
  33. {tina_python-0.7.0 → tina_python-0.7.2}/tina/core/__init__.py +0 -0
  34. {tina_python-0.7.0 → tina_python-0.7.2}/tina/core/error.py +0 -0
  35. {tina_python-0.7.0 → tina_python-0.7.2}/tina/core/logger.py +0 -0
  36. {tina_python-0.7.0 → tina_python-0.7.2}/tina/llm/base_multimodal_api.py +0 -0
  37. {tina_python-0.7.0 → tina_python-0.7.2}/tina/mcp/__init__.py +0 -0
  38. {tina_python-0.7.0 → tina_python-0.7.2}/tina/mcp/client.py +0 -0
  39. {tina_python-0.7.0 → tina_python-0.7.2}/tina/mcp/mcp_tools_executor.py +0 -0
  40. {tina_python-0.7.0 → tina_python-0.7.2}/tina/py.typed +0 -0
  41. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/agent_worker.py +0 -0
  42. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/deepseek.py +0 -0
  43. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/doc_parser.py +0 -0
  44. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/env_reader.py +0 -0
  45. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/multi_agent/__init__.py +0 -0
  46. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/multi_agent/environment.py +0 -0
  47. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/multi_agent/message.py +0 -0
  48. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/multi_agent/message_bus.py +0 -0
  49. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/multi_agent/web/__init__.py +0 -0
  50. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/multi_agent/web/server.py +0 -0
  51. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/multimodal_formatter.py +0 -0
  52. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/output_parser.py +0 -0
  53. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/run_agent_in_cli.py +0 -0
  54. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/tui/__init__.py +0 -0
  55. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/tui/context_manager.py +0 -0
  56. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/tui/token.py +0 -0
  57. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/tui/tui.py +0 -0
  58. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/type_mapper.py +0 -0
  59. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/url.py +0 -0
  60. {tina_python-0.7.0 → tina_python-0.7.2}/tina/utils/usage.py +0 -0
  61. {tina_python-0.7.0 → tina_python-0.7.2}/tina_python.egg-info/dependency_links.txt +0 -0
  62. {tina_python-0.7.0 → tina_python-0.7.2}/tina_python.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tina-python
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: tina is in your computer!
5
5
  Home-page: https://gitee.com/wang-churi/tina
6
6
  Author: 王出日
@@ -18,7 +18,7 @@ License-File: LICENSE
18
18
  Requires-Dist: httpx
19
19
  Requires-Dist: python-dotenv
20
20
  Provides-Extra: tui
21
- Requires-Dist: tina-tui>=0.1.0; extra == "tui"
21
+ Requires-Dist: tina-tui>=0.2.0; extra == "tui"
22
22
  Provides-Extra: multi-agent
23
23
  Requires-Dist: tina-multi-agent>=0.1.0; extra == "multi-agent"
24
24
  Provides-Extra: mcp
@@ -28,7 +28,7 @@ Requires-Dist: pytest>=9.0; extra == "test"
28
28
  Requires-Dist: pytest-asyncio>=1.4; extra == "test"
29
29
  Requires-Dist: pytest-cov>=7.0; extra == "test"
30
30
  Provides-Extra: all
31
- Requires-Dist: tina-tui>=0.1.0; extra == "all"
31
+ Requires-Dist: tina-tui>=0.2.0; extra == "all"
32
32
  Requires-Dist: tina-multi-agent>=0.1.0; extra == "all"
33
33
  Requires-Dist: mcp>=2.0; extra == "all"
34
34
  Dynamic: author
@@ -53,10 +53,13 @@ pip install tina-python
53
53
  # 如果需要使用 MCP(模型上下文协议)服务
54
54
  pip install tina-python[mcp]
55
55
 
56
- # 如果需要 TUI 终端界面
56
+ # 如果需要 TUI 终端界面(独立发行包 tina-tui)
57
57
  pip install tina-python[tui]
58
58
 
59
- # 一次装齐所有可选功能(TUI + MCP)
59
+ # 如果需要多 Agent 环境 + Web 调试控制台(独立发行包 tina-multi-agent)
60
+ pip install tina-python[multi-agent]
61
+
62
+ # 一次装齐所有可选功能(TUI + 多 Agent + MCP)
60
63
  pip install tina-python[all]
61
64
 
62
65
  # 如果需要运行测试
@@ -72,7 +75,7 @@ from tina.llm import BaseAPI
72
75
  # 1. 实例化大模型(支持通过 tina.env 文件配置)
73
76
  llm = BaseAPI(
74
77
  api_key="your-api-key",
75
- base_url="https://api.openai.com/v1/chat/completions",
78
+ base_url="https://api.openai.com/v1",
76
79
  model="gpt-4o"
77
80
  )
78
81
 
@@ -113,7 +116,7 @@ for chunk in result:
113
116
  - [四、MCP 支持 —— 模型上下文协议](#四mcp-支持--模型上下文协议)
114
117
  - [五、多模态支持](#五多模态支持)
115
118
  - [六、快速开发工具](#六快速开发工具)
116
- - [6.5 终端界面 TUI(可选扩展)](#65-终端界面-tui可选扩展)
119
+ - [七、拓展包(可选)](#七拓展包可选)
117
120
 
118
121
  ---
119
122
 
@@ -141,7 +144,8 @@ tina 是一个轻量、模块化的 AI 智能体框架,专注于让开发者
141
144
  | **MCPClient** | MCP 集成 | 连接 MCP 服务器生态(stdio/SSE) |
142
145
  | **ContextManager** | 上下文管理 | 滚动窗口策略,自动截断 |
143
146
  | **AgentEvents** | 事件系统 | 贯穿 Agent 生命周期的回调钩子 |
144
- | **TUI(可选)** | 终端界面 | 测试你写的 Agent 的交互控制台,也可当作自己的 TUI 使用 |
147
+ | **TUI(可选)** | 终端界面 | 独立包 `tina-tui`:测试 Agent 的交互控制台,也可当作自己的 TUI 使用 |
148
+ | **多 Agent(可选)** | 多 Agent 环境 | 独立包 `tina-multi-agent`:消息总线 + Web 调试控制台 |
145
149
 
146
150
  ---
147
151
 
@@ -160,7 +164,7 @@ llm = BaseAPI()
160
164
  # 或者:手动传入参数
161
165
  llm = BaseAPI(
162
166
  api_key="your-api-key",
163
- base_url="https://api.openai.com/v1/chat/completions",
167
+ base_url="https://api.openai.com/v1",
164
168
  model="gpt-4o"
165
169
  )
166
170
  ```
@@ -168,11 +172,11 @@ llm = BaseAPI(
168
172
  `tina.env` 文件示例:
169
173
  ```env
170
174
  LLM_API_KEY="your-api-key"
171
- BASE_URL="https://api.openai.com/v1/chat/completions"
175
+ BASE_URL="https://api.openai.com/v1"
172
176
  MODEL_NAME="gpt-4o"
173
177
  ```
174
178
 
175
- > **注意**:`base_url` 需要包含完整的 `/chat/completions` 路由,tina 不会自动补充。
179
+ > **base_url 规则(0.7.0 起)**:只写服务根地址即可(如 `https://api.openai.com/v1`),tina 会自动补上 `/chat/completions`;写完整地址(`.../chat/completions`)也依然兼容。旧文档要求"必须自带 `/chat/completions`"的说法已作废。
176
180
 
177
181
  ### 1.2 非流式调用
178
182
 
@@ -707,7 +711,7 @@ tina 支持通过 MCP(Model Context Protocol)连接外部工具生态。
707
711
  pip install tina-python[mcp]
708
712
  ```
709
713
 
710
- > 想一次装齐所有可选功能(TUI + MCP):`pip install tina-python[all]`
714
+ > 想一次装齐所有可选功能(TUI + 多 Agent + MCP):`pip install tina-python[all]`
711
715
 
712
716
  ### 4.2 使用 MCP 客户端
713
717
 
@@ -898,55 +902,7 @@ message = build_multimodal_message(
898
902
 
899
903
  tina 提供了一些开箱即用的工具函数和工具包,帮助你快速搭建应用。
900
904
 
901
- ### 6.1 系统工具包 `system_tools`
902
-
903
- tina 自带一套系统工具包,包含文件操作、代码执行等常用功能:
904
-
905
- ```python
906
- from tina import Agent, Tools
907
- from tina.llm import BaseAPI
908
- from tina.utils.system_tools import system_tools
909
-
910
- tools = Tools(name="my_tools")
911
- tools += system_tools # 添加 tina 自带的系统工具包(工具集需命名)
912
-
913
- agent = Agent(
914
- llm=BaseAPI(),
915
- tools=tools,
916
- system_prompt="你是一个系统助手,可以帮助我管理文件和执行代码"
917
- )
918
-
919
- result = agent.predict(instruction="帮我看看当前目录下有哪些文件", stream=True)
920
- for chunk in result:
921
- print(chunk.content, end="")
922
- ```
923
-
924
- **内置工具一览:**
925
-
926
- | 工具名称 | 需要确认 | 功能说明 |
927
- |---------|---------|---------|
928
- | `get_time` | ❌ | 获取当前系统时间 |
929
- | `list_dir` | ❌ | 列出目录下的文件和子目录 |
930
- | `project_tree` | ❌ | 获取项目目录结构(类似 tree 命令) |
931
- | `get_path` | ❌ | 获取文件/文件夹的绝对路径 |
932
- | `read_code` | ❌ | 按字符范围读取文件内容片段 |
933
- | `read_code_by_line` | ❌ | 按行读取代码片段(带行号) |
934
- | `search_in_files` | ❌ | 在项目中按正则搜索文本(自动忽略 `.git`/`.venv` 等) |
935
- | `delay` | ❌ | 延时函数 |
936
- | `make_dir` | ✅ | 创建目录(自动创建父目录) |
937
- | `write_code` | ✅ | 写入文件内容(覆盖,自动创建父目录) |
938
- | `append_code` | ✅ | 追加写入文件内容(自动创建父目录) |
939
- | `delete_path` | ✅ | 删除文件或目录(`recursive=True` 可递归) |
940
- | `replace_code_by_lines` | ✅ | 按行范围替换代码块 |
941
- | `terminal` | ✅ | 在终端运行指令(带超时) |
942
- | `run_python` | ✅ | 执行一小段 Python 代码 |
943
- | `shot_down_system` | ✅ | 关机 |
944
-
945
- > `需要确认` 的工具在执行时会触发 `on_tool_confirmation` 事件,适合接入人工审批流程。
946
- >
947
- > 由于系统工具包使用了命名空间,工具在模型侧的实际名称为 `tina_sys_tools_{名称}`,例如 `tina_sys_tools_read_code`。
948
-
949
- ### 6.2 后台工作器 `AgentWorker`
905
+ ### 6.1 后台工作器 `AgentWorker`
950
906
 
951
907
  `AgentWorker` 将 Agent 包装为异步后台服务,通过消息队列接收外部指令并持续处理:
952
908
 
@@ -986,7 +942,7 @@ asyncio.run(main())
986
942
 
987
943
  `AgentWorker` 还会将自身的 `put` 方法自动注册为 Agent 的工具,方便多 Agent 场景下互相调用。
988
944
 
989
- ### 6.3 终端交互控制台 `run_agent_in_cli`
945
+ ### 6.2 终端交互控制台 `run_agent_in_cli`
990
946
 
991
947
  快速启动一个 Agent 交互式终端,适合调试和测试:
992
948
 
@@ -1012,7 +968,7 @@ run_agent_in_cli(agent)
1012
968
  | `#clear` | 清屏 |
1013
969
  | `exit` / `quit` | 退出对话(`#exit` 不支持,会被当作普通输入) |
1014
970
 
1015
- ### 6.4 多模态消息构建器 `build_multimodal_message`
971
+ ### 6.3 多模态消息构建器 `build_multimodal_message`
1016
972
 
1017
973
  用于灵活构建包含多模态内容的消息:
1018
974
 
@@ -1031,7 +987,13 @@ print(message)
1031
987
  # {"role": "user", "content": [{"type": "text", "text": "..."}, {"type": "image_url", ...}]}
1032
988
  ```
1033
989
 
1034
- ### 6.5 终端界面 TUI(可选扩展)
990
+ ---
991
+
992
+ ## 七、拓展包(可选)
993
+
994
+ 除核心之外的可选能力:有**随主包提供**的(编码工具),也有拆成**独立发行包**的(终端界面、多 Agent 环境),按需安装、可独立更新与发布。主包内不再包含后者的实现(仅保留 `tina.utils.*` 兼容转发壳)。
995
+
996
+ ### 7.1 终端界面 TUI(`tina-tui`)
1035
997
 
1036
998
  终端界面由配套包 **`tina-tui`**(基于 [Textual](https://textual.textualize.io/))提供,作为**可选扩展**单独发行:方便你测试自己写的 Agent,也可以直接当作自己的 TUI 来用。核心不依赖它,需要额外安装:
1037
999
 
@@ -1039,6 +1001,21 @@ print(message)
1039
1001
  pip install tina-python[tui] # 等价于安装 tina-tui
1040
1002
  ```
1041
1003
 
1004
+ **开箱即用的 `tinacode` 命令**:装好后可以在任意目录直接起一个编码 agent,不用写 Python:
1005
+
1006
+ ```bash
1007
+ cd <你的项目>
1008
+ tinacode
1009
+ ```
1010
+
1011
+ - 工作目录 = 你敲命令时所在的目录(`code_*` 工具的相对路径以它为准)
1012
+ - 会话历史存到 `<cwd>/.tina/chat_sessions/`,**按目录隔离**
1013
+ - 模型配置读 `<cwd>/tina.env` 或 `.env`,没有则回退全局 `~/.tina/tina.env`
1014
+ - 目录里的 `.tinacode.md` / `AGENTS.md` / `.tina.md` 自动注入系统提示(目录级定制不用改代码)
1015
+ - 工具集是 `CodingTools`(见 [7.3](#73-编码工具codingtools))
1016
+
1017
+ 自己组装 Agent 再交给 TUI:
1018
+
1042
1019
  ```python
1043
1020
  from tina import Agent, Tools
1044
1021
  from tina.llm import BaseAPI
@@ -1059,8 +1036,9 @@ run_agent_in_tui(agent, max_tokens=32000)
1059
1036
  - 自动为 Agent 注册工具确认事件(`require_confirmation=True` 的工具会弹出选择条)
1060
1037
  - 上下文 token 占用与上限进度(显示百分比,≥80% 变黄、超限变红警告),运行时显示动画
1061
1038
  - `Esc` 可打断本轮回复;已生成的部分正文写回上下文,进行中的工具调用记为「该次调用被打断」
1062
- - 输入框支持多行与粘贴;`Enter` 发送、`Shift+Enter` 换行、`Tab` 补全命令
1039
+ - 输入框支持多行与粘贴;`Enter` 发送、`Shift+Enter` 换行、`Tab` 补全命令与会话 id
1063
1040
  - 底部粘性滚动:在底部时自动跟随输出,向上滚动查看历史时不会被打扰,滚回底部自动恢复
1041
+ - 会话自动归档到 `<项目>/.tina/chat_sessions/`:可切换 / 重命名 / 删除,首轮结束后自动起名
1064
1042
  - 可选 `unlimited_context=True`:用 tina 提供的无限制上下文管理器替换 Agent 的(不裁剪历史、不截断工具结果)
1065
1043
 
1066
1044
  | 指令 | 功能 |
@@ -1070,6 +1048,11 @@ run_agent_in_tui(agent, max_tokens=32000)
1070
1048
  | `#context` | 查看当前上下文 |
1071
1049
  | `#model` | 查看当前模型信息 |
1072
1050
  | `#tokens` | 查看当前上下文 token 占用 |
1051
+ | `#sessions` | 列出已保存的会话(可跟关键字过滤) |
1052
+ | `#switch` | 切换会话(按 id / id 前缀 / 标题) |
1053
+ | `#new` | 新建会话(当前会话自动保存) |
1054
+ | `#rename` | 重命名当前会话 |
1055
+ | `#delete` | 删除会话 |
1073
1056
  | `#compact` | 压缩上下文(让 Agent 自我总结并并入 system) |
1074
1057
  | `#clear` | 清空上下文与界面 |
1075
1058
  | `#exit` | 退出 |
@@ -1080,6 +1063,71 @@ run_agent_in_tui(agent, max_tokens=32000)
1080
1063
 
1081
1064
  完整说明(安装、指令、快捷键、自建界面)见 [`docs/tui.md`](./docs/tui.md)。
1082
1065
 
1066
+ ### 7.2 多 Agent 环境(`tina-multi-agent`)
1067
+
1068
+ 多 Agent 场景由独立发行包 **`tina-multi-agent`** 提供:把多个各自独立的 `Agent`(含 `MultimodalAgent`)注册进一个「环境」,通过消息总线互相通信,并带一个 Web 调试控制台用于观测与介入。
1069
+
1070
+ ```bash
1071
+ pip install tina-python[multi-agent] # 等价于安装 tina-multi-agent
1072
+ ```
1073
+
1074
+ ```python
1075
+ from tina import Agent
1076
+ from tina.llm import BaseAPI
1077
+ from tina_multi_agent import MultiAgentEnvironment, MultiAgentWeb
1078
+
1079
+ llm = BaseAPI()
1080
+
1081
+ env = MultiAgentEnvironment(name="room")
1082
+ env.add_agent(Agent(llm=llm, name="alice", system_prompt="你是 alice"))
1083
+ env.add_agent(Agent(llm=llm, name="bob", system_prompt="你是 bob"))
1084
+
1085
+ # 带 Web 控制台启动(自动启动环境):打开 http://127.0.0.1:7077
1086
+ MultiAgentWeb(env, port=7077).run()
1087
+ ```
1088
+
1089
+ - 每个 Agent 一个收信队列;外部指令走 `add_user_message`,同伴消息作为带 `name` 的 assistant 消息注入。
1090
+ - 支持**回合中途注入**(`before_llm_call`)、打断(`env.interrupt`)、工具确认与权限表。
1091
+ - Web 控制台能力、消息总线、`POST /instruction`、`WS /ws` 事件等完整说明见 [`packages/tina-multi-agent/README.md`](./packages/tina-multi-agent/README.md)。
1092
+
1093
+ > 兼容提示:旧路径 `tina.utils.multi_agent` 仍可用(主包内保留转发壳);未安装 `tina-multi-agent` 时会提示安装。
1094
+
1095
+ ### 7.3 编码工具(`CodingTools`)
1096
+
1097
+ 面向「写代码」的**主包内置**能力(命名空间 `code`),像普通工具包一样按需搭配到任意 Agent:一个编码工具包 + 一个项目感知的上下文管理器。提供可靠的**局部编辑**(精确文本匹配 + 唯一性校验 + 原子写)、搜索增强与命令输出截断。
1098
+
1099
+ ```python
1100
+ from tina import Agent
1101
+ from tina.utils.coding_tools import CodingTools
1102
+
1103
+ tools = CodingTools(root=".").get_tools() # code_read / code_glob / code_grep / code_write / code_edit / code_patch / code_bash
1104
+ agent = Agent(llm=llm, tools=tools)
1105
+ ```
1106
+
1107
+ | 工具 | 说明 | 需确认 |
1108
+ |------|------|--------|
1109
+ | `code_read` | 按行读取(offset/limit、行号、总行数与截断提示) | 否 |
1110
+ | `code_glob` | 按 glob 查找文件(如 `**/*.py`) | 否 |
1111
+ | `code_grep` | 正则搜索(`include` / 上下文行 / 忽略大小写) | 否 |
1112
+ | `code_write` | 整文件写入(`.py` 写前语法校验) | ✅ |
1113
+ | `code_edit` | 精确文本替换(命中多次需 `replace_all`,返回 diff) | ✅ |
1114
+ | `code_patch` | 应用 unified diff 补丁(一次多处/跨行改动,行号可偏差、上下文对不上则整体中止) | ✅ |
1115
+ | `code_bash` | 执行命令(首尾截断、带 exit code) | ✅ |
1116
+
1117
+ 配套的项目感知上下文管理器(自动注入 `AGENTS.md` / `.tinacode.md` / `.tina.md`、工作目录与目录结构摘要,可用 `refresh_project_context()` 刷新):
1118
+
1119
+ 既可在构造时传入,也可之后替换:
1120
+
1121
+ ```python
1122
+ from tina import Agent
1123
+ from tina.utils.coding_context import CodingContextManager
1124
+
1125
+ agent = Agent(llm=llm, tools=tools, context_manager=CodingContextManager(root="."))
1126
+ # 或:agent.set_context_manager(CodingContextManager(root="."))
1127
+ ```
1128
+
1129
+ > 未显式传 `system_prompt` 时,Agent 会**保留** `context_manager` 自带的系统提示(不再用默认提示覆盖);显式传 `system_prompt` 才会覆盖它。
1130
+
1083
1131
  ---
1084
1132
 
1085
1133
  ## 附录
@@ -1090,7 +1138,7 @@ tina 支持通过环境文件配置 API 信息,自动从当前目录查找 `.e
1090
1138
 
1091
1139
  ```env
1092
1140
  LLM_API_KEY="your-api-key"
1093
- BASE_URL="https://api.openai.com/v1/chat/completions"
1141
+ BASE_URL="https://api.openai.com/v1"
1094
1142
  MODEL_NAME="gpt-4o"
1095
1143
  MAX_INPUT=8000
1096
1144
  ```
@@ -1101,7 +1149,8 @@ MAX_INPUT=8000
1101
1149
  |------|------|
1102
1150
  | 核心功能 | `httpx`, `python-dotenv` |
1103
1151
  | MCP 支持 | `mcp` |
1104
- | TUI 界面(可选) | `textual` |
1152
+ | TUI 界面(可选,`tina-tui`) | `textual` |
1153
+ | 多 Agent(可选,`tina-multi-agent`) | `fastapi`, `uvicorn`, `websockets` |
1105
1154
  | 测试 | `pytest`, `pytest-asyncio`, `pytest-cov` |
1106
1155
 
1107
1156
  ### 许可证
@@ -15,10 +15,13 @@ pip install tina-python
15
15
  # 如果需要使用 MCP(模型上下文协议)服务
16
16
  pip install tina-python[mcp]
17
17
 
18
- # 如果需要 TUI 终端界面
18
+ # 如果需要 TUI 终端界面(独立发行包 tina-tui)
19
19
  pip install tina-python[tui]
20
20
 
21
- # 一次装齐所有可选功能(TUI + MCP)
21
+ # 如果需要多 Agent 环境 + Web 调试控制台(独立发行包 tina-multi-agent)
22
+ pip install tina-python[multi-agent]
23
+
24
+ # 一次装齐所有可选功能(TUI + 多 Agent + MCP)
22
25
  pip install tina-python[all]
23
26
 
24
27
  # 如果需要运行测试
@@ -34,7 +37,7 @@ from tina.llm import BaseAPI
34
37
  # 1. 实例化大模型(支持通过 tina.env 文件配置)
35
38
  llm = BaseAPI(
36
39
  api_key="your-api-key",
37
- base_url="https://api.openai.com/v1/chat/completions",
40
+ base_url="https://api.openai.com/v1",
38
41
  model="gpt-4o"
39
42
  )
40
43
 
@@ -75,7 +78,7 @@ for chunk in result:
75
78
  - [四、MCP 支持 —— 模型上下文协议](#四mcp-支持--模型上下文协议)
76
79
  - [五、多模态支持](#五多模态支持)
77
80
  - [六、快速开发工具](#六快速开发工具)
78
- - [6.5 终端界面 TUI(可选扩展)](#65-终端界面-tui可选扩展)
81
+ - [七、拓展包(可选)](#七拓展包可选)
79
82
 
80
83
  ---
81
84
 
@@ -103,7 +106,8 @@ tina 是一个轻量、模块化的 AI 智能体框架,专注于让开发者
103
106
  | **MCPClient** | MCP 集成 | 连接 MCP 服务器生态(stdio/SSE) |
104
107
  | **ContextManager** | 上下文管理 | 滚动窗口策略,自动截断 |
105
108
  | **AgentEvents** | 事件系统 | 贯穿 Agent 生命周期的回调钩子 |
106
- | **TUI(可选)** | 终端界面 | 测试你写的 Agent 的交互控制台,也可当作自己的 TUI 使用 |
109
+ | **TUI(可选)** | 终端界面 | 独立包 `tina-tui`:测试 Agent 的交互控制台,也可当作自己的 TUI 使用 |
110
+ | **多 Agent(可选)** | 多 Agent 环境 | 独立包 `tina-multi-agent`:消息总线 + Web 调试控制台 |
107
111
 
108
112
  ---
109
113
 
@@ -122,7 +126,7 @@ llm = BaseAPI()
122
126
  # 或者:手动传入参数
123
127
  llm = BaseAPI(
124
128
  api_key="your-api-key",
125
- base_url="https://api.openai.com/v1/chat/completions",
129
+ base_url="https://api.openai.com/v1",
126
130
  model="gpt-4o"
127
131
  )
128
132
  ```
@@ -130,11 +134,11 @@ llm = BaseAPI(
130
134
  `tina.env` 文件示例:
131
135
  ```env
132
136
  LLM_API_KEY="your-api-key"
133
- BASE_URL="https://api.openai.com/v1/chat/completions"
137
+ BASE_URL="https://api.openai.com/v1"
134
138
  MODEL_NAME="gpt-4o"
135
139
  ```
136
140
 
137
- > **注意**:`base_url` 需要包含完整的 `/chat/completions` 路由,tina 不会自动补充。
141
+ > **base_url 规则(0.7.0 起)**:只写服务根地址即可(如 `https://api.openai.com/v1`),tina 会自动补上 `/chat/completions`;写完整地址(`.../chat/completions`)也依然兼容。旧文档要求"必须自带 `/chat/completions`"的说法已作废。
138
142
 
139
143
  ### 1.2 非流式调用
140
144
 
@@ -669,7 +673,7 @@ tina 支持通过 MCP(Model Context Protocol)连接外部工具生态。
669
673
  pip install tina-python[mcp]
670
674
  ```
671
675
 
672
- > 想一次装齐所有可选功能(TUI + MCP):`pip install tina-python[all]`
676
+ > 想一次装齐所有可选功能(TUI + 多 Agent + MCP):`pip install tina-python[all]`
673
677
 
674
678
  ### 4.2 使用 MCP 客户端
675
679
 
@@ -860,55 +864,7 @@ message = build_multimodal_message(
860
864
 
861
865
  tina 提供了一些开箱即用的工具函数和工具包,帮助你快速搭建应用。
862
866
 
863
- ### 6.1 系统工具包 `system_tools`
864
-
865
- tina 自带一套系统工具包,包含文件操作、代码执行等常用功能:
866
-
867
- ```python
868
- from tina import Agent, Tools
869
- from tina.llm import BaseAPI
870
- from tina.utils.system_tools import system_tools
871
-
872
- tools = Tools(name="my_tools")
873
- tools += system_tools # 添加 tina 自带的系统工具包(工具集需命名)
874
-
875
- agent = Agent(
876
- llm=BaseAPI(),
877
- tools=tools,
878
- system_prompt="你是一个系统助手,可以帮助我管理文件和执行代码"
879
- )
880
-
881
- result = agent.predict(instruction="帮我看看当前目录下有哪些文件", stream=True)
882
- for chunk in result:
883
- print(chunk.content, end="")
884
- ```
885
-
886
- **内置工具一览:**
887
-
888
- | 工具名称 | 需要确认 | 功能说明 |
889
- |---------|---------|---------|
890
- | `get_time` | ❌ | 获取当前系统时间 |
891
- | `list_dir` | ❌ | 列出目录下的文件和子目录 |
892
- | `project_tree` | ❌ | 获取项目目录结构(类似 tree 命令) |
893
- | `get_path` | ❌ | 获取文件/文件夹的绝对路径 |
894
- | `read_code` | ❌ | 按字符范围读取文件内容片段 |
895
- | `read_code_by_line` | ❌ | 按行读取代码片段(带行号) |
896
- | `search_in_files` | ❌ | 在项目中按正则搜索文本(自动忽略 `.git`/`.venv` 等) |
897
- | `delay` | ❌ | 延时函数 |
898
- | `make_dir` | ✅ | 创建目录(自动创建父目录) |
899
- | `write_code` | ✅ | 写入文件内容(覆盖,自动创建父目录) |
900
- | `append_code` | ✅ | 追加写入文件内容(自动创建父目录) |
901
- | `delete_path` | ✅ | 删除文件或目录(`recursive=True` 可递归) |
902
- | `replace_code_by_lines` | ✅ | 按行范围替换代码块 |
903
- | `terminal` | ✅ | 在终端运行指令(带超时) |
904
- | `run_python` | ✅ | 执行一小段 Python 代码 |
905
- | `shot_down_system` | ✅ | 关机 |
906
-
907
- > `需要确认` 的工具在执行时会触发 `on_tool_confirmation` 事件,适合接入人工审批流程。
908
- >
909
- > 由于系统工具包使用了命名空间,工具在模型侧的实际名称为 `tina_sys_tools_{名称}`,例如 `tina_sys_tools_read_code`。
910
-
911
- ### 6.2 后台工作器 `AgentWorker`
867
+ ### 6.1 后台工作器 `AgentWorker`
912
868
 
913
869
  `AgentWorker` 将 Agent 包装为异步后台服务,通过消息队列接收外部指令并持续处理:
914
870
 
@@ -948,7 +904,7 @@ asyncio.run(main())
948
904
 
949
905
  `AgentWorker` 还会将自身的 `put` 方法自动注册为 Agent 的工具,方便多 Agent 场景下互相调用。
950
906
 
951
- ### 6.3 终端交互控制台 `run_agent_in_cli`
907
+ ### 6.2 终端交互控制台 `run_agent_in_cli`
952
908
 
953
909
  快速启动一个 Agent 交互式终端,适合调试和测试:
954
910
 
@@ -974,7 +930,7 @@ run_agent_in_cli(agent)
974
930
  | `#clear` | 清屏 |
975
931
  | `exit` / `quit` | 退出对话(`#exit` 不支持,会被当作普通输入) |
976
932
 
977
- ### 6.4 多模态消息构建器 `build_multimodal_message`
933
+ ### 6.3 多模态消息构建器 `build_multimodal_message`
978
934
 
979
935
  用于灵活构建包含多模态内容的消息:
980
936
 
@@ -993,7 +949,13 @@ print(message)
993
949
  # {"role": "user", "content": [{"type": "text", "text": "..."}, {"type": "image_url", ...}]}
994
950
  ```
995
951
 
996
- ### 6.5 终端界面 TUI(可选扩展)
952
+ ---
953
+
954
+ ## 七、拓展包(可选)
955
+
956
+ 除核心之外的可选能力:有**随主包提供**的(编码工具),也有拆成**独立发行包**的(终端界面、多 Agent 环境),按需安装、可独立更新与发布。主包内不再包含后者的实现(仅保留 `tina.utils.*` 兼容转发壳)。
957
+
958
+ ### 7.1 终端界面 TUI(`tina-tui`)
997
959
 
998
960
  终端界面由配套包 **`tina-tui`**(基于 [Textual](https://textual.textualize.io/))提供,作为**可选扩展**单独发行:方便你测试自己写的 Agent,也可以直接当作自己的 TUI 来用。核心不依赖它,需要额外安装:
999
961
 
@@ -1001,6 +963,21 @@ print(message)
1001
963
  pip install tina-python[tui] # 等价于安装 tina-tui
1002
964
  ```
1003
965
 
966
+ **开箱即用的 `tinacode` 命令**:装好后可以在任意目录直接起一个编码 agent,不用写 Python:
967
+
968
+ ```bash
969
+ cd <你的项目>
970
+ tinacode
971
+ ```
972
+
973
+ - 工作目录 = 你敲命令时所在的目录(`code_*` 工具的相对路径以它为准)
974
+ - 会话历史存到 `<cwd>/.tina/chat_sessions/`,**按目录隔离**
975
+ - 模型配置读 `<cwd>/tina.env` 或 `.env`,没有则回退全局 `~/.tina/tina.env`
976
+ - 目录里的 `.tinacode.md` / `AGENTS.md` / `.tina.md` 自动注入系统提示(目录级定制不用改代码)
977
+ - 工具集是 `CodingTools`(见 [7.3](#73-编码工具codingtools))
978
+
979
+ 自己组装 Agent 再交给 TUI:
980
+
1004
981
  ```python
1005
982
  from tina import Agent, Tools
1006
983
  from tina.llm import BaseAPI
@@ -1021,8 +998,9 @@ run_agent_in_tui(agent, max_tokens=32000)
1021
998
  - 自动为 Agent 注册工具确认事件(`require_confirmation=True` 的工具会弹出选择条)
1022
999
  - 上下文 token 占用与上限进度(显示百分比,≥80% 变黄、超限变红警告),运行时显示动画
1023
1000
  - `Esc` 可打断本轮回复;已生成的部分正文写回上下文,进行中的工具调用记为「该次调用被打断」
1024
- - 输入框支持多行与粘贴;`Enter` 发送、`Shift+Enter` 换行、`Tab` 补全命令
1001
+ - 输入框支持多行与粘贴;`Enter` 发送、`Shift+Enter` 换行、`Tab` 补全命令与会话 id
1025
1002
  - 底部粘性滚动:在底部时自动跟随输出,向上滚动查看历史时不会被打扰,滚回底部自动恢复
1003
+ - 会话自动归档到 `<项目>/.tina/chat_sessions/`:可切换 / 重命名 / 删除,首轮结束后自动起名
1026
1004
  - 可选 `unlimited_context=True`:用 tina 提供的无限制上下文管理器替换 Agent 的(不裁剪历史、不截断工具结果)
1027
1005
 
1028
1006
  | 指令 | 功能 |
@@ -1032,6 +1010,11 @@ run_agent_in_tui(agent, max_tokens=32000)
1032
1010
  | `#context` | 查看当前上下文 |
1033
1011
  | `#model` | 查看当前模型信息 |
1034
1012
  | `#tokens` | 查看当前上下文 token 占用 |
1013
+ | `#sessions` | 列出已保存的会话(可跟关键字过滤) |
1014
+ | `#switch` | 切换会话(按 id / id 前缀 / 标题) |
1015
+ | `#new` | 新建会话(当前会话自动保存) |
1016
+ | `#rename` | 重命名当前会话 |
1017
+ | `#delete` | 删除会话 |
1035
1018
  | `#compact` | 压缩上下文(让 Agent 自我总结并并入 system) |
1036
1019
  | `#clear` | 清空上下文与界面 |
1037
1020
  | `#exit` | 退出 |
@@ -1042,6 +1025,71 @@ run_agent_in_tui(agent, max_tokens=32000)
1042
1025
 
1043
1026
  完整说明(安装、指令、快捷键、自建界面)见 [`docs/tui.md`](./docs/tui.md)。
1044
1027
 
1028
+ ### 7.2 多 Agent 环境(`tina-multi-agent`)
1029
+
1030
+ 多 Agent 场景由独立发行包 **`tina-multi-agent`** 提供:把多个各自独立的 `Agent`(含 `MultimodalAgent`)注册进一个「环境」,通过消息总线互相通信,并带一个 Web 调试控制台用于观测与介入。
1031
+
1032
+ ```bash
1033
+ pip install tina-python[multi-agent] # 等价于安装 tina-multi-agent
1034
+ ```
1035
+
1036
+ ```python
1037
+ from tina import Agent
1038
+ from tina.llm import BaseAPI
1039
+ from tina_multi_agent import MultiAgentEnvironment, MultiAgentWeb
1040
+
1041
+ llm = BaseAPI()
1042
+
1043
+ env = MultiAgentEnvironment(name="room")
1044
+ env.add_agent(Agent(llm=llm, name="alice", system_prompt="你是 alice"))
1045
+ env.add_agent(Agent(llm=llm, name="bob", system_prompt="你是 bob"))
1046
+
1047
+ # 带 Web 控制台启动(自动启动环境):打开 http://127.0.0.1:7077
1048
+ MultiAgentWeb(env, port=7077).run()
1049
+ ```
1050
+
1051
+ - 每个 Agent 一个收信队列;外部指令走 `add_user_message`,同伴消息作为带 `name` 的 assistant 消息注入。
1052
+ - 支持**回合中途注入**(`before_llm_call`)、打断(`env.interrupt`)、工具确认与权限表。
1053
+ - Web 控制台能力、消息总线、`POST /instruction`、`WS /ws` 事件等完整说明见 [`packages/tina-multi-agent/README.md`](./packages/tina-multi-agent/README.md)。
1054
+
1055
+ > 兼容提示:旧路径 `tina.utils.multi_agent` 仍可用(主包内保留转发壳);未安装 `tina-multi-agent` 时会提示安装。
1056
+
1057
+ ### 7.3 编码工具(`CodingTools`)
1058
+
1059
+ 面向「写代码」的**主包内置**能力(命名空间 `code`),像普通工具包一样按需搭配到任意 Agent:一个编码工具包 + 一个项目感知的上下文管理器。提供可靠的**局部编辑**(精确文本匹配 + 唯一性校验 + 原子写)、搜索增强与命令输出截断。
1060
+
1061
+ ```python
1062
+ from tina import Agent
1063
+ from tina.utils.coding_tools import CodingTools
1064
+
1065
+ tools = CodingTools(root=".").get_tools() # code_read / code_glob / code_grep / code_write / code_edit / code_patch / code_bash
1066
+ agent = Agent(llm=llm, tools=tools)
1067
+ ```
1068
+
1069
+ | 工具 | 说明 | 需确认 |
1070
+ |------|------|--------|
1071
+ | `code_read` | 按行读取(offset/limit、行号、总行数与截断提示) | 否 |
1072
+ | `code_glob` | 按 glob 查找文件(如 `**/*.py`) | 否 |
1073
+ | `code_grep` | 正则搜索(`include` / 上下文行 / 忽略大小写) | 否 |
1074
+ | `code_write` | 整文件写入(`.py` 写前语法校验) | ✅ |
1075
+ | `code_edit` | 精确文本替换(命中多次需 `replace_all`,返回 diff) | ✅ |
1076
+ | `code_patch` | 应用 unified diff 补丁(一次多处/跨行改动,行号可偏差、上下文对不上则整体中止) | ✅ |
1077
+ | `code_bash` | 执行命令(首尾截断、带 exit code) | ✅ |
1078
+
1079
+ 配套的项目感知上下文管理器(自动注入 `AGENTS.md` / `.tinacode.md` / `.tina.md`、工作目录与目录结构摘要,可用 `refresh_project_context()` 刷新):
1080
+
1081
+ 既可在构造时传入,也可之后替换:
1082
+
1083
+ ```python
1084
+ from tina import Agent
1085
+ from tina.utils.coding_context import CodingContextManager
1086
+
1087
+ agent = Agent(llm=llm, tools=tools, context_manager=CodingContextManager(root="."))
1088
+ # 或:agent.set_context_manager(CodingContextManager(root="."))
1089
+ ```
1090
+
1091
+ > 未显式传 `system_prompt` 时,Agent 会**保留** `context_manager` 自带的系统提示(不再用默认提示覆盖);显式传 `system_prompt` 才会覆盖它。
1092
+
1045
1093
  ---
1046
1094
 
1047
1095
  ## 附录
@@ -1052,7 +1100,7 @@ tina 支持通过环境文件配置 API 信息,自动从当前目录查找 `.e
1052
1100
 
1053
1101
  ```env
1054
1102
  LLM_API_KEY="your-api-key"
1055
- BASE_URL="https://api.openai.com/v1/chat/completions"
1103
+ BASE_URL="https://api.openai.com/v1"
1056
1104
  MODEL_NAME="gpt-4o"
1057
1105
  MAX_INPUT=8000
1058
1106
  ```
@@ -1063,7 +1111,8 @@ MAX_INPUT=8000
1063
1111
  |------|------|
1064
1112
  | 核心功能 | `httpx`, `python-dotenv` |
1065
1113
  | MCP 支持 | `mcp` |
1066
- | TUI 界面(可选) | `textual` |
1114
+ | TUI 界面(可选,`tina-tui`) | `textual` |
1115
+ | 多 Agent(可选,`tina-multi-agent`) | `fastapi`, `uvicorn`, `websockets` |
1067
1116
  | 测试 | `pytest`, `pytest-asyncio`, `pytest-cov` |
1068
1117
 
1069
1118
  ### 许可证
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tina-python"
7
- version = "0.7.0"
7
+ version = "0.7.2"
8
8
  description = "tina is in your computer!"
9
9
  readme = { file = "README.md", content-type = "text/markdown" }
10
10
  requires-python = ">=3.10"
@@ -29,7 +29,9 @@ GitHub = "https://github.com/XIMOCY/tina.git"
29
29
 
30
30
  [project.optional-dependencies]
31
31
  tui = [
32
- "tina-tui>=0.1.0",
32
+ # 0.2.0 起提供 tinacode 命令;不收紧的话,已装 tina-tui 0.1.0 的环境
33
+ # pip 不会升级它,用户拿不到 tinacode
34
+ "tina-tui>=0.2.0",
33
35
  ]
34
36
  multi-agent = [
35
37
  "tina-multi-agent>=0.1.0",
@@ -43,7 +45,7 @@ test = [
43
45
  "pytest-cov>=7.0",
44
46
  ]
45
47
  all = [
46
- "tina-tui>=0.1.0",
48
+ "tina-tui>=0.2.0",
47
49
  "tina-multi-agent>=0.1.0",
48
50
  "mcp>=2.0",
49
51
  ]
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="tina-python",
5
- version="0.7.0",
5
+ version="0.7.1",
6
6
  packages=find_packages(),
7
7
  package_data={"tina": ["py.typed"]},
8
8
  install_requires=["httpx", "python-dotenv"],
@@ -21,4 +21,4 @@ __all__ = [
21
21
  "AgentEvents",
22
22
  "FilesAPI",
23
23
  ]
24
- __version__ = "0.7.0"
24
+ __version__ = "0.7.2"