LightAgent 0.2.6__tar.gz → 0.2.9__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.
@@ -11,13 +11,16 @@ import logging
11
11
  import os
12
12
  import httpx
13
13
  import importlib
14
+ from openai.types.chat import ChatCompletionChunk
15
+ import asyncio
14
16
 
15
17
  # 全局工具注册表
16
18
  _FUNCTION_MAPPINGS = {} # 工具名称 -> 工具函数
19
+ _FUNCTION_INFO = {} # 工具名称 -> 工具info信息
17
20
  _OPENAI_FUNCTION_SCHEMAS = [] # OpenAI 格式的工具描述
18
21
  _PROMPT_FUNCTION_SCHEMAS = [] # prompt 格式的工具描述
19
22
 
20
- __version__ = "0.2.1" # 你可以根据需要设置版本号
23
+ __version__ = "0.2.9" # 你可以根据需要设置版本号
21
24
 
22
25
 
23
26
  def register_tool_manually(tools: List[Union[str, Callable]]) -> bool:
@@ -32,6 +35,9 @@ def register_tool_manually(tools: List[Union[str, Callable]]) -> bool:
32
35
 
33
36
  tool_info = func.tool_info
34
37
  tool_name = tool_info["tool_name"]
38
+
39
+ # 注册到全局字典
40
+ _FUNCTION_INFO[tool_name] = tool_info
35
41
  _FUNCTION_MAPPINGS[tool_name] = func # 注册工具
36
42
 
37
43
  # 构建 OpenAI 格式的工具描述
@@ -82,36 +88,41 @@ def load_tool(tool_name: str, tools_directory: str = "tools"):
82
88
  return tool_func
83
89
  raise AttributeError(f"Tool '{tool_name}' is not properly defined in {tool_path}")
84
90
 
91
+ from typing import Dict, Any, Union, Generator, AsyncGenerator
92
+ import inspect
93
+ import traceback
85
94
 
86
- def dispatch_tool(tool_name: str, tool_params: Dict[str, Any]) -> Union[str, Generator[str, None, None]]:
95
+ async def dispatch_tool(tool_name: str, tool_params: Dict[str, Any]) -> Union[str, Generator[str, None, None], AsyncGenerator[str, None]]:
87
96
  """
88
- 调用工具执行,支持流式输出。
89
-
90
- :param tool_name: 工具名称
91
- :param tool_params: 工具参数
92
- :return: 如果工具是流式输出,返回生成器;否则返回字符串结果。
97
+ 调用工具执行,支持同步/异步工具及流式输出。
93
98
  """
94
99
  if tool_name not in _FUNCTION_MAPPINGS:
95
100
  return f"Tool `{tool_name}` not found."
96
101
 
97
102
  tool_call = _FUNCTION_MAPPINGS[tool_name]
98
103
  try:
99
- # print(f"Calling tool: {tool_name} with params: {tool_params}") # 调试信息
100
- result = tool_call(**tool_params)
104
+ # 区分同步/异步工具
105
+ if inspect.iscoroutinefunction(tool_call):
106
+ result = await tool_call(**tool_params)
107
+ else:
108
+ result = tool_call(**tool_params)
101
109
 
102
- # 如果工具返回的是可迭代对象(如生成器),则逐块处理并返回生成器
103
- if isinstance(result, Iterable) and not isinstance(result, (str, bytes)):
110
+ # 处理不同类型的流式输出
111
+ if inspect.isasyncgen(result):
112
+ return async_stream_generator(result)
113
+ elif inspect.isgenerator(result):
104
114
  return stream_generator(result)
105
- # 否则,返回字符串结果
106
115
  else:
107
116
  return str(result)
108
117
  except Exception as e:
109
- # print(f"Tool call failed: {e}") # 调试信息
110
118
  return traceback.format_exc()
111
119
 
120
+ async def async_stream_generator(async_gen: AsyncGenerator) -> AsyncGenerator[str, None]:
121
+ async for chunk in async_gen:
122
+ yield chunk
112
123
 
113
- def stream_generator(result):
114
- for chunk in result:
124
+ def stream_generator(sync_gen: Generator) -> Generator[str, None, None]:
125
+ for chunk in sync_gen:
115
126
  yield chunk
116
127
 
117
128
 
@@ -150,7 +161,7 @@ def get_tools_str() -> str:
150
161
 
151
162
 
152
163
  class LightAgent:
153
- __version__ = "0.2.1" # 将版本号放在类中
164
+ __version__ = "0.2.9" # 将版本号放在类中
154
165
 
