tina-python 0.7.4__tar.gz → 0.7.5__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.
- {tina_python-0.7.4/tina_python.egg-info → tina_python-0.7.5}/PKG-INFO +1 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/pyproject.toml +1 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/setup.py +1 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/__init__.py +1 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/agent_response.py +0 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/events.py +0 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/multimodal_agent.py +1 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/context/manager.py +1 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/context/message.py +36 -11
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/core/error.py +1 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/llm/base_api.py +1 -2
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/llm/base_multimodal_api.py +0 -4
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/mcp/client.py +0 -2
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/output_parser.py +0 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/run_agent_in_cli.py +1 -2
- {tina_python-0.7.4 → tina_python-0.7.5/tina_python.egg-info}/PKG-INFO +1 -1
- {tina_python-0.7.4 → tina_python-0.7.5}/LICENSE +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/MANIFEST.in +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/README.md +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/setup.cfg +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/agent.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/agent_runtime.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/context_manager.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/executor.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/keyword_actions.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/message_view.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/prompt.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/state.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/agent/core/tools.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/context/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/core/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/core/logger.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/llm/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/llm/files_api.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/mcp/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/mcp/mcp_tools_executor.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/py.typed +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/agent_worker.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/coding_context.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/coding_tools.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/deepseek.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/doc_parser.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/env_reader.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/multi_agent/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/multi_agent/environment.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/multi_agent/message.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/multi_agent/message_bus.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/multi_agent/web/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/multi_agent/web/server.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/multimodal_formatter.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/session_store.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/tui/__init__.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/tui/context_manager.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/tui/token.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/tui/tui.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/type_mapper.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/url.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina/utils/usage.py +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina_python.egg-info/SOURCES.txt +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina_python.egg-info/dependency_links.txt +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina_python.egg-info/requires.txt +0 -0
- {tina_python-0.7.4 → tina_python-0.7.5}/tina_python.egg-info/top_level.txt +0 -0
|
@@ -58,7 +58,7 @@ class MultimodalAgent(Agent):
|
|
|
58
58
|
events: tina.AgentEvents类型,事件管理器,用于管理事件,
|
|
59
59
|
context_manager: tina.ContextManager类型,上下文管理器,
|
|
60
60
|
agent_runtime: tina.BaseAgentRuntime类型,运行时,
|
|
61
|
-
max_tool_loop: int
|
|
61
|
+
max_tool_loop: int 最大工具调用次数,超过该次数则停止调用工具(默认 100)
|
|
62
62
|
name: str 智能体名字,用于多Agent区分
|
|
63
63
|
keyword_actions: KeywordActions,可选关键词动作
|
|
64
64
|
|
|
@@ -54,7 +54,7 @@ def _coerce_messages(messages: Any) -> list:
|
|
|
54
54
|
messages = list(messages)
|
|
55
55
|
if all(isinstance(item, dict) for item in messages):
|
|
56
56
|
return parse_messages(messages)
|
|
57
|
-
if all(isinstance(item,
|
|
57
|
+
if all(isinstance(item, Message) for item in messages):
|
|
58
58
|
return messages
|
|
59
59
|
raise TypeError(
|
|
60
60
|
"set_messages/add_messages 只接受「全是 dict」或「全是 Message/ToolCalls」,不能混用"
|
|
@@ -87,6 +87,24 @@ def content_chars(content: Any) -> int:
|
|
|
87
87
|
return 0
|
|
88
88
|
|
|
89
89
|
|
|
90
|
+
def _get_field(obj: Any, key: str, default: Any = None) -> Any:
|
|
91
|
+
"""dict 风格的字段读取,供 `Message.get()` / `ToolCalls.get()` 使用
|
|
92
|
+
|
|
93
|
+
0.7.4 把上下文改存对象后,下游大量 `msg.get("role")` 写法会
|
|
94
|
+
`AttributeError`。这里提供一个兼容入口:能读到属性就读属性,
|
|
95
|
+
读不到再翻 `extra`(未知的 wire 字段),最后回退到 `default`。
|
|
96
|
+
"""
|
|
97
|
+
if key == "tool_calls":
|
|
98
|
+
# `ToolCalls` 对象把调用放在 `.calls` 上
|
|
99
|
+
return getattr(obj, "calls", default)
|
|
100
|
+
if hasattr(obj, key):
|
|
101
|
+
return getattr(obj, key)
|
|
102
|
+
extra = getattr(obj, "extra", None)
|
|
103
|
+
if extra:
|
|
104
|
+
return extra.get(key, default)
|
|
105
|
+
return default
|
|
106
|
+
|
|
107
|
+
|
|
90
108
|
class Message:
|
|
91
109
|
"""消息基类:`role` + `content` + 未知字段兜底"""
|
|
92
110
|
|
|
@@ -124,6 +142,20 @@ class Message:
|
|
|
124
142
|
|
|
125
143
|
# --- 便利方法 ---
|
|
126
144
|
|
|
145
|
+
def get(self, key: str, default: Any = None) -> Any:
|
|
146
|
+
"""dict 风格读字段,兼容 0.7.3 及以前的写法
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
msg.get("role") # → "user"
|
|
150
|
+
msg.get("reasoning_content") # 没有该属性时回退 extra / default
|
|
151
|
+
msg.get("tool_calls") # ToolCalls 对象返回 .calls
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
新代码建议直接用属性(`msg.role` / `msg.content`),这个入口只为
|
|
155
|
+
让下游的旧代码零改动升级。
|
|
156
|
+
"""
|
|
157
|
+
return _get_field(self, key, default)
|
|
158
|
+
|
|
127
159
|
def copy(self) -> "Message":
|
|
128
160
|
import copy as _copy
|
|
129
161
|
|
|
@@ -175,7 +207,7 @@ class AssistantMessage(Message):
|
|
|
175
207
|
return [data]
|
|
176
208
|
|
|
177
209
|
|
|
178
|
-
class ToolCalls:
|
|
210
|
+
class ToolCalls(Message):
|
|
179
211
|
"""一次工具调用回合 —— **原子单位**
|
|
180
212
|
|
|
181
213
|
展开后是 1 + N 条消息:
|
|
@@ -203,20 +235,18 @@ class ToolCalls:
|
|
|
203
235
|
meta: dict[str, Any] | None = None,
|
|
204
236
|
revision: Revision | None = None,
|
|
205
237
|
) -> None:
|
|
238
|
+
# 复用 Message 的 content 兜底 / extra / meta
|
|
239
|
+
super().__init__(content, extra=extra, meta=meta)
|
|
206
240
|
#: 变更计数器(由 ContextManager 注入,用于派生缓存失效)
|
|
207
241
|
self._revision = revision
|
|
208
242
|
#: N 个 tool_call(并行调用就是 N>1)
|
|
209
243
|
self.calls: list[dict[str, Any]] = [dict(call) for call in calls]
|
|
210
244
|
#: call_id -> 工具结果文本;缺的视为「被中断」
|
|
211
245
|
self.results: dict[str, str] = ResultMap(results or {}, revision)
|
|
212
|
-
#: assistant 自己的正文(通常是空串)
|
|
213
|
-
self.content = "" if content is None else content
|
|
214
246
|
#: DeepSeek 等思考模型的思维链。**带 tool_calls 的这条也必须回传**,否则 400
|
|
215
247
|
self.reasoning_content = reasoning_content
|
|
216
248
|
#: tool 消息上的未知字段(保证无损往返)
|
|
217
249
|
self.result_extra: dict[str, dict[str, Any]] = dict(result_extra or {})
|
|
218
|
-
self.extra: dict[str, Any] = dict(extra or {})
|
|
219
|
-
self.meta: dict[str, Any] = dict(meta or {})
|
|
220
250
|
|
|
221
251
|
# --- 便利访问 ---
|
|
222
252
|
|
|
@@ -278,11 +308,6 @@ class ToolCalls:
|
|
|
278
308
|
out.append(message)
|
|
279
309
|
return out
|
|
280
310
|
|
|
281
|
-
def copy(self) -> "ToolCalls":
|
|
282
|
-
import copy as _copy
|
|
283
|
-
|
|
284
|
-
return _copy.deepcopy(self)
|
|
285
|
-
|
|
286
311
|
def __repr__(self) -> str:
|
|
287
312
|
return f"ToolCalls({len(self.calls)} 个调用,{len(self.results)} 个结果)"
|
|
288
313
|
|
|
@@ -324,7 +349,7 @@ class MessageList(list):
|
|
|
324
349
|
|
|
325
350
|
@staticmethod
|
|
326
351
|
def _check(item: Any) -> None:
|
|
327
|
-
if isinstance(item,
|
|
352
|
+
if isinstance(item, Message):
|
|
328
353
|
return
|
|
329
354
|
raise TypeError(
|
|
330
355
|
f"messages 里只能放 Message / ToolCalls 对象,收到 {type(item).__name__}。"
|
|
@@ -134,7 +134,7 @@ def classify_api_error(error: BaseException) -> dict:
|
|
|
134
134
|
class ModelPathNotGiven(TinaError):
|
|
135
135
|
def __init__(self, model_name: str):
|
|
136
136
|
super().__init__(
|
|
137
|
-
|
|
137
|
+
"Model path is not given. Please provide a valid model path. \n模型的路径没有给出,请提供一个有效的模型路径。"
|
|
138
138
|
)
|
|
139
139
|
|
|
140
140
|
|
|
@@ -137,7 +137,7 @@ class BaseAPI:
|
|
|
137
137
|
"""
|
|
138
138
|
if self._async_client is None or self._async_client.is_closed:
|
|
139
139
|
self._async_client = httpx.AsyncClient(timeout=self._timeout)
|
|
140
|
-
self.logger.debug(
|
|
140
|
+
self.logger.debug("BaseAPI - 异步客户端已在当前 Loop 中创建")
|
|
141
141
|
return self._async_client
|
|
142
142
|
|
|
143
143
|
async def fetch_balance(self) -> dict | None:
|
|
@@ -785,7 +785,6 @@ class BaseAPI:
|
|
|
785
785
|
Raises:
|
|
786
786
|
APIRequestFailed: 当API调用失败时抛出异常
|
|
787
787
|
"""
|
|
788
|
-
import httpx
|
|
789
788
|
from ..core.error import APIRequestFailed
|
|
790
789
|
|
|
791
790
|
messages = self._prepare_messages(input_text, role, sys_prompt, messages)
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import httpx
|
|
2
|
-
import json
|
|
3
|
-
import os
|
|
4
2
|
from typing import AsyncGenerator, Union, Generator
|
|
5
|
-
from ..utils.env_reader import EnvReader
|
|
6
3
|
from ..core.error import APIRequestFailed
|
|
7
4
|
from ..utils.output_parser import stream_generator_parser
|
|
8
5
|
from ..utils.multimodal_formatter import build_multimodal_message
|
|
9
|
-
from ..core import logger
|
|
10
6
|
|
|
11
7
|
|
|
12
8
|
from .base_api import BaseAPI
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import os
|
|
3
|
-
import sys
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
async def ainput(prompt: str) -> str:
|
|
@@ -59,7 +58,7 @@ def run_agent_in_cli(agent):
|
|
|
59
58
|
if t_name not in active_tools:
|
|
60
59
|
active_tools[t_name] = {"args": ""}
|
|
61
60
|
print(f"\n\n\033[1;33m🛠️ [调用工具] {t_name}\033[0m")
|
|
62
|
-
print(
|
|
61
|
+
print("\033[90m [参数构建]: \033[0m", end="", flush=True)
|
|
63
62
|
last_role = "assistant"
|
|
64
63
|
|
|
65
64
|
# 3. 处理工具参数流 (改用 t_name 索引,增加安全判断)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|