LightAgent 0.2.8__tar.gz → 0.2.85__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.
- {lightagent-0.2.8 → lightagent-0.2.85}/LightAgent/la_core.py +39 -20
- {lightagent-0.2.8 → lightagent-0.2.85}/PKG-INFO +5 -1
- {lightagent-0.2.8 → lightagent-0.2.85}/README.md +2 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/README.zh-CN.md +2 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/pyproject.toml +1 -1
- {lightagent-0.2.8 → lightagent-0.2.85}/LICENSE +0 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/LightAgent/__init__.py +0 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/README.de.md +0 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/README.es.md +0 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/README.fr.md +0 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/README.ja.md +0 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/README.ko.md +0 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/README.pt.md +0 -0
- {lightagent-0.2.8 → lightagent-0.2.85}/README.ru.md +0 -0
|
@@ -11,6 +11,7 @@ import logging
|
|
|
11
11
|
import os
|
|
12
12
|
import httpx
|
|
13
13
|
import importlib
|
|
14
|
+
from openai.types.chat import ChatCompletionChunk
|
|
14
15
|
|
|
15
16
|
# 全局工具注册表
|
|
16
17
|
_FUNCTION_MAPPINGS = {} # 工具名称 -> 工具函数
|
|
@@ -18,7 +19,7 @@ _FUNCTION_INFO = {} # 工具名称 -> 工具info信息
|
|
|
18
19
|
_OPENAI_FUNCTION_SCHEMAS = [] # OpenAI 格式的工具描述
|
|
19
20
|
_PROMPT_FUNCTION_SCHEMAS = [] # prompt 格式的工具描述
|
|
20
21
|
|
|
21
|
-
__version__ = "0.2.
|
|
22
|
+
__version__ = "0.2.85" # 你可以根据需要设置版本号
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
def register_tool_manually(tools: List[Union[str, Callable]]) -> bool:
|
|
@@ -154,7 +155,7 @@ def get_tools_str() -> str:
|
|
|
154
155
|
|
|
155
156
|
|
|
156
157
|
class LightAgent:
|
|
157
|
-
__version__ = "0.2.
|
|
158
|
+
__version__ = "0.2.85" # 将版本号放在类中
|
|
158
159
|
|
|
159
160
|
def __init__(
|
|
160
161
|
self,
|
|
@@ -478,15 +479,19 @@ class LightAgent:
|
|
|
478
479
|
output = ""
|
|
479
480
|
function_call_name = ""
|
|
480
481
|
tool_calls = response.choices[0].message.tool_calls
|
|
481
|
-
self.log("DEBUG", "tool_calls", {"tool_calls": tool_calls})
|
|
482
|
+
self.log("DEBUG", "non_stream tool_calls", {"tool_calls": tool_calls})
|
|
482
483
|
|
|
483
484
|
# 遍历所有工具调用
|
|
484
485
|
for tool_call in tool_calls:
|
|
485
486
|
function_call = tool_call.function
|
|
486
|
-
self.log("DEBUG", "function_call", {"function_call": function_call.model_dump()})
|
|
487
487
|
|
|
488
|
+
# 尝试自动修复常见转义问题
|
|
489
|
+
fixed_args = function_call.arguments.replace('\\"', '"').replace('\\\\', '\\')
|
|
490
|
+
self.log("DEBUG", "non_stream function_call", {"function_call": fixed_args})
|
|
491
|
+
|
|
492
|
+
function_args = json.loads(fixed_args)
|
|
488
493
|
# 解析函数参数
|
|
489
|
-
function_args = json.loads(function_call.arguments)
|
|
494
|
+
# function_args = json.loads(function_call.arguments)
|
|
490
495
|
|
|
491
496
|
# 调用工具并获取响应
|
|
492
497
|
tool_response = dispatch_tool(function_call.name, function_args)
|
|
@@ -495,7 +500,7 @@ class LightAgent:
|
|
|
495
500
|
|
|
496
501
|
# 如果工具返回的是生成器(流式输出),则将所有 chunk 叠加
|
|
497
502
|
if isinstance(tool_response, Generator):
|
|
498
|
-
|
|
503
|
+
print(f"Streaming response from tool: {function_call.name}")
|
|
499
504
|
for chunk in tool_response:
|
|
500
505
|
# print("Received chunk:", chunk) # 打印每个 chunk
|
|
501
506
|
if function_call_name == 'finish':
|
|
@@ -520,16 +525,18 @@ class LightAgent:
|
|
|
520
525
|
else:
|
|
521
526
|
# print(f"Non-streaming response from tool: {function_call.name}")
|
|
522
527
|
combined_response = tool_response
|
|
528
|
+
# print("tool_response type:",type(combined_response))
|
|
523
529
|
# 如果是 JSON 字符串,解析并转换为中文
|
|
524
530
|
if isinstance(combined_response, str):
|
|
525
531
|
try:
|
|
526
532
|
combined_response = json.loads(combined_response) # 解析 JSON
|
|
527
533
|
combined_response = json.dumps(combined_response, ensure_ascii=False) # 转换为中文
|
|
528
534
|
except json.JSONDecodeError:
|
|
535
|
+
combined_response = tool_response
|
|
529
536
|
pass # 如果不是 JSON 字符串,保持原样
|
|
530
537
|
tool_responses.append(combined_response) # 直接添加普通响应
|
|
531
538
|
|
|
532
|
-
self.log("INFO", "tool_response", {"tool_response": combined_response})
|
|
539
|
+
self.log("INFO", "non_stream tool_response", {"tool_response": combined_response})
|
|
533
540
|
|
|
534
541
|
# 将工具调用的结果添加到列表中
|
|
535
542
|
tool_responses.append(combined_response)
|
|
@@ -560,8 +567,13 @@ class LightAgent:
|
|
|
560
567
|
# 更新响应
|
|
561
568
|
if function_call_name == 'finish':
|
|
562
569
|
return # 如果最后调用了finish工具,则结束生成器
|
|
563
|
-
# print(params)
|
|
564
|
-
|
|
570
|
+
# print("params:",params)
|
|
571
|
+
self.log("DEBUG", "chat-completions params", {"params": params})
|
|
572
|
+
|
|
573
|
+
try:
|
|
574
|
+
response = self.client.chat.completions.create(**params)
|
|
575
|
+
except Exception as e:
|
|
576
|
+
print(f"An error occurred: {e}")
|
|
565
577
|
|
|
566
578
|
# 重试次数用尽
|
|
567
579
|
self.log("ERROR", "max_retry_reached", {"message": "Failed to generate a valid response."})
|
|
@@ -653,14 +665,17 @@ class LightAgent:
|
|
|
653
665
|
combined_response = ""
|
|
654
666
|
for chunk in tool_response:
|
|
655
667
|
# 将工具返回的数据继续流出
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
668
|
+
if isinstance(chunk, ChatCompletionChunk):
|
|
669
|
+
yield chunk
|
|
670
|
+
else:
|
|
671
|
+
tool_output = {
|
|
672
|
+
"name": tool_call["name"],
|
|
673
|
+
"title": _FUNCTION_INFO.get(tool_call["name"], {}).get(
|
|
674
|
+
'tool_title') or '',
|
|
675
|
+
"output": chunk,
|
|
676
|
+
}
|
|
677
|
+
self.log("INFO", "tool_call", {"tool_output": tool_output})
|
|
678
|
+
yield tool_output
|
|
664
679
|
# 将工具的调用信息推送给开发者
|
|
665
680
|
if function_call_name == 'finish':
|
|
666
681
|
content = chunk.choices[0].delta.content or ""
|
|
@@ -669,8 +684,11 @@ class LightAgent:
|
|
|
669
684
|
combined_response += chunk # 将每个 chunk 叠加
|
|
670
685
|
tool_responses.append(combined_response) # 将叠加后的完整响应添加到列表
|
|
671
686
|
else:
|
|
672
|
-
# print(f"Non-streaming response from tool: {
|
|
673
|
-
|
|
687
|
+
# print(f"Non-streaming response from tool: {tool_response}")
|
|
688
|
+
combined_response = tool_response
|
|
689
|
+
tool_responses.append(combined_response) # 直接添加普通响应
|
|
690
|
+
self.log("INFO", "stream tool_response", {"tool_response": combined_response})
|
|
691
|
+
|
|
674
692
|
|
|
675
693
|
except json.JSONDecodeError as e:
|
|
676
694
|
self.log("ERROR", "json_decode_error",
|
|
@@ -702,6 +720,7 @@ class LightAgent:
|
|
|
702
720
|
# 更新响应
|
|
703
721
|
if function_call_name == 'finish':
|
|
704
722
|
return # 如果最后调用了finish工具,则结束生成器
|
|
723
|
+
self.log("DEBUG", "chat-completions params", {"params": params})
|
|
705
724
|
response = self.client.chat.completions.create(**params)
|
|
706
725
|
|
|
707
726
|
# 重试次数用尽
|
|
@@ -1087,4 +1106,4 @@ class LightSwarm:
|
|
|
1087
1106
|
if __name__ == "__main__":
|
|
1088
1107
|
# Example of registering and using a tool
|
|
1089
1108
|
print("This is LightAgent")
|
|
1090
|
-
# print(dispatch_tool("example_tool", {"param1": "test"}))
|
|
1109
|
+
# print(dispatch_tool("example_tool", {"param1": "test"}))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: LightAgent
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.85
|
|
4
4
|
Summary: **LightAgent** is an extremely lightweight active Agentic Framework with memory (`mem0`), tools (`Tools`), and a Tree of Thought (`ToT`). It supports swarm-like multi-agent collaboration, automated tool generation, and agent assessment, with underlying model support for OpenAI, Zhipu ChatGLM, Baichuan Large Model, DeepSeek R1, Qwen series large models, and more. At the same time, LightAgent supports OpenAI streaming format API service output, seamlessly integrating with major mainstream chat frameworks. 🌟
|
|
5
5
|
Home-page: https://github.com/wxai-space/LightAgent
|
|
6
6
|
License: Apache 2.0
|
|
@@ -356,6 +356,7 @@ def get_weather(
|
|
|
356
356
|
# Define tool information inside the function
|
|
357
357
|
get_weather.tool_info = {
|
|
358
358
|
"tool_name": "get_weather",
|
|
359
|
+
"tool_title": "get weather",
|
|
359
360
|
"tool_description": "Get current weather information for the specified city.",
|
|
360
361
|
"tool_params": [
|
|
361
362
|
{"name": "city_name", "description": "The name of the city to query", "type": "string", "required": True},
|
|
@@ -378,6 +379,7 @@ def search_news(
|
|
|
378
379
|
# Define tool information inside the function
|
|
379
380
|
search_news.tool_info = {
|
|
380
381
|
"tool_name": "search_news",
|
|
382
|
+
"tool_title": "search news",
|
|
381
383
|
"tool_description": "Search news based on keywords.",
|
|
382
384
|
"tool_params": [
|
|
383
385
|
{"name": "keyword", "description": "Search keyword", "type": "string", "required": True},
|
|
@@ -1077,6 +1079,7 @@ def get_weather(
|
|
|
1077
1079
|
# 在函数内部定义工具信息
|
|
1078
1080
|
get_weather.tool_info = {
|
|
1079
1081
|
"tool_name": "get_weather",
|
|
1082
|
+
"tool_name": "获取天气",
|
|
1080
1083
|
"tool_description": "获取指定城市的当前天气信息",
|
|
1081
1084
|
"tool_params": [
|
|
1082
1085
|
{"name": "city_name", "description": "要查询的城市名称", "type": "string", "required": True},
|
|
@@ -1099,6 +1102,7 @@ def search_news(
|
|
|
1099
1102
|
# 在函数内部定义工具信息
|
|
1100
1103
|
search_news.tool_info = {
|
|
1101
1104
|
"tool_name": "search_news",
|
|
1105
|
+
"tool_name": "联网搜索",
|
|
1102
1106
|
"tool_description": "根据关键词搜索新闻",
|
|
1103
1107
|
"tool_params": [
|
|
1104
1108
|
{"name": "keyword", "description": "搜索关键词", "type": "string", "required": True},
|
|
@@ -335,6 +335,7 @@ def get_weather(
|
|
|
335
335
|
# Define tool information inside the function
|
|
336
336
|
get_weather.tool_info = {
|
|
337
337
|
"tool_name": "get_weather",
|
|
338
|
+
"tool_title": "get weather",
|
|
338
339
|
"tool_description": "Get current weather information for the specified city.",
|
|
339
340
|
"tool_params": [
|
|
340
341
|
{"name": "city_name", "description": "The name of the city to query", "type": "string", "required": True},
|
|
@@ -357,6 +358,7 @@ def search_news(
|
|
|
357
358
|
# Define tool information inside the function
|
|
358
359
|
search_news.tool_info = {
|
|
359
360
|
"tool_name": "search_news",
|
|
361
|
+
"tool_title": "search news",
|
|
360
362
|
"tool_description": "Search news based on keywords.",
|
|
361
363
|
"tool_params": [
|
|
362
364
|
{"name": "keyword", "description": "Search keyword", "type": "string", "required": True},
|
|
@@ -339,6 +339,7 @@ def get_weather(
|
|
|
339
339
|
# 在函数内部定义工具信息
|
|
340
340
|
get_weather.tool_info = {
|
|
341
341
|
"tool_name": "get_weather",
|
|
342
|
+
"tool_name": "获取天气",
|
|
342
343
|
"tool_description": "获取指定城市的当前天气信息",
|
|
343
344
|
"tool_params": [
|
|
344
345
|
{"name": "city_name", "description": "要查询的城市名称", "type": "string", "required": True},
|
|
@@ -361,6 +362,7 @@ def search_news(
|
|
|
361
362
|
# 在函数内部定义工具信息
|
|
362
363
|
search_news.tool_info = {
|
|
363
364
|
"tool_name": "search_news",
|
|
365
|
+
"tool_name": "联网搜索",
|
|
364
366
|
"tool_description": "根据关键词搜索新闻",
|
|
365
367
|
"tool_params": [
|
|
366
368
|
{"name": "keyword", "description": "搜索关键词", "type": "string", "required": True},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "LightAgent"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.85"
|
|
4
4
|
description = "**LightAgent** is an extremely lightweight active Agentic Framework with memory (`mem0`), tools (`Tools`), and a Tree of Thought (`ToT`). It supports swarm-like multi-agent collaboration, automated tool generation, and agent assessment, with underlying model support for OpenAI, Zhipu ChatGLM, Baichuan Large Model, DeepSeek R1, Qwen series large models, and more. At the same time, LightAgent supports OpenAI streaming format API service output, seamlessly integrating with major mainstream chat frameworks. 🌟"
|
|
5
5
|
authors = ["caiweige <caiweige@qq.com>"]
|
|
6
6
|
license = "Apache 2.0"
|
|
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
|