155
166
  def __init__(
156
167
  self,
@@ -159,11 +170,14 @@ class LightAgent:
159
170
  instructions: Optional[str] = None, # 代理指令
160
171
  role: Optional[str] = None,
161
172
  model: str,
162
- api_key: str,
173
+ api_key: str | None = None,
163
174
  base_url: str | httpx.URL | None = None,
164
175
  websocket_base_url: str | httpx.URL | None = None,
165
176
  memory=None, # 支持外部传入记忆模块
166
177
  tree_of_thought: bool = False, # 是否启用链式思考
178
+ tot_model: str | None = None,
179
+ tot_api_key: str | None = None,
180
+ tot_base_url: str | httpx.URL | None = None,
167
181
  self_learning: bool = False, # 是否启用agent自我学习
168
182
  tools: List[Union[str, Callable]] = None, # 支持混合输入
169
183
  debug: bool = False, # 是否启用调试模式
@@ -182,6 +196,9 @@ class LightAgent:
182
196
  :param websocket_base_url: WebSocket 的基础 URL。
183
197
  :param memory: 外部传入的记忆模块,需实现 `retrieve` 和 `store` 方法。
184
198
  :param tree_of_thought: 是否启用思维链功能。
199
+ :param tot_model: 使用的模型名称。
200
+ :param tot_api_key: API 密钥。
201
+ :param tot_base_url: API 的基础 URL。
185
202
  :param tools: 工具列表,支持函数名称(字符串)或函数对象。
186
203
  :param debug: 是否启用调试模式。
187
204
  :param log_level: 日志级别(INFO, DEBUG, ERROR)。
@@ -236,9 +253,21 @@ class LightAgent:
236
253
  base_url = f"https://api.openai.com/v1"
237
254
 
238
255
  self.client = OpenAI(
239
- base_url=base_url,
240
- api_key=self.api_key
256
+ base_url = base_url,
257
+ api_key = self.api_key
241
258
  )
259
+ if self.tree_of_thought:
260
+ if tot_api_key is None:
261
+ tot_api_key = api_key
262
+ if tot_base_url is None:
263
+ tot_base_url = base_url
264
+ if not tot_model:
265
+ tot_model = "deepseek-r1" # 默认思维推理模型为deepseek-r1
266
+ self.tot_model = tot_model
267
+ self.tot_client = OpenAI(
268
+ base_url = tot_base_url,
269
+ api_key = tot_api_key
270
+ )
242
271
 
243
272
  def get_tool(self, tool_name: str) -> Callable:
244
273
  """
@@ -272,6 +301,7 @@ class LightAgent:
272
301
  # 注册工具函数
273
302
  if hasattr(tool_func, "tool_info"):
274
303
  tool_info = tool_func.tool_info
304
+ _FUNCTION_INFO[tool_name] = tool_info # 注册工具info信息
275
305
  _FUNCTION_MAPPINGS[tool_name] = tool_func
276
306
 
277
307
  # 构建 OpenAI 格式的工具描述
@@ -358,7 +388,7 @@ class LightAgent:
358
388
  query: str,
359
389
  light_swarm=None,
360
390
  stream: bool = False,
361
- max_retry: int = 5,
391
+ max_retry: int = 10,
362
392
  user_id: str = "default_user",
363
393
  history: list = None,
364
394
  metadata: Optional[Dict] = None,
@@ -398,7 +428,6 @@ class LightAgent:
398
428
  return result
399
429
 
400
430
  # 2. 正常处理任务
401
-
402
431
  now = datetime.now()
403
432
  current_date = now.strftime("%Y-%m-%d")
404
433
  current_time = now.strftime("%H:%M:%S")
@@ -456,20 +485,25 @@ class LightAgent:
456
485
  output = ""
457
486
  function_call_name = ""
458
487
  tool_calls = response.choices[0].message.tool_calls
459
- self.log("DEBUG", "tool_calls", {"tool_calls": tool_calls})
488
+ self.log("DEBUG", "non_stream tool_calls", {"tool_calls": tool_calls})
460
489
 
461
490
  # 遍历所有工具调用
462
491
  for tool_call in tool_calls:
463
492
  function_call = tool_call.function
464
- self.log("DEBUG", "function_call", {"function_call": function_call.model_dump()})
465
493
 
494
+ # 尝试自动修复常见转义问题
495
+ fixed_args = function_call.arguments.replace('\\"', '"').replace('\\\\', '\\')
496
+ self.log("DEBUG", "non_stream function_call", {"function_call": fixed_args})
497
+
498
+ function_args = json.loads(fixed_args)
466
499
  # 解析函数参数
467
- function_args = json.loads(function_call.arguments)
500
+ # function_args = json.loads(function_call.arguments)
468
501
 
469
502
  # 调用工具并获取响应
470
- tool_response = dispatch_tool(function_call.name, function_args)
503
+ tool_response = asyncio.run(dispatch_tool(function_call.name, function_args))
471
504
  function_call_name = function_call.name
472
505
  combined_response = ""
506
+ single_tool_response = ""
473
507
 
474
508
  # 如果工具返回的是生成器(流式输出),则将所有 chunk 叠加
475
509
  if isinstance(tool_response, Generator):
@@ -483,26 +517,48 @@ class LightAgent:
483
517
  combined_response += chunk # 将每个 chunk 叠加
484
518
  if combined_response == "":
485
519
  combined_response = "".join(tool_response)
486
- tool_responses.append(combined_response) # 将叠加后的完整响应添加到列表
520
+
521
+ # 将 combined_response 解析为 JSON 对象(如果它是 JSON 字符串)
522
+ try:
523
+ combined_response = json.loads(combined_response) # 解析 JSON
524
+ except json.JSONDecodeError:
525
+ pass # 如果不是 JSON 字符串,保持原样
526
+
527
+ # 将 JSON 对象中的 Unicode 编码转换为中文字符
528
+ if isinstance(combined_response, dict):
529
+ combined_response = json.dumps(combined_response, ensure_ascii=False) # 确保中文字符不转义
530
+ single_tool_response = combined_response # 处理单个工具的方法
531
+
487
532
  else:
488
533
  # print(f"Non-streaming response from tool: {function_call.name}")
489
534
  combined_response = tool_response
490
- tool_responses.append(combined_response) # 直接添加普通响应
535
+ # print("tool_response type:",type(combined_response))
536
+ # 如果是 JSON 字符串,解析并转换为中文
537
+ if isinstance(combined_response, str):
538
+ try:
539
+ combined_response = json.loads(combined_response) # 解析 JSON
540
+ combined_response = json.dumps(combined_response, ensure_ascii=False) # 转换为中文
541
+ except json.JSONDecodeError:
542
+ combined_response = tool_response
543
+ pass # 如果不是 JSON 字符串,保持原样
544
+ single_tool_response = combined_response # 处理单个工具的方法
491
545
 
492
- self.log("INFO", "tool_response", {"tool_response": combined_response})
493
546
 
494
- # 将工具调用的结果添加到列表中
495
- tool_responses.append(combined_response)
547
+ self.log("DEBUG", "non_stream single_tool_response", {"single_tool_response": single_tool_response})
548
+
549
+ # 将单个工具的响应结果添加到列表中
550
+ tool_responses.append(single_tool_response)
496
551
 
497
552
  # 将所有工具调用的结果合并为一个字符串
553
+ self.log("DEBUG", "non_stream tool_responses", {"tool_responses": tool_responses})
554
+
498
555
  combined_tool_response = "\n".join(tool_responses)
499
556
 
500
557
  # 将工具调用和响应添加到消息列表中
501
558
  params["messages"].append(
502
559
  {
503
560
  "role": "assistant",
504
- "content": json.dumps(
505
- [tool_call.function.model_dump() for tool_call in tool_calls]),
561
+ "content": f"使用工具: \n {json.dumps([tool_call.function.model_dump() for tool_call in tool_calls],ensure_ascii=False)}\n",
506
562
  }
507
563
  )
508
564
  params["messages"].append(
@@ -520,7 +576,13 @@ class LightAgent:
520
576
  # 更新响应
521
577
  if function_call_name == 'finish':
522
578
  return # 如果最后调用了finish工具,则结束生成器
523
- response = self.client.chat.completions.create(**params)
579
+ # print("params:",params)
580
+ self.log("DEBUG", "chat-completions params", {"params": params})
581
+
582
+ try:
583
+ response = self.client.chat.completions.create(**params)
584
+ except Exception as e:
585
+ print(f"An error occurred: {e}")
524
586
 
525
587
  # 重试次数用尽
526
588
  self.log("ERROR", "max_retry_reached", {"message": "Failed to generate a valid response."})
@@ -583,6 +645,7 @@ class LightAgent:
583
645
  if tool_call["name"]: # 确保工具调用有名称
584
646
  function_call = {
585
647
  "name": tool_call["name"],
648
+ "title": _FUNCTION_INFO.get(tool_call["name"], {}).get('tool_title') or '',
586
649
  "arguments": tool_call["arguments"],
587
650
  }
588
651
  self.log("INFO", "tool_call", {"function_call": function_call})
@@ -602,24 +665,42 @@ class LightAgent:
602
665
 
603
666
  for json_obj in json_objects:
604
667
  function_args = json.loads(json_obj)
605
- tool_response = dispatch_tool(function_call["name"], function_args)
668
+ # tool_response = dispatch_tool(function_call["name"], function_args)
669
+ tool_response = asyncio.run(dispatch_tool(function_call["name"], function_args))
606
670
  function_call_name = function_call["name"]
671
+ combined_response = ""
672
+ single_tool_response = ""
607
673
 
608
674
  # 如果工具返回的是生成器(流式输出),则将所有 chunk 叠加
609
675
  if isinstance(tool_response, Generator):
610
676
  # print(f"Streaming response from tool: {function_call['name']}")
611
- combined_response = ""
612
677
  for chunk in tool_response:
613
- yield chunk
678
+ # 将工具返回的数据继续流出
679
+ if isinstance(chunk, ChatCompletionChunk):
680
+ yield chunk
681
+ else:
682
+ tool_output = {
683
+ "name": tool_call["name"],
684
+ "title": _FUNCTION_INFO.get(tool_call["name"], {}).get(
685
+ 'tool_title') or '',
686
+ "output": chunk,
687
+ }
688
+ self.log("INFO", "tool_call", {"tool_output": tool_output})
689
+ yield tool_output
690
+ # 将工具的调用信息推送给开发者
614
691
  if function_call_name == 'finish':
615
692
  content = chunk.choices[0].delta.content or ""
616
693
  combined_response += content # 将每个 chunk 叠加
617
694
  else:
618
695
  combined_response += chunk # 将每个 chunk 叠加
619
- tool_responses.append(combined_response) # 将叠加后的完整响应添加到列表
696
+ single_tool_response = combined_response # 处理单个工具的方法
620
697
  else:
621
- # print(f"Non-streaming response from tool: {function_call['name']}")
622
- tool_responses.append(tool_response) # 直接添加普通响应
698
+ # print(f"Non-streaming response from tool: {tool_response}")
699
+ combined_response = tool_response
700
+ single_tool_response = combined_response # 处理单个工具的方法
701
+ self.log("INFO", "stream single_tool_response", {"single_tool_response": single_tool_response})
702
+ # 将单个工具的响应结果添加到列表中
703
+ tool_responses.append(single_tool_response)
623
704
 
624
705
  except json.JSONDecodeError as e:
625
706
  self.log("ERROR", "json_decode_error",
@@ -651,6 +732,7 @@ class LightAgent:
651
732
  # 更新响应
652
733
  if function_call_name == 'finish':
653
734
  return # 如果最后调用了finish工具,则结束生成器
735
+ self.log("DEBUG", "chat-completions params", {"params": params})
654
736
  response = self.client.chat.completions.create(**params)
655
737
 
656
738
  # 重试次数用尽
@@ -788,18 +870,21 @@ class LightAgent:
788
870
 
789
871
  def run_thought(self, query: str, stream=False, tools=None):
790
872
  """使用思维树的方式 让大模型先根据get_tools_str生成一个解答用户query的工具使用计划"""
791
- tot_model = "deepseek-chat" # self.model
873
+ tot_model = self.tot_model # self.model
792
874
  tools = get_tools_str()
793
875
  if not isinstance(tools, str):
794
876
  tools = str(tools) # 确保 tools 是字符串
795
- system_prompt = f"""你是一个智能助手,请根据用户输入的问题,结合工具使用计划,生成一个思维树,并按照思维树依次调用工具步骤,最终生成一个最终回答。/n 工具列表: {tools}"""
877
+ now = datetime.now()
878
+ current_date = now.strftime("%Y-%m-%d")
879
+ current_time = now.strftime("%H:%M:%S")
880
+ system_prompt = f"""你是一个智能助手,请根据用户输入的问题,结合工具使用计划,生成一个思维树,并按照思维树依次调用工具步骤,最终生成一个最终回答。/n 今日的日期: {current_date} 当前时间: {current_time} /n 工具列表: {tools}"""
796
881
  self.log("DEBUG", "run_thought", {"system_prompt": system_prompt})
797
882
 
798
883
  # 第一次请求,生成初始的工具使用计划
799
884
  params = dict(model=tot_model,
800
885
  messages=[{"role": "system", "content": system_prompt}, {"role": "user", "content": query}],
801
886
  stream=False)
802
- response = self.client.chat.completions.create(**params)
887
+ response = self.tot_client.chat.completions.create(**params)
803
888
  initial_content = response.choices[0].message.content
804
889
  self.log("DEBUG", "initial_response", {"response": initial_content})
805
890
 
@@ -812,7 +897,7 @@ class LightAgent:
812
897
  ], stream=False)
813
898
  self.log("DEBUG", "reflection_params", {"params": reflection_params})
814
899
 
815
- reflection_response = self.client.chat.completions.create(**reflection_params)
900
+ reflection_response = self.tot_client.chat.completions.create(**reflection_params)
816
901
  refined_content = reflection_response.choices[0].message.content
817
902
  self.log("DEBUG", "refined_response", {"response": refined_content})
818
903
  return refined_content
@@ -951,6 +1036,7 @@ class LightAgent:
951
1036
  # 在函数内部定义工具信息
952
1037
  get_weather.tool_info = {
953
1038
  "tool_name": "get_weather",
1039
+ "tool_title": "天气查询",
954
1040
  "tool_description": "获取指定城市的当前天气信息",
955
1041
  "tool_params": [
956
1042
  {"name": "city_name", "description": "要查询的城市名称", "type": "string", "required": True},
@@ -1033,4 +1119,4 @@ class LightSwarm:
1033
1119
  if __name__ == "__main__":
1034
1120
  # Example of registering and using a tool
1035
1121
  print("This is LightAgent")
1036
- # print(dispatch_tool("example_tool", {"param1": "test"}))
1122
+ # print(dispatch_tool("example_tool", {"param1": "test"}))
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LightAgent
3
- Version: 0.2.6
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, 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. 🌟
3
+ Version: 0.2.9
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
7
7
  Author: caiweige
@@ -54,10 +54,12 @@ Description-Content-Type: text/markdown
54
54
  <h1>LightAgent🚀 (Next Generation Agentic AI Framework)</h1>
55
55
  </div>
56
56
 
57
- **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, 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. 🌟
57
+ **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, Qwen, stepfun and more. At the same time, LightAgent supports OpenAI streaming format API service output, seamlessly integrating with major mainstream chat frameworks. 🌟
58
58
 
59
59
  ---
60
60
 
61
+ ![lightswarm_demo_en.png](docs%2Fimages%2Flightswarm_demo_en.png)
62
+
61
63
  ## ✨ Features
62
64
 
63
65
  - **Lightweight and Efficient** 🚀: Minimalist design, quick deployment, suitable for various application scenarios. (No LangChain, No LlamaIndex) 100% Python implementation, no additional dependencies, core code is only 1000 lines, fully open source.
@@ -72,6 +74,15 @@ Description-Content-Type: text/markdown
72
74
  - **Tool Generator** 🚀: Just provide your API documentation to the [Tool Generator], which will automatically create exclusive tools for you, allowing you to quickly build hundreds of personalized custom tools in just 1 hour to improve efficiency and unleash your creative potential.
73
75
  - **Agent Self-Learning** 🧠️: Each agent has its own scene memory capabilities and the ability to self-learn from user conversations.
74
76
 
77
+ ---
78
+ ## News
79
+ - <img src="https://img.alicdn.com/imgextra/i3/O1CN01SFL0Gu26nrQBFKXFR_!!6000000007707-2-tps-500-500.png" alt="new" width="30" height="30"/>**[2025-02-19]** LightAgent v0.2.7 supports deepseek-r1 model for tot now.Significantly enhances the multi-tool planning capability for complex tasks.
80
+ - **[2025-02-06]** LightAgent version 0.2.5 is released now.
81
+ - **[2025-01-20]** LightAgent version 0.2.0 is released now.
82
+ - **[2025-01-05]** LightAgent version 0.1.0 is released now.
83
+
84
+ ---
85
+
75
86
  ## 🚧 Coming Soon
76
87
 
77
88
  - **Adaptive Tool Mechanism** 🛠️: Supports adding an unlimited number of tools, allowing the large model to first select a candidate tool set from thousands of tools, filtering irrelevant tools before submitting context to the large model, significantly reducing token consumption.
@@ -79,6 +90,7 @@ Description-Content-Type: text/markdown
79
90
  - **Agent Assessment** 📊: Built-in agent assessment tool for conveniently evaluating and optimizing the agents you build, aligning with business scenarios, and continuously improving intelligence levels.
80
91
 
81
92
  ## Built-in "Thought Flow"
93
+ ### ToT now supports DeepSeek-R1.
82
94
  The Thought Flow method effectively addresses challenges in complex scenarios through systematic, structured, and flexible thinking processes. Here are the specific implementation steps:
83
95
  ```text
84
96
  Problem Definition: Clarify the core problems and objectives.
@@ -346,6 +358,7 @@ def get_weather(
346
358
  # Define tool information inside the function
347
359
  get_weather.tool_info = {
348
360
  "tool_name": "get_weather",
361
+ "tool_title": "get weather",
349
362
  "tool_description": "Get current weather information for the specified city.",
350
363
  "tool_params": [
351
364
  {"name": "city_name", "description": "The name of the city to query", "type": "string", "required": True},
@@ -368,6 +381,7 @@ def search_news(
368
381
  # Define tool information inside the function
369
382
  search_news.tool_info = {
370
383
  "tool_name": "search_news",
384
+ "tool_title": "search news",
371
385
  "tool_description": "Search news based on keywords.",
372
386
  "tool_params": [
373
387
  {"name": "keyword", "description": "Search keyword", "type": "string", "required": True},
@@ -488,7 +502,7 @@ agent.create_tool(text, tools_directory=tools_directory)
488
502
  After execution, two files will be generated in the tools directory: get_stock_kline_data.py and get_stock_realtime_data.py.
489
503
 
490
504
  ### 4. Tree of Thought (ToT)
491
- The built-in Tree of Thought module supports complex task decomposition and multi-step reasoning. Through the Tree of Thought, the agent can better handle complex tasks.
505
+ Currently, it is already supported to independently customize the use of the deepseek-r1 model for planning and thinking.The built-in Tree of Thought module supports complex task decomposition and multi-step reasoning. Through the Tree of Thought, the agent can better handle complex tasks.
492
506
 
493
507
  ```python
494
508
  # Enable Tree of Thought
@@ -497,6 +511,9 @@ agent = LightAgent(
497
511
  api_key="your_api_key",
498
512
  base_url="your_base_url",
499
513
  tree_of_thought=True, # Enable Tree of Thought
514
+ tot_model="deepseek-r1",
515
+ tot_api_key="sk-uXx0H0B***17778F1", # your deepseek r1 API Key
516
+ tot_base_url="https://api.deepseek.com/v1", # api url
500
517
  )
501
518
  ```
502
519
 
@@ -758,10 +775,10 @@ We look forward to your feedback and work together to make LightAgent even stron
758
775
  <h1>LightAgent🚀(下一代Agentic AI框架)</h1>
759
776
  </div>
760
777
 
761
- **LightAgent** 是一个极其轻量的带记忆(`mem0`)、工具(`Tools`)、思维树(`ToT`)的主动式 Agentic Framework(自主性框架)。它支持比Openai Swarm更简单的多智能体协同,构建具备自我学习能力的agent,并支持Agent测评,底层模型支持 OpenAI、智谱 ChatGLM、DeepSeek、阶跃星辰、Qwen千问大模型等。同时,LightAgent 支持 OpenAI 流格式 API 服务输出,无缝接入各大主流 Chat 框架。🌟
778
+ **LightAgent** 是一个极其轻量的带记忆(`mem0`)、工具(`Tools`)、思维树(`ToT`)的主动式 Agentic Framework(自主性框架)。它支持比Openai Swarm更简单的多智能体协同,构建具备自我学习能力的agent,并支持Agent测评,底层模型支持 OpenAI、智谱 ChatGLM、DeepSeek、阶跃星辰、Qwen通义千问大模型等。同时,LightAgent 支持 OpenAI 流格式 API 服务输出,无缝接入各大主流 Chat 框架。🌟
762
779
 
763
780
  ---
764
-
781
+ ![lightswarm_demo_cn.png](docs%2Fimages%2Flightswarm_demo_cn.png)
765
782
  ## ✨ 特性
766
783
 
767
784
  - **轻量高效** 🚀:极简设计,快速部署,适合各种规模的应用场景。(No LangChain, No LlamaIndex)100% Python 实现,无需额外依赖,核心代码仅1000行,完全开源。
@@ -776,6 +793,14 @@ We look forward to your feedback and work together to make LightAgent even stron
776
793
  - **Tools工具生成器** 🚀:只需将您的API文档交给[Tools工具生成器],它将自动化地为您打造专属的tools,助您在短短1小时内快速构建数百个个性化的自定义工具,提升效率,释放您的创新潜能。
777
794
  - **agent自我学习** 🧠️:每个agent拥有自己的场景记忆能力,拥有从用户的对话中进行自我学习能力。
778
795
 
796
+ ---
797
+ ## 新闻
798
+ - <img src="https://img.alicdn.com/imgextra/i3/O1CN01SFL0Gu26nrQBFKXFR_!!6000000007707-2-tps-500-500.png" alt="new" width="30" height="30"/>**[2025-02-19]** LightAgent v0.2.7 支持单独采用 deepseek-r1 作为的agent推理规划ToT引擎,大幅度提升复杂任务的多工具Plan能力.
799
+ - **[2025-02-06]** LightAgent version 0.2.5 is released now.
800
+ - **[2025-01-20]** LightAgent version 0.2.0 is released now.
801
+ - **[2025-01-05]** LightAgent version 0.1.0 is released now.
802
+
803
+ ---
779
804
 
780
805
  ## 🚧 即将推出
781
806
 
@@ -784,7 +809,8 @@ We look forward to your feedback and work together to make LightAgent even stron
784
809
  - **Agent 测评** 📊:内置 Agent 测评工具,方便评估和优化你构建的Agent,对齐业务场景,持续提升智能水平。
785
810
 
786
811
 
787
- ## 内置 “思考流”
812
+ ## 🔥内置 “思考流”
813
+ ### ToT现已支持DeepSeek-R1
788
814
  (Thought Flow)方法通过系统性、结构化和灵活的思维过程,能够有效应对复杂场景中的挑战。
789
815
  以下是具体实施步骤:
790
816
  ```text
@@ -1055,6 +1081,7 @@ def get_weather(
1055
1081
  # 在函数内部定义工具信息
1056
1082
  get_weather.tool_info = {
1057
1083
  "tool_name": "get_weather",
1084
+ "tool_name": "获取天气",
1058
1085
  "tool_description": "获取指定城市的当前天气信息",
1059
1086
  "tool_params": [
1060
1087
  {"name": "city_name", "description": "要查询的城市名称", "type": "string", "required": True},
@@ -1077,6 +1104,7 @@ def search_news(
1077
1104
  # 在函数内部定义工具信息
1078
1105
  search_news.tool_info = {
1079
1106
  "tool_name": "search_news",
1107
+ "tool_name": "联网搜索",
1080
1108
  "tool_description": "根据关键词搜索新闻",
1081
1109
  "tool_params": [
1082
1110
  {"name": "keyword", "description": "搜索关键词", "type": "string", "required": True},
@@ -1197,7 +1225,7 @@ agent.create_tool(text, tools_directory=tools_directory)
1197
1225
  执行后将在tools目录中生成2个文件:get_stock_kline_data.py和get_stock_realtime_data.py
1198
1226
 
1199
1227
  ### 4. 思维树(ToT)
1200
- 内置思维树模块,支持复杂任务分解和多步推理。通过思维树,Agent 可以更好地处理复杂任务。
1228
+ 当前已经支持单独自定义使用deepseek-r1模型来做规划思考。内置思维树模块,支持复杂任务分解和多步推理。通过思维树,Agent 可以更好地处理复杂任务。
1201
1229
 
1202
1230
  ```python
1203
1231
  # 启用思维树
@@ -1206,6 +1234,9 @@ agent = LightAgent(
1206
1234
  api_key="your_api_key",
1207
1235
  base_url= "your_base_url",
1208
1236
  tree_of_thought=True, # 启用思维树
1237
+ tot_model="deepseek-r1",
1238
+ tot_api_key="sk-uXx0H0B***17778F1", # 替换为你的 deepseek r1 API Key
1239
+ tot_base_url="https://api.deepseek.com/v1", # api url
1209
1240
  )
1210
1241
  ```
1211
1242
 
@@ -33,10 +33,12 @@
33
33
  <h1>LightAgent🚀 (Next Generation Agentic AI Framework)</h1>
34
34
  </div>
35
35
 
36
- **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, 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. 🌟
36
+ **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, Qwen, stepfun and more. At the same time, LightAgent supports OpenAI streaming format API service output, seamlessly integrating with major mainstream chat frameworks. 🌟
37
37
 
38
38
  ---
39
39
 
40
+ ![lightswarm_demo_en.png](docs%2Fimages%2Flightswarm_demo_en.png)
41
+
40
42
  ## ✨ Features
41
43
 
42
44
  - **Lightweight and Efficient** 🚀: Minimalist design, quick deployment, suitable for various application scenarios. (No LangChain, No LlamaIndex) 100% Python implementation, no additional dependencies, core code is only 1000 lines, fully open source.
@@ -51,6 +53,15 @@
51
53
  - **Tool Generator** 🚀: Just provide your API documentation to the [Tool Generator], which will automatically create exclusive tools for you, allowing you to quickly build hundreds of personalized custom tools in just 1 hour to improve efficiency and unleash your creative potential.
52
54
  - **Agent Self-Learning** 🧠️: Each agent has its own scene memory capabilities and the ability to self-learn from user conversations.
53
55
 
56
+ ---
57
+ ## News
58
+ - <img src="https://img.alicdn.com/imgextra/i3/O1CN01SFL0Gu26nrQBFKXFR_!!6000000007707-2-tps-500-500.png" alt="new" width="30" height="30"/>**[2025-02-19]** LightAgent v0.2.7 supports deepseek-r1 model for tot now.Significantly enhances the multi-tool planning capability for complex tasks.
59
+ - **[2025-02-06]** LightAgent version 0.2.5 is released now.
60
+ - **[2025-01-20]** LightAgent version 0.2.0 is released now.
61
+ - **[2025-01-05]** LightAgent version 0.1.0 is released now.
62
+
63
+ ---
64
+
54
65
  ## 🚧 Coming Soon
55
66
 
56
67
  - **Adaptive Tool Mechanism** 🛠️: Supports adding an unlimited number of tools, allowing the large model to first select a candidate tool set from thousands of tools, filtering irrelevant tools before submitting context to the large model, significantly reducing token consumption.
@@ -58,6 +69,7 @@
58
69
  - **Agent Assessment** 📊: Built-in agent assessment tool for conveniently evaluating and optimizing the agents you build, aligning with business scenarios, and continuously improving intelligence levels.
59
70
 
60
71
  ## Built-in "Thought Flow"
72
+ ### ToT now supports DeepSeek-R1.
61
73
  The Thought Flow method effectively addresses challenges in complex scenarios through systematic, structured, and flexible thinking processes. Here are the specific implementation steps:
62
74
  ```text
63
75
  Problem Definition: Clarify the core problems and objectives.
@@ -325,6 +337,7 @@ def get_weather(
325
337
  # Define tool information inside the function
326
338
  get_weather.tool_info = {
327
339
  "tool_name": "get_weather",
340
+ "tool_title": "get weather",
328
341
  "tool_description": "Get current weather information for the specified city.",
329
342
  "tool_params": [
330
343
  {"name": "city_name", "description": "The name of the city to query", "type": "string", "required": True},
@@ -347,6 +360,7 @@ def search_news(
347
360
  # Define tool information inside the function
348
361
  search_news.tool_info = {
349
362
  "tool_name": "search_news",
363
+ "tool_title": "search news",
350
364
  "tool_description": "Search news based on keywords.",
351
365
  "tool_params": [
352
366
  {"name": "keyword", "description": "Search keyword", "type": "string", "required": True},
@@ -467,7 +481,7 @@ agent.create_tool(text, tools_directory=tools_directory)
467
481
  After execution, two files will be generated in the tools directory: get_stock_kline_data.py and get_stock_realtime_data.py.
468
482
 
469
483
  ### 4. Tree of Thought (ToT)
470
- The built-in Tree of Thought module supports complex task decomposition and multi-step reasoning. Through the Tree of Thought, the agent can better handle complex tasks.
484
+ Currently, it is already supported to independently customize the use of the deepseek-r1 model for planning and thinking.The built-in Tree of Thought module supports complex task decomposition and multi-step reasoning. Through the Tree of Thought, the agent can better handle complex tasks.
471
485
 
472
486
  ```python
473
487
  # Enable Tree of Thought
@@ -476,6 +490,9 @@ agent = LightAgent(
476
490
  api_key="your_api_key",
477
491
  base_url="your_base_url",
478
492
  tree_of_thought=True, # Enable Tree of Thought
493
+ tot_model="deepseek-r1",
494
+ tot_api_key="sk-uXx0H0B***17778F1", # your deepseek r1 API Key
495
+ tot_base_url="https://api.deepseek.com/v1", # api url
479
496
  )
480
497
  ```
481
498
 
@@ -33,10 +33,10 @@
33
33
  <h1>LightAgent🚀(下一代Agentic AI框架)</h1>
34
34
  </div>
35
35
 
36
- **LightAgent** 是一个极其轻量的带记忆(`mem0`)、工具(`Tools`)、思维树(`ToT`)的主动式 Agentic Framework(自主性框架)。它支持比Openai Swarm更简单的多智能体协同,构建具备自我学习能力的agent,并支持Agent测评,底层模型支持 OpenAI、智谱 ChatGLM、DeepSeek、阶跃星辰、Qwen千问大模型等。同时,LightAgent 支持 OpenAI 流格式 API 服务输出,无缝接入各大主流 Chat 框架。🌟
36
+ **LightAgent** 是一个极其轻量的带记忆(`mem0`)、工具(`Tools`)、思维树(`ToT`)的主动式 Agentic Framework(自主性框架)。它支持比Openai Swarm更简单的多智能体协同,构建具备自我学习能力的agent,并支持Agent测评,底层模型支持 OpenAI、智谱 ChatGLM、DeepSeek、阶跃星辰、Qwen通义千问大模型等。同时,LightAgent 支持 OpenAI 流格式 API 服务输出,无缝接入各大主流 Chat 框架。🌟
37
37
 
38
38
  ---
39
-
39
+ ![lightswarm_demo_cn.png](docs%2Fimages%2Flightswarm_demo_cn.png)
40
40
  ## ✨ 特性
41
41
 
42
42
  - **轻量高效** 🚀:极简设计,快速部署,适合各种规模的应用场景。(No LangChain, No LlamaIndex)100% Python 实现,无需额外依赖,核心代码仅1000行,完全开源。
@@ -51,6 +51,14 @@
51
51
  - **Tools工具生成器** 🚀:只需将您的API文档交给[Tools工具生成器],它将自动化地为您打造专属的tools,助您在短短1小时内快速构建数百个个性化的自定义工具,提升效率,释放您的创新潜能。
52
52
  - **agent自我学习** 🧠️:每个agent拥有自己的场景记忆能力,拥有从用户的对话中进行自我学习能力。
53
53
 
54
+ ---
55
+ ## 新闻
56
+ - <img src="https://img.alicdn.com/imgextra/i3/O1CN01SFL0Gu26nrQBFKXFR_!!6000000007707-2-tps-500-500.png" alt="new" width="30" height="30"/>**[2025-02-19]** LightAgent v0.2.7 支持单独采用 deepseek-r1 作为的agent推理规划ToT引擎,大幅度提升复杂任务的多工具Plan能力.
57
+ - **[2025-02-06]** LightAgent version 0.2.5 is released now.
58
+ - **[2025-01-20]** LightAgent version 0.2.0 is released now.
59
+ - **[2025-01-05]** LightAgent version 0.1.0 is released now.
60
+
61
+ ---
54
62
 
55
63
  ## 🚧 即将推出
56
64
 
@@ -59,7 +67,8 @@
59
67
  - **Agent 测评** 📊:内置 Agent 测评工具,方便评估和优化你构建的Agent,对齐业务场景,持续提升智能水平。
60
68
 
61
69
 
62
- ## 内置 “思考流”
70
+ ## 🔥内置 “思考流”
71
+ ### ToT现已支持DeepSeek-R1
63
72
  (Thought Flow)方法通过系统性、结构化和灵活的思维过程,能够有效应对复杂场景中的挑战。
64
73
  以下是具体实施步骤:
65
74
  ```text
@@ -330,6 +339,7 @@ def get_weather(
330
339
  # 在函数内部定义工具信息
331
340
  get_weather.tool_info = {
332
341
  "tool_name": "get_weather",
342
+ "tool_name": "获取天气",
333
343
  "tool_description": "获取指定城市的当前天气信息",
334
344
  "tool_params": [
335
345
  {"name": "city_name", "description": "要查询的城市名称", "type": "string", "required": True},
@@ -352,6 +362,7 @@ def search_news(
352
362
  # 在函数内部定义工具信息
353
363
  search_news.tool_info = {
354
364
  "tool_name": "search_news",
365
+ "tool_name": "联网搜索",
355
366
  "tool_description": "根据关键词搜索新闻",
356
367
  "tool_params": [
357
368
  {"name": "keyword", "description": "搜索关键词", "type": "string", "required": True},
@@ -472,7 +483,7 @@ agent.create_tool(text, tools_directory=tools_directory)
472
483
  执行后将在tools目录中生成2个文件:get_stock_kline_data.py和get_stock_realtime_data.py
473
484
 
474
485
  ### 4. 思维树(ToT)
475
- 内置思维树模块,支持复杂任务分解和多步推理。通过思维树,Agent 可以更好地处理复杂任务。
486
+ 当前已经支持单独自定义使用deepseek-r1模型来做规划思考。内置思维树模块,支持复杂任务分解和多步推理。通过思维树,Agent 可以更好地处理复杂任务。
476
487
 
477
488
  ```python
478
489
  # 启用思维树
@@ -481,6 +492,9 @@ agent = LightAgent(
481
492
  api_key="your_api_key",
482
493
  base_url= "your_base_url",
483
494
  tree_of_thought=True, # 启用思维树
495
+ tot_model="deepseek-r1",
496
+ tot_api_key="sk-uXx0H0B***17778F1", # 替换为你的 deepseek r1 API Key
497
+ tot_base_url="https://api.deepseek.com/v1", # api url
484
498
  )
485
499
  ```
486
500
 
@@ -1,7 +1,7 @@
1
1
  [tool.poetry]
2
2
  name = "LightAgent"
3
- version = "0.2.6"
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, 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. 🌟"
3
+ version = "0.2.9"
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"
7
7
  readme = [
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes