tina-python 0.6.5__tar.gz → 0.6.6__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.6.5/tina_python.egg-info → tina_python-0.6.6}/PKG-INFO +22 -13
- {tina_python-0.6.5 → tina_python-0.6.6}/README.md +21 -12
- {tina_python-0.6.5 → tina_python-0.6.6}/pyproject.toml +1 -1
- {tina_python-0.6.5 → tina_python-0.6.6}/setup.py +1 -1
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/__init__.py +1 -1
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/mcp/client.py +65 -8
- {tina_python-0.6.5 → tina_python-0.6.6/tina_python.egg-info}/PKG-INFO +22 -13
- {tina_python-0.6.5 → tina_python-0.6.6}/LICENSE +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/MANIFEST.in +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/setup.cfg +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/__init__.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/agent.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/__init__.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/agent_response.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/agent_runtime.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/context_manager.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/events.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/executor.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/keyword_actions.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/prompt.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/state.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/core/tools.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/agent/multimodal_agent.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/core/__init__.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/core/error.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/core/logger.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/llm/BaseNewAPI.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/llm/__init__.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/llm/base_api.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/llm/base_multimodal_api.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/llm/ollama_api.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/mcp/__init__.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/mcp/mcp_tools_executor.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/py.typed +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/__init__.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/agent_worker.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/deepseek.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/doc_parser.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/env_reader.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/multimodal_formatter.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/output_parser.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/run_agent_in_cli.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/system_tools.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/timer.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/tui/__init__.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/tui/context_manager.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/tui/token.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/tui/tui.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina/utils/type_mapper.py +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina_python.egg-info/SOURCES.txt +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina_python.egg-info/dependency_links.txt +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/tina_python.egg-info/requires.txt +0 -0
- {tina_python-0.6.5 → tina_python-0.6.6}/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.6.
|
|
3
|
+
Version: 0.6.6
|
|
4
4
|
Summary: tina is in your computer!
|
|
5
5
|
Home-page: https://gitee.com/wang-churi/tina
|
|
6
6
|
Author: 王出日
|
|
@@ -50,6 +50,12 @@ pip install tina-python
|
|
|
50
50
|
# 如果需要使用 MCP(模型上下文协议)服务
|
|
51
51
|
pip install tina-python[mcp]
|
|
52
52
|
|
|
53
|
+
# 如果需要 TUI 终端界面
|
|
54
|
+
pip install tina-python[tui]
|
|
55
|
+
|
|
56
|
+
# 一次装齐所有可选功能(TUI + MCP)
|
|
57
|
+
pip install tina-python[all]
|
|
58
|
+
|
|
53
59
|
# 如果需要运行测试
|
|
54
60
|
pip install tina-python[test]
|
|
55
61
|
```
|
|
@@ -211,8 +217,9 @@ result = await llm.apredict(
|
|
|
211
217
|
stream=False
|
|
212
218
|
)
|
|
213
219
|
|
|
214
|
-
#
|
|
215
|
-
|
|
220
|
+
# 异步流式:先 await 拿到异步生成器
|
|
221
|
+
result = await llm.apredict(input_text="讲个故事", stream=True)
|
|
222
|
+
async for chunk in result:
|
|
216
223
|
print(chunk["content"], end="")
|
|
217
224
|
```
|
|
218
225
|
|
|
@@ -242,8 +249,6 @@ async for chunk in llm.apredict(input_text="讲个故事", stream=True):
|
|
|
242
249
|
{
|
|
243
250
|
"role": "assistant",
|
|
244
251
|
"content": "回复内容",
|
|
245
|
-
# 推理模型时会出现
|
|
246
|
-
"reasoning_content": "推理链...",
|
|
247
252
|
# 有工具调用时会出现
|
|
248
253
|
"tool_calls": [
|
|
249
254
|
{
|
|
@@ -255,7 +260,8 @@ async for chunk in llm.apredict(input_text="讲个故事", stream=True):
|
|
|
255
260
|
]
|
|
256
261
|
}
|
|
257
262
|
|
|
258
|
-
#
|
|
263
|
+
# 流式:逐块返回片段,工具调用以 tool_name / tool_arguments 片段给出;
|
|
264
|
+
# 推理模型的思维链在 reasoning_content 中,末尾可能带有 usage
|
|
259
265
|
```
|
|
260
266
|
|
|
261
267
|
### 1.8 获取可用模型列表
|
|
@@ -392,9 +398,12 @@ tool_calls = [
|
|
|
392
398
|
}
|
|
393
399
|
}
|
|
394
400
|
]
|
|
395
|
-
|
|
401
|
+
# execute 需要事件对象(Agent 内部会自动传入)
|
|
402
|
+
from tina import AgentEvents
|
|
403
|
+
|
|
404
|
+
results = tools.execute(tool_calls, events=AgentEvents())
|
|
396
405
|
# [
|
|
397
|
-
# {"role": "tool", "tool_call_id": "call_123", "
|
|
406
|
+
# {"role": "tool", "tool_call_id": "call_123", "tool_name": "get_weather", "content": "北京今天天气晴朗"}
|
|
398
407
|
# ]
|
|
399
408
|
```
|
|
400
409
|
|
|
@@ -542,7 +551,7 @@ elif agent.state == AgentState.ERROR:
|
|
|
542
551
|
# 获取消息列表
|
|
543
552
|
messages = agent.get_messages()
|
|
544
553
|
|
|
545
|
-
#
|
|
554
|
+
# 清空全部消息(含系统提示词,之后需重新 set_system_prompt)
|
|
546
555
|
agent.clear_messages()
|
|
547
556
|
|
|
548
557
|
# 获取系统提示词
|
|
@@ -630,7 +639,7 @@ def on_turn_end():
|
|
|
630
639
|
agent_a = Agent(llm=llm, tools=tools, name="agent_a")
|
|
631
640
|
agent_b = Agent(llm=llm, tools=tools, name="agent_b")
|
|
632
641
|
|
|
633
|
-
#
|
|
642
|
+
# 关联另一个 Agent(记录到 other_agents,目前不会自动共享消息列表)
|
|
634
643
|
agent_a.connect_agent(agent_b)
|
|
635
644
|
|
|
636
645
|
# 断开连接
|
|
@@ -889,8 +898,8 @@ from tina import Agent, Tools
|
|
|
889
898
|
from tina.llm import BaseAPI
|
|
890
899
|
from tina.utils.system_tools import system_tools
|
|
891
900
|
|
|
892
|
-
tools = Tools()
|
|
893
|
-
tools += system_tools # 添加 tina
|
|
901
|
+
tools = Tools(name="my_tools")
|
|
902
|
+
tools += system_tools # 添加 tina 自带的系统工具包(工具集需命名)
|
|
894
903
|
|
|
895
904
|
agent = Agent(
|
|
896
905
|
llm=BaseAPI(),
|
|
@@ -992,7 +1001,7 @@ run_agent_in_cli(agent)
|
|
|
992
1001
|
|------|------|
|
|
993
1002
|
| `#context` | 查看当前对话上下文(消息列表) |
|
|
994
1003
|
| `#clear` | 清屏 |
|
|
995
|
-
|
|
|
1004
|
+
| `exit` / `quit` | 退出对话(`#exit` 不支持,会被当作普通输入) |
|
|
996
1005
|
|
|
997
1006
|
### 6.4 多模态消息构建器 `build_multimodal_message`
|
|
998
1007
|
|
|
@@ -15,6 +15,12 @@ pip install tina-python
|
|
|
15
15
|
# 如果需要使用 MCP(模型上下文协议)服务
|
|
16
16
|
pip install tina-python[mcp]
|
|
17
17
|
|
|
18
|
+
# 如果需要 TUI 终端界面
|
|
19
|
+
pip install tina-python[tui]
|
|
20
|
+
|
|
21
|
+
# 一次装齐所有可选功能(TUI + MCP)
|
|
22
|
+
pip install tina-python[all]
|
|
23
|
+
|
|
18
24
|
# 如果需要运行测试
|
|
19
25
|
pip install tina-python[test]
|
|
20
26
|
```
|
|
@@ -176,8 +182,9 @@ result = await llm.apredict(
|
|
|
176
182
|
stream=False
|
|
177
183
|
)
|
|
178
184
|
|
|
179
|
-
#
|
|
180
|
-
|
|
185
|
+
# 异步流式:先 await 拿到异步生成器
|
|
186
|
+
result = await llm.apredict(input_text="讲个故事", stream=True)
|
|
187
|
+
async for chunk in result:
|
|
181
188
|
print(chunk["content"], end="")
|
|
182
189
|
```
|
|
183
190
|
|
|
@@ -207,8 +214,6 @@ async for chunk in llm.apredict(input_text="讲个故事", stream=True):
|
|
|
207
214
|
{
|
|
208
215
|
"role": "assistant",
|
|
209
216
|
"content": "回复内容",
|
|
210
|
-
# 推理模型时会出现
|
|
211
|
-
"reasoning_content": "推理链...",
|
|
212
217
|
# 有工具调用时会出现
|
|
213
218
|
"tool_calls": [
|
|
214
219
|
{
|
|
@@ -220,7 +225,8 @@ async for chunk in llm.apredict(input_text="讲个故事", stream=True):
|
|
|
220
225
|
]
|
|
221
226
|
}
|
|
222
227
|
|
|
223
|
-
#
|
|
228
|
+
# 流式:逐块返回片段,工具调用以 tool_name / tool_arguments 片段给出;
|
|
229
|
+
# 推理模型的思维链在 reasoning_content 中,末尾可能带有 usage
|
|
224
230
|
```
|
|
225
231
|
|
|
226
232
|
### 1.8 获取可用模型列表
|
|
@@ -357,9 +363,12 @@ tool_calls = [
|
|
|
357
363
|
}
|
|
358
364
|
}
|
|
359
365
|
]
|
|
360
|
-
|
|
366
|
+
# execute 需要事件对象(Agent 内部会自动传入)
|
|
367
|
+
from tina import AgentEvents
|
|
368
|
+
|
|
369
|
+
results = tools.execute(tool_calls, events=AgentEvents())
|
|
361
370
|
# [
|
|
362
|
-
# {"role": "tool", "tool_call_id": "call_123", "
|
|
371
|
+
# {"role": "tool", "tool_call_id": "call_123", "tool_name": "get_weather", "content": "北京今天天气晴朗"}
|
|
363
372
|
# ]
|
|
364
373
|
```
|
|
365
374
|
|
|
@@ -507,7 +516,7 @@ elif agent.state == AgentState.ERROR:
|
|
|
507
516
|
# 获取消息列表
|
|
508
517
|
messages = agent.get_messages()
|
|
509
518
|
|
|
510
|
-
#
|
|
519
|
+
# 清空全部消息(含系统提示词,之后需重新 set_system_prompt)
|
|
511
520
|
agent.clear_messages()
|
|
512
521
|
|
|
513
522
|
# 获取系统提示词
|
|
@@ -595,7 +604,7 @@ def on_turn_end():
|
|
|
595
604
|
agent_a = Agent(llm=llm, tools=tools, name="agent_a")
|
|
596
605
|
agent_b = Agent(llm=llm, tools=tools, name="agent_b")
|
|
597
606
|
|
|
598
|
-
#
|
|
607
|
+
# 关联另一个 Agent(记录到 other_agents,目前不会自动共享消息列表)
|
|
599
608
|
agent_a.connect_agent(agent_b)
|
|
600
609
|
|
|
601
610
|
# 断开连接
|
|
@@ -854,8 +863,8 @@ from tina import Agent, Tools
|
|
|
854
863
|
from tina.llm import BaseAPI
|
|
855
864
|
from tina.utils.system_tools import system_tools
|
|
856
865
|
|
|
857
|
-
tools = Tools()
|
|
858
|
-
tools += system_tools # 添加 tina
|
|
866
|
+
tools = Tools(name="my_tools")
|
|
867
|
+
tools += system_tools # 添加 tina 自带的系统工具包(工具集需命名)
|
|
859
868
|
|
|
860
869
|
agent = Agent(
|
|
861
870
|
llm=BaseAPI(),
|
|
@@ -957,7 +966,7 @@ run_agent_in_cli(agent)
|
|
|
957
966
|
|------|------|
|
|
958
967
|
| `#context` | 查看当前对话上下文(消息列表) |
|
|
959
968
|
| `#clear` | 清屏 |
|
|
960
|
-
|
|
|
969
|
+
| `exit` / `quit` | 退出对话(`#exit` 不支持,会被当作普通输入) |
|
|
961
970
|
|
|
962
971
|
### 6.4 多模态消息构建器 `build_multimodal_message`
|
|
963
972
|
|
|
@@ -30,6 +30,70 @@ def _tool_input_schema(tool: Any) -> Dict[str, Any]:
|
|
|
30
30
|
return schema or {}
|
|
31
31
|
|
|
32
32
|
|
|
33
|
+
def _normalize_property(prop: Any) -> Dict[str, Any]:
|
|
34
|
+
"""将单个 MCP 属性 schema 归一化为 Tina/大模型友好的形式。
|
|
35
|
+
|
|
36
|
+
修复原先只保留 `type` 且缺省退化为 Python 类型名 ``"str"`` 的问题:
|
|
37
|
+
- 缺少顶层 `type` 时,从 enum / anyOf 推断,最后回退为 JSON Schema 的
|
|
38
|
+
``"string"``,不再输出 ``"str"``;
|
|
39
|
+
- 保留 `enum` 等约束信息,避免模型失去取值范围;
|
|
40
|
+
- 将带 null 的 `anyOf`/`oneOf` 及 ``["string", "null"]`` 形式的 type
|
|
41
|
+
压平为 `type` + `nullable`,提升对不支持联合类型的模型兼容性。
|
|
42
|
+
"""
|
|
43
|
+
prop = dict(prop) if isinstance(prop, dict) else {}
|
|
44
|
+
description = prop.get("description", "")
|
|
45
|
+
|
|
46
|
+
# 压平 nullable 联合类型(例如 zod 的 z.enum([...]).nullable())
|
|
47
|
+
variants = prop.get("anyOf") or prop.get("oneOf")
|
|
48
|
+
if isinstance(variants, list):
|
|
49
|
+
non_null = [
|
|
50
|
+
v for v in variants if isinstance(v, dict) and v.get("type") != "null"
|
|
51
|
+
]
|
|
52
|
+
has_null = any(
|
|
53
|
+
isinstance(v, dict) and v.get("type") == "null" for v in variants
|
|
54
|
+
)
|
|
55
|
+
if len(non_null) == 1 and has_null:
|
|
56
|
+
merged = dict(non_null[0])
|
|
57
|
+
merged.setdefault("description", description)
|
|
58
|
+
merged["nullable"] = True
|
|
59
|
+
return _normalize_property(merged)
|
|
60
|
+
|
|
61
|
+
# 压平 type 为数组的形式,如 ["string", "null"]
|
|
62
|
+
raw_type = prop.get("type")
|
|
63
|
+
if isinstance(raw_type, list):
|
|
64
|
+
types = [t for t in raw_type if t != "null"]
|
|
65
|
+
prop["nullable"] = prop.get("nullable", "null" in raw_type)
|
|
66
|
+
if len(types) == 1:
|
|
67
|
+
prop["type"] = types[0]
|
|
68
|
+
else:
|
|
69
|
+
prop.pop("type", None)
|
|
70
|
+
|
|
71
|
+
# 缺少 type 时从 enum 推断,否则回退 "string"(而非 Python 的 "str")
|
|
72
|
+
if "type" not in prop:
|
|
73
|
+
values = prop.get("enum")
|
|
74
|
+
if isinstance(values, list) and values:
|
|
75
|
+
if all(isinstance(v, str) for v in values):
|
|
76
|
+
prop["type"] = "string"
|
|
77
|
+
elif all(
|
|
78
|
+
isinstance(v, (int, float)) and not isinstance(v, bool)
|
|
79
|
+
for v in values
|
|
80
|
+
):
|
|
81
|
+
prop["type"] = "number"
|
|
82
|
+
elif not (
|
|
83
|
+
prop.get("anyOf") or prop.get("oneOf") or prop.get("$ref")
|
|
84
|
+
):
|
|
85
|
+
prop["type"] = "string"
|
|
86
|
+
|
|
87
|
+
prop["description"] = description
|
|
88
|
+
return prop
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _convert_input_schema(schema: Dict[str, Any]) -> Dict[str, Any]:
|
|
92
|
+
"""将 MCP 工具的 input schema.properties 转为 Tina 工具参数格式"""
|
|
93
|
+
properties = schema.get("properties", {}) or {}
|
|
94
|
+
return {name: _normalize_property(prop) for name, prop in properties.items()}
|
|
95
|
+
|
|
96
|
+
|
|
33
97
|
class MCPClient:
|
|
34
98
|
def __init__(self):
|
|
35
99
|
if not MCP_AVAILABLE:
|
|
@@ -269,17 +333,10 @@ class MCPClient:
|
|
|
269
333
|
# 注意:Tina Tools 内部可能还会根据包名加一层前缀
|
|
270
334
|
# 这里的 register_no_function 保持你习惯的格式
|
|
271
335
|
schema = _tool_input_schema(tool)
|
|
272
|
-
properties = schema.get("properties", {}) or {}
|
|
273
336
|
tina_tools.register_no_function(
|
|
274
337
|
name=f"{sid}_{tool.name}", # 外部包名是mcp,内部就是 mcp_sid_name
|
|
275
338
|
description=f"[MCP:{sid}] {tool.description}",
|
|
276
|
-
parameters=
|
|
277
|
-
k: {
|
|
278
|
-
"type": v.get("type", "str"),
|
|
279
|
-
"description": v.get("description", ""),
|
|
280
|
-
}
|
|
281
|
-
for k, v in properties.items()
|
|
282
|
-
},
|
|
339
|
+
parameters=_convert_input_schema(schema),
|
|
283
340
|
required_parameters=schema.get("required", []) or [],
|
|
284
341
|
)
|
|
285
342
|
return tina_tools
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tina-python
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.6
|
|
4
4
|
Summary: tina is in your computer!
|
|
5
5
|
Home-page: https://gitee.com/wang-churi/tina
|
|
6
6
|
Author: 王出日
|
|
@@ -50,6 +50,12 @@ pip install tina-python
|
|
|
50
50
|
# 如果需要使用 MCP(模型上下文协议)服务
|
|
51
51
|
pip install tina-python[mcp]
|
|
52
52
|
|
|
53
|
+
# 如果需要 TUI 终端界面
|
|
54
|
+
pip install tina-python[tui]
|
|
55
|
+
|
|
56
|
+
# 一次装齐所有可选功能(TUI + MCP)
|
|
57
|
+
pip install tina-python[all]
|
|
58
|
+
|
|
53
59
|
# 如果需要运行测试
|
|
54
60
|
pip install tina-python[test]
|
|
55
61
|
```
|
|
@@ -211,8 +217,9 @@ result = await llm.apredict(
|
|
|
211
217
|
stream=False
|
|
212
218
|
)
|
|
213
219
|
|
|
214
|
-
#
|
|
215
|
-
|
|
220
|
+
# 异步流式:先 await 拿到异步生成器
|
|
221
|
+
result = await llm.apredict(input_text="讲个故事", stream=True)
|
|
222
|
+
async for chunk in result:
|
|
216
223
|
print(chunk["content"], end="")
|
|
217
224
|
```
|
|
218
225
|
|
|
@@ -242,8 +249,6 @@ async for chunk in llm.apredict(input_text="讲个故事", stream=True):
|
|
|
242
249
|
{
|
|
243
250
|
"role": "assistant",
|
|
244
251
|
"content": "回复内容",
|
|
245
|
-
# 推理模型时会出现
|
|
246
|
-
"reasoning_content": "推理链...",
|
|
247
252
|
# 有工具调用时会出现
|
|
248
253
|
"tool_calls": [
|
|
249
254
|
{
|
|
@@ -255,7 +260,8 @@ async for chunk in llm.apredict(input_text="讲个故事", stream=True):
|
|
|
255
260
|
]
|
|
256
261
|
}
|
|
257
262
|
|
|
258
|
-
#
|
|
263
|
+
# 流式:逐块返回片段,工具调用以 tool_name / tool_arguments 片段给出;
|
|
264
|
+
# 推理模型的思维链在 reasoning_content 中,末尾可能带有 usage
|
|
259
265
|
```
|
|
260
266
|
|
|
261
267
|
### 1.8 获取可用模型列表
|
|
@@ -392,9 +398,12 @@ tool_calls = [
|
|
|
392
398
|
}
|
|
393
399
|
}
|
|
394
400
|
]
|
|
395
|
-
|
|
401
|
+
# execute 需要事件对象(Agent 内部会自动传入)
|
|
402
|
+
from tina import AgentEvents
|
|
403
|
+
|
|
404
|
+
results = tools.execute(tool_calls, events=AgentEvents())
|
|
396
405
|
# [
|
|
397
|
-
# {"role": "tool", "tool_call_id": "call_123", "
|
|
406
|
+
# {"role": "tool", "tool_call_id": "call_123", "tool_name": "get_weather", "content": "北京今天天气晴朗"}
|
|
398
407
|
# ]
|
|
399
408
|
```
|
|
400
409
|
|
|
@@ -542,7 +551,7 @@ elif agent.state == AgentState.ERROR:
|
|
|
542
551
|
# 获取消息列表
|
|
543
552
|
messages = agent.get_messages()
|
|
544
553
|
|
|
545
|
-
#
|
|
554
|
+
# 清空全部消息(含系统提示词,之后需重新 set_system_prompt)
|
|
546
555
|
agent.clear_messages()
|
|
547
556
|
|
|
548
557
|
# 获取系统提示词
|
|
@@ -630,7 +639,7 @@ def on_turn_end():
|
|
|
630
639
|
agent_a = Agent(llm=llm, tools=tools, name="agent_a")
|
|
631
640
|
agent_b = Agent(llm=llm, tools=tools, name="agent_b")
|
|
632
641
|
|
|
633
|
-
#
|
|
642
|
+
# 关联另一个 Agent(记录到 other_agents,目前不会自动共享消息列表)
|
|
634
643
|
agent_a.connect_agent(agent_b)
|
|
635
644
|
|
|
636
645
|
# 断开连接
|
|
@@ -889,8 +898,8 @@ from tina import Agent, Tools
|
|
|
889
898
|
from tina.llm import BaseAPI
|
|
890
899
|
from tina.utils.system_tools import system_tools
|
|
891
900
|
|
|
892
|
-
tools = Tools()
|
|
893
|
-
tools += system_tools # 添加 tina
|
|
901
|
+
tools = Tools(name="my_tools")
|
|
902
|
+
tools += system_tools # 添加 tina 自带的系统工具包(工具集需命名)
|
|
894
903
|
|
|
895
904
|
agent = Agent(
|
|
896
905
|
llm=BaseAPI(),
|
|
@@ -992,7 +1001,7 @@ run_agent_in_cli(agent)
|
|
|
992
1001
|
|------|------|
|
|
993
1002
|
| `#context` | 查看当前对话上下文(消息列表) |
|
|
994
1003
|
| `#clear` | 清屏 |
|
|
995
|
-
|
|
|
1004
|
+
| `exit` / `quit` | 退出对话(`#exit` 不支持,会被当作普通输入) |
|
|
996
1005
|
|
|
997
1006
|
### 6.4 多模态消息构建器 `build_multimodal_message`
|
|
998
1007
|
|
|
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
|