lionagi 0.2.7__py3-none-any.whl → 0.2.9__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. lionagi/__init__.py +11 -25
  2. lionagi/core/action/README.md +20 -0
  3. lionagi/core/action/__init__.py +1 -2
  4. lionagi/core/action/function_calling.py +2 -27
  5. lionagi/core/action/node.py +1 -16
  6. lionagi/core/action/tool.py +4 -17
  7. lionagi/core/action/tool_manager.py +8 -31
  8. lionagi/core/agent/README.md +1 -0
  9. lionagi/core/agent/base_agent.py +3 -27
  10. lionagi/core/agent/eval/README.md +1 -0
  11. lionagi/core/collections/README.md +23 -0
  12. lionagi/core/collections/__init__.py +2 -3
  13. lionagi/core/collections/_logger.py +0 -17
  14. lionagi/core/collections/abc/README.md +63 -0
  15. lionagi/core/collections/abc/__init__.py +18 -18
  16. lionagi/core/collections/abc/component.py +5 -21
  17. lionagi/core/collections/abc/concepts.py +1 -17
  18. lionagi/core/collections/abc/exceptions.py +0 -16
  19. lionagi/core/collections/exchange.py +1 -16
  20. lionagi/core/collections/flow.py +5 -25
  21. lionagi/core/collections/model.py +6 -21
  22. lionagi/core/collections/pile.py +317 -35
  23. lionagi/core/collections/progression.py +4 -17
  24. lionagi/core/collections/util.py +2 -2
  25. lionagi/core/director/README.md +1 -0
  26. lionagi/core/director/direct.py +1 -17
  27. lionagi/core/engine/branch_engine.py +6 -6
  28. lionagi/core/engine/instruction_map_engine.py +4 -4
  29. lionagi/core/engine/script_engine.py +2 -16
  30. lionagi/core/executor/base_executor.py +1 -1
  31. lionagi/core/executor/graph_executor.py +6 -9
  32. lionagi/core/executor/neo4j_executor.py +7 -9
  33. lionagi/core/generic/README.md +0 -0
  34. lionagi/core/generic/__init__.py +1 -2
  35. lionagi/core/generic/edge.py +7 -3
  36. lionagi/core/generic/edge_condition.py +3 -2
  37. lionagi/core/generic/graph.py +5 -6
  38. lionagi/core/generic/node.py +4 -4
  39. lionagi/core/generic/tree.py +2 -1
  40. lionagi/core/generic/tree_node.py +2 -0
  41. lionagi/core/mail/__init__.py +0 -1
  42. lionagi/core/mail/mail.py +2 -1
  43. lionagi/core/mail/mail_manager.py +8 -6
  44. lionagi/core/mail/package.py +2 -0
  45. lionagi/core/mail/start_mail.py +2 -2
  46. lionagi/core/message/__init__.py +4 -5
  47. lionagi/core/message/action_request.py +5 -31
  48. lionagi/core/message/action_response.py +3 -23
  49. lionagi/core/message/assistant_response.py +2 -17
  50. lionagi/core/message/instruction.py +2 -48
  51. lionagi/core/message/message.py +2 -17
  52. lionagi/core/message/system.py +2 -17
  53. lionagi/core/message/util.py +7 -26
  54. lionagi/core/report/base.py +4 -26
  55. lionagi/core/report/form.py +6 -28
  56. lionagi/core/report/report.py +3 -26
  57. lionagi/core/report/util.py +2 -17
  58. lionagi/core/rule/_default.py +3 -2
  59. lionagi/core/rule/action.py +4 -19
  60. lionagi/core/rule/base.py +4 -19
  61. lionagi/core/rule/boolean.py +2 -2
  62. lionagi/core/rule/choice.py +3 -2
  63. lionagi/core/rule/mapping.py +7 -21
  64. lionagi/core/rule/number.py +3 -1
  65. lionagi/core/rule/rulebook.py +2 -70
  66. lionagi/core/rule/string.py +2 -13
  67. lionagi/core/rule/util.py +0 -35
  68. lionagi/core/session/branch.py +11 -27
  69. lionagi/core/session/directive_mixin.py +1 -16
  70. lionagi/core/session/session.py +8 -24
  71. lionagi/core/unit/__init__.py +1 -2
  72. lionagi/core/unit/parallel_unit.py +4 -21
  73. lionagi/core/unit/template/action.py +0 -16
  74. lionagi/core/unit/template/base.py +0 -16
  75. lionagi/core/unit/template/plan.py +1 -16
  76. lionagi/core/unit/template/predict.py +0 -16
  77. lionagi/core/unit/template/score.py +1 -17
  78. lionagi/core/unit/template/select.py +1 -16
  79. lionagi/core/unit/unit.py +6 -21
  80. lionagi/core/unit/unit_form.py +6 -19
  81. lionagi/core/unit/unit_mixin.py +11 -29
  82. lionagi/core/unit/util.py +1 -0
  83. lionagi/core/validator/validator.py +8 -22
  84. lionagi/core/work/work.py +2 -19
  85. lionagi/core/work/work_edge.py +3 -3
  86. lionagi/core/work/work_function.py +1 -18
  87. lionagi/core/work/work_function_node.py +0 -5
  88. lionagi/core/work/work_queue.py +1 -16
  89. lionagi/core/work/work_task.py +4 -4
  90. lionagi/core/work/worker.py +5 -20
  91. lionagi/core/work/worker_engine.py +5 -5
  92. lionagi/core/work/worklog.py +1 -17
  93. lionagi/experimental/compressor/base.py +1 -0
  94. lionagi/experimental/compressor/llm_compressor.py +7 -4
  95. lionagi/experimental/directive/README.md +1 -0
  96. lionagi/experimental/directive/parser/base_parser.py +2 -17
  97. lionagi/experimental/directive/parser/base_syntax.txt +200 -0
  98. lionagi/experimental/directive/template/base_template.py +1 -17
  99. lionagi/experimental/directive/tokenizer.py +0 -16
  100. lionagi/experimental/evaluator/README.md +1 -0
  101. lionagi/experimental/evaluator/ast_evaluator.py +0 -16
  102. lionagi/experimental/evaluator/base_evaluator.py +1 -17
  103. lionagi/experimental/knowledge/base.py +1 -1
  104. lionagi/integrations/bridge/__init__.py +1 -1
  105. lionagi/integrations/bridge/langchain_/documents.py +1 -1
  106. lionagi/integrations/bridge/llamaindex_/node_parser.py +2 -1
  107. lionagi/integrations/bridge/llamaindex_/textnode.py +2 -1
  108. lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +1 -1
  109. lionagi/integrations/bridge/transformers_/install_.py +1 -0
  110. lionagi/integrations/chunker/chunk.py +5 -6
  111. lionagi/integrations/loader/load.py +3 -3
  112. lionagi/integrations/loader/load_util.py +2 -2
  113. lionagi/integrations/provider/__init__.py +0 -1
  114. lionagi/integrations/provider/_mapping.py +6 -5
  115. lionagi/integrations/provider/mlx_service.py +4 -3
  116. lionagi/integrations/provider/oai.py +1 -17
  117. lionagi/integrations/provider/ollama.py +1 -1
  118. lionagi/integrations/provider/openrouter.py +1 -0
  119. lionagi/integrations/provider/transformers.py +2 -2
  120. lionagi/integrations/storage/neo4j.py +1 -1
  121. lionagi/integrations/storage/storage_util.py +3 -4
  122. lionagi/integrations/storage/structure_excel.py +5 -4
  123. lionagi/integrations/storage/to_csv.py +3 -2
  124. lionagi/integrations/storage/to_excel.py +2 -2
  125. lionagi/libs/__init__.py +15 -19
  126. lionagi/libs/ln_api.py +9 -26
  127. lionagi/libs/ln_async.py +3 -2
  128. lionagi/libs/ln_convert.py +1 -18
  129. lionagi/libs/ln_func_call.py +3 -20
  130. lionagi/libs/ln_image.py +4 -1
  131. lionagi/libs/ln_knowledge_graph.py +5 -2
  132. lionagi/libs/ln_nested.py +2 -18
  133. lionagi/libs/ln_parse.py +4 -19
  134. lionagi/libs/ln_queue.py +2 -17
  135. lionagi/libs/ln_tokenize.py +3 -1
  136. lionagi/libs/ln_validate.py +2 -18
  137. lionagi/libs/sys_util.py +0 -16
  138. lionagi/lions/coder/code_form.py +3 -1
  139. lionagi/lions/coder/coder.py +1 -1
  140. lionagi/lions/coder/util.py +3 -2
  141. lionagi/lions/researcher/data_source/finhub_.py +1 -0
  142. lionagi/lions/researcher/data_source/google_.py +2 -2
  143. lionagi/lions/researcher/data_source/wiki_.py +1 -1
  144. lionagi/tests/libs/test_api.py +2 -1
  145. lionagi/tests/libs/test_convert.py +2 -1
  146. lionagi/tests/libs/test_field_validators.py +9 -8
  147. lionagi/tests/libs/test_func_call.py +2 -2
  148. lionagi/tests/libs/test_nested.py +1 -0
  149. lionagi/tests/libs/test_queue.py +1 -0
  150. lionagi/tests/libs/test_sys_util.py +4 -4
  151. lionagi/tests/test_core/collections/test_component.py +6 -4
  152. lionagi/tests/test_core/collections/test_exchange.py +2 -1
  153. lionagi/tests/test_core/collections/test_flow.py +2 -1
  154. lionagi/tests/test_core/collections/test_pile.py +3 -2
  155. lionagi/tests/test_core/collections/test_progression.py +3 -2
  156. lionagi/tests/test_core/generic/test_edge.py +4 -2
  157. lionagi/tests/test_core/generic/test_graph.py +3 -2
  158. lionagi/tests/test_core/generic/test_node.py +2 -1
  159. lionagi/tests/test_core/generic/test_tree_node.py +2 -1
  160. lionagi/tests/test_core/mail/test_mail.py +2 -1
  161. lionagi/tests/test_core/test_branch.py +3 -2
  162. lionagi/tests/test_core/test_form.py +1 -0
  163. lionagi/tests/test_core/test_report.py +1 -0
  164. lionagi/tests/test_core/test_validator.py +4 -3
  165. lionagi/version.py +1 -1
  166. lionagi-0.2.9.dist-info/METADATA +68 -0
  167. lionagi-0.2.9.dist-info/RECORD +267 -0
  168. {lionagi-0.2.7.dist-info → lionagi-0.2.9.dist-info}/WHEEL +1 -2
  169. lionagi-0.2.7.dist-info/METADATA +0 -277
  170. lionagi-0.2.7.dist-info/RECORD +0 -258
  171. lionagi-0.2.7.dist-info/top_level.txt +0 -1
  172. {lionagi-0.2.7.dist-info → lionagi-0.2.9.dist-info}/LICENSE +0 -0
lionagi/__init__.py CHANGED
@@ -1,38 +1,24 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  import logging
18
- from .version import __version__
2
+
19
3
  from dotenv import load_dotenv
20
4
 
21
- from lionagi.libs.ln_convert import to_list, to_dict, to_df, to_readable_dict
22
- from lionagi.libs.ln_func_call import alcall, bcall, lcall, CallDecorator as cd, tcall
23
- from lionagi.core.collections.abc import Field
24
- from lionagi.core.collections import progression, flow, pile, iModel
25
- from lionagi.core.generic import Node, Graph, Tree, Edge
5
+ import lionagi.core.director.direct as direct
26
6
  from lionagi.core.action import func_to_tool
7
+ from lionagi.core.collections import flow, iModel, pile, progression
8
+ from lionagi.core.collections.abc import Field
9
+ from lionagi.core.generic import Edge, Graph, Node, Tree
27
10
  from lionagi.core.report import Form, Report
28
11
  from lionagi.core.session.branch import Branch
29
12
  from lionagi.core.session.session import Session
30
- from lionagi.core.work.worker import work, Worker, worklink
31
- from lionagi.integrations.provider.services import Services
13
+ from lionagi.core.work.worker import Worker, work, worklink
32
14
  from lionagi.integrations.chunker.chunk import chunk
33
15
  from lionagi.integrations.loader.load import load
34
- import lionagi.core.director.direct as direct
16
+ from lionagi.integrations.provider.services import Services
17
+ from lionagi.libs.ln_convert import to_df, to_dict, to_list, to_readable_dict
18
+ from lionagi.libs.ln_func_call import CallDecorator as cd
19
+ from lionagi.libs.ln_func_call import alcall, bcall, lcall, tcall
35
20
 
21
+ from .version import __version__
36
22
 
37
23
  __all__ = [
38
24
  "Field",
@@ -0,0 +1,20 @@
1
+ # Action Folder
2
+
3
+ The `action` folder contains various modules designed to facilitate dynamic function invocation and tool management within the system. Each module provides specific functionalities, which are briefly described below:
4
+
5
+ ## Modules
6
+
7
+ ### function_calling.py
8
+ This module defines the `FunctionCalling` class, which supports dynamic invocation of functions based on different input types such as tuples, dictionaries, `ActionRequest` objects, or JSON strings. It enables seamless function calls by creating instances based on the provided input format and invoking the corresponding functions asynchronously.
9
+
10
+ ### tool_manager.py
11
+ The `ToolManager` class is defined in this module. It manages tools in the system, allowing for the registration, invocation, and retrieval of tool schemas. Tools can be registered individually or in batches and invoked using various input formats including function names, JSON strings, or specialized objects like `FunctionCalling`.
12
+
13
+ ### tool.py
14
+ This module contains the `Tool` class, representing a tool with capabilities for pre-processing, post-processing, and parsing function results. It allows for the definition of callable functions, optional pre-processors, post-processors, and parsers to handle function results. The `Tool` class ensures flexible and reusable tool definitions within the system.
15
+
16
+ ## Usage Guide
17
+
18
+ - **function_calling.py**: Use this module when you need to dynamically invoke functions based on varying input formats. It simplifies function calls by creating a standardized interface for different types of function descriptions.
19
+ - **tool_manager.py**: Utilize the `ToolManager` class to manage your system's tools. It provides methods for registering tools, invoking them, and retrieving their schemas, making it a central point for tool management.
20
+ - **tool.py**: Define individual tools using the `Tool` class, specifying any necessary pre-processing or post-processing steps. This module is essential for creating robust and flexible tools that can be easily integrated into the system.
@@ -1,8 +1,7 @@
1
1
  from .function_calling import FunctionCalling
2
+ from .node import ActionNode, DirectiveSelection
2
3
  from .tool import Tool
3
4
  from .tool_manager import ToolManager, func_to_tool
4
- from .node import ActionNode, DirectiveSelection
5
-
6
5
 
7
6
  __all__ = [
8
7
  "FunctionCalling",
@@ -1,35 +1,10 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- """
18
- This module defines the FunctionCalling class, which facilitates dynamic
19
- invocation of functions based on various input types. It supports initializing
20
- function calls from tuples, dictionaries, ActionRequest objects, or JSON strings.
21
-
22
- Note:
23
- Function Calling object is the only way for AI system to call functions.
24
- """
25
-
26
1
  from functools import singledispatchmethod
27
2
  from typing import Any, Callable, Dict
28
3
 
29
- from lionagi.libs import ParseUtil
30
- from lionagi.libs.ln_func_call import call_handler
31
4
  from lionagi.core.collections.abc import Actionable
32
5
  from lionagi.core.message.action_request import ActionRequest
6
+ from lionagi.libs import ParseUtil
7
+ from lionagi.libs.ln_func_call import call_handler
33
8
 
34
9
 
35
10
  class FunctionCalling(Actionable):
@@ -1,23 +1,8 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  from pydantic import Field
18
2
 
19
3
  from lionagi.core.collections.abc import Actionable
20
4
  from lionagi.core.generic.node import Node
5
+
21
6
  from .tool import Tool
22
7
 
23
8
 
@@ -1,24 +1,11 @@
1
- """
2
- Copyright 2024 HaiyangLi
1
+ from typing import Any, Callable, Dict, List, Union
3
2
 
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- from typing import Callable, Union, List, Dict, Any
18
3
  from pydantic import Field, field_serializer
19
- from lionagi.libs.ln_func_call import call_handler
4
+
20
5
  from lionagi.core.collections.abc import Actionable
21
6
  from lionagi.core.generic.node import Node
7
+ from lionagi.libs.ln_func_call import call_handler
8
+
22
9
  from .function_calling import FunctionCalling
23
10
 
24
11
 
@@ -1,35 +1,12 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- """
18
- This module contains the ToolManager class, which manages tools in the system.
19
- It allows registering, invoking, and retrieving schemas of tools. Tools can be
20
- registered individually or in batches, and invoked using function names, JSON
21
- strings, or specialized objects.
22
- """
23
-
24
1
  import inspect
25
2
  from functools import singledispatchmethod
26
- from typing import Any, Callable, List, Union, Tuple
27
- from lionagi.libs import ParseUtil
28
- from lionagi.libs.ln_convert import to_list, to_dict
29
- from lionagi.libs.ln_func_call import lcall
30
- from lionagi.core.collections.abc import Actionable
3
+ from typing import Any, Callable, List, Tuple, Union
4
+
5
+ from lionfuncs import function_to_schema, lcall, to_dict, to_list
6
+
31
7
  from lionagi.core.action.function_calling import FunctionCalling
32
- from lionagi.core.action.tool import Tool, TOOL_TYPE
8
+ from lionagi.core.action.tool import TOOL_TYPE, Tool
9
+ from lionagi.core.collections.abc import Actionable
33
10
 
34
11
 
35
12
  class ToolManager(Actionable):
@@ -336,7 +313,7 @@ def func_to_tool(
336
313
  for idx in range(len(funcs)):
337
314
  f_ = lambda _f: Tool(
338
315
  function=_f,
339
- schema_=ParseUtil._func_to_schema(_f, style=docstring_style),
316
+ schema_=function_to_schema(_f, style=docstring_style),
340
317
  parser=parsers[idx] if len(parsers) > 1 else parsers[0],
341
318
  **kwargs,
342
319
  )
@@ -348,7 +325,7 @@ def func_to_tool(
348
325
  funcs,
349
326
  lambda _f: Tool(
350
327
  function=_f,
351
- schema_=ParseUtil._func_to_schema(_f, style=docstring_style),
328
+ schema_=function_to_schema(_f, style=docstring_style),
352
329
  **kwargs,
353
330
  ),
354
331
  )
@@ -0,0 +1 @@
1
+ agent as worker with structured executor
@@ -1,34 +1,10 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- """
18
- This module contains the BaseAgent class, which serves as a base class for agents.
19
- """
20
-
21
- from pydantic import Field
22
1
  from typing import Any, Callable
23
2
 
24
- from lionagi.libs import func_call, AsyncUtil
25
-
26
-
27
- from lionagi.core.mail.start_mail import StartMail
3
+ from lionagi.core.executor.base_executor import BaseExecutor
28
4
  from lionagi.core.generic.node import Node
29
5
  from lionagi.core.mail.mail_manager import MailManager
30
- from lionagi.core.executor.base_executor import BaseExecutor
31
- from lionagi.core.executor.graph_executor import GraphExecutor
6
+ from lionagi.core.mail.start_mail import StartMail
7
+ from lionagi.libs import AsyncUtil, func_call
32
8
 
33
9
 
34
10
  class BaseAgent(Node):
@@ -0,0 +1 @@
1
+ TODO
@@ -0,0 +1,23 @@
1
+ # LionAGI Core Collections
2
+
3
+ The `lionagi.core.collections` module provides essential data structures and abstractions for managing collections, sequences, and flows of items within the LionAGI system. These components form the foundation for efficient storage, access, and manipulation of data in AI-driven applications.
4
+
5
+ ## Pile
6
+
7
+ `Pile` is a versatile container for managing collections of `Element` objects. It offers ordered and type-validated storage, flexible key access, item retrieval and assignment, inclusion and exclusion operations, homogeneity checks, iteration, and arithmetic operations. `Pile` also supports insertion, appending, and conversion to DataFrame for easy data analysis.
8
+
9
+ ## Progression
10
+
11
+ `Progression` represents a sequence of items with a specific order. It provides methods for managing and manipulating the order of items, including inclusion and exclusion, item retrieval and removal, appending, extending, copying, and clearing. `Progression` supports arithmetic operations for adding and subtracting items or progressions, and offers length and iteration capabilities.
12
+
13
+ ## Flow
14
+
15
+ `Flow` represents a flow of categorical sequences, allowing for the organization and management of multiple `Progression` sequences within a single structure. It provides sequence storage, a registry for sequence lookup by name, a default sequence concept, sequence retrieval and appending, registration, item removal, and iteration over sequences. `Flow` makes it convenient to work with related sequences and perform operations across multiple sequences.
16
+
17
+ ## Exchange
18
+
19
+ `Exchange` is designed to handle incoming and outgoing flows of items. It uses a `Pile` to store pending items and maintains separate collections for pending incoming and outgoing items. `Exchange` provides methods for including and excluding items based on their direction (incoming or outgoing), facilitating efficient item exchange processing.
20
+
21
+ These core collections work together to provide a robust and flexible framework for managing data within the LionAGI system. They offer powerful capabilities for storing, accessing, and manipulating collections, sequences, and flows of items, enabling developers to build efficient and organized AI-driven applications.
22
+
23
+ For detailed usage examples and advanced features, please refer to the individual component documentation and upcoming tutorials.
@@ -1,9 +1,8 @@
1
+ from .exchange import Exchange
2
+ from .flow import Flow, flow
1
3
  from .model import iModel
2
4
  from .pile import Pile, pile
3
5
  from .progression import Progression, progression
4
- from .flow import Flow, flow
5
- from .exchange import Exchange
6
-
7
6
 
8
7
  __all__ = [
9
8
  "iModel",
@@ -1,19 +1,3 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  import atexit
18
2
  import contextlib
19
3
  import logging
@@ -24,7 +8,6 @@ from typing import Any, Dict, List
24
8
 
25
9
  from lionagi.libs import SysUtil, convert, nested
26
10
 
27
-
28
11
  # TODO: there should be a global data logger, under setting
29
12
 
30
13
 
@@ -0,0 +1,63 @@
1
+ # Core Components and Abstractions
2
+
3
+ The `lionagi.core.collections.abc` module provides essential building blocks and abstractions for constructing the LionAGI system. These components establish a solid foundation for managing data, relationships, and behaviors within the system's architecture. ^1
4
+
5
+ ## Component
6
+
7
+ The `Component` class, located in `lionagi.core.collections.abc`, serves as a fundamental building block within the LionAGI system architecture. As a subclass of both `Element` and `ABC` (Abstract Base Class), it encapsulates the essential attributes and behaviors required for individual components to function within the larger system.
8
+
9
+ ### Key Attributes
10
+ - **ln_id**: A unique 32-character identifier assigned to each component instance.
11
+ - **timestamp**: The UTC timestamp indicating when the component was created.
12
+ - **metadata**: A container for additional metadata associated with the component.
13
+ - **extra_fields**: Customizable fields that can be added to each component as needed.
14
+ - **content**: The primary data or functionality encapsulated by the component.
15
+
16
+ ### Key Methods
17
+ - **Type Conversion**
18
+ - **from_obj()**: Accepts input in various formats, including dict, string, llamaindex, langchain, pydantic, pd.DataFrame, and pd.Series.
19
+ - **to**: Provides methods for converting the component to different representations, such as to_dict(), to_xml(), to_pd_series(), to_langchain_doc(), and to_llama_index_node().
20
+ - **repr**: Returns a string representation of the component in `pd.Series` format.
21
+
22
+ ## Concepts
23
+
24
+ The `concepts.py` file, located in `lionagi.core.collections.abc`, defines a set of abstract base classes that are essential for managing the fundamental behaviors and relationships within the LionAGI system. These classes establish a structured framework for handling collections, sequencing, conditions, actions, and other core concepts.
25
+
26
+ ### Key Classes
27
+ 1. **Record**: Manages a collection of unique items, offering a standardized interface for item retrieval, addition, and iteration.
28
+ 2. **Ordering**: Ensures a specific order is maintained when sequencing items.
29
+ 3. **Condition**: Represents conditions that can be evaluated asynchronously to determine their applicability to a given context.
30
+ 4. **Actionable**: Encapsulates actions that can be invoked asynchronously with arguments.
31
+ 5. **Progressable**: Manages processes that can progress forward asynchronously.
32
+ 6. **Relatable**: Establishes relationships between items based on provided arguments.
33
+ 7. **Sendable**: Defines message-like objects with sender and recipient fields, including validation.
34
+ 8. **Executable**: Represents objects that can be executed asynchronously.
35
+ 9. **Directive**: Encapsulates higher-level directives for directing operations asynchronously.
36
+
37
+ These abstract classes form a consistent and extensible foundation for building complex, interactive components within the LionAGI system, promoting efficient and organized development practices.
38
+
39
+ ## Exceptions
40
+
41
+ The `exceptions.py` file, found in `lionagi.core.collections.abc`, defines a comprehensive set of custom exceptions designed to handle various error conditions that may arise within the LionAGI system. These exceptions provide clear and specific error messages, facilitating easier debugging and error management. ^2
42
+
43
+ ### Key Exception Classes
44
+ 1. **LionAGIError**: The base class for all exceptions in the LionAGI system, providing a customizable generic error message.
45
+ 2. **LionValueError**: Raised for errors related to input values, ensuring that incorrect values are properly reported.
46
+ 3. **LionTypeError**: Raised for type mismatches or type checking errors, helping to enforce correct data types throughout the system.
47
+ 4. **LionItemError**: A base class for exceptions related to LionAGI items, including specific error messages for item-related issues.
48
+ 5. **ItemNotFoundError**: Raised when a specified item cannot be found within the system, indicating missing or incorrect item references.
49
+ 6. **ItemInvalidError**: Raised when an invalid item is used in an operation, ensuring operations are performed on valid items only.
50
+ 7. **FieldError**: Raised for errors in field validation, highlighting issues with specific data fields.
51
+ 8. **LionOperationError**: A base class for exceptions related to operational failures, providing a framework for more specific operational errors.
52
+ 9. **ConcurrencyError**: Raised for errors due to concurrency issues, ensuring that concurrent operations are properly managed.
53
+ 10. **RelationError**: Raised for errors in relation operations, indicating issues with node relationships.
54
+ 11. **ActionError**: Raised for errors in action operations, signaling problems with executing specified actions.
55
+ 12. **ResourceLimitExceededError**: Raised when a resource limit is exceeded, helping to manage and enforce system resource constraints.
56
+ 13. **TimeoutError**: Raised when an operation times out, ensuring that long-running operations are properly handled.
57
+ 14. **ServiceError**: Raised for errors in endpoint configuration, indicating issues with service availability or configuration.
58
+
59
+ These exceptions contribute to a robust error handling mechanism within the LionAGI system, ensuring that errors are clearly reported and managed, ultimately aiding in maintaining the system's stability and reliability.
60
+
61
+ ^1: [Design Patterns: Elements of Reusable Object-Oriented Software](https://en.wikipedia.org/wiki/Design_Patterns)
62
+
63
+ ^2: [Python Exceptions: An Introduction](https://realpython.com/python-exceptions/)
@@ -1,31 +1,31 @@
1
1
  """abc: Abstract Base Classes for lionagi."""
2
2
 
3
3
  from pydantic import Field
4
- from .exceptions import (
5
- LionTypeError,
6
- LionValueError,
7
- ItemNotFoundError,
8
- FieldError,
9
- LionOperationError,
10
- RelationError,
11
- ActionError,
12
- ModelLimitExceededError,
13
- )
14
- from .component import Element, Component, LionIDable, get_lion_id
4
+
5
+ from .component import Component, Element, LionIDable, get_lion_id
15
6
  from .concepts import (
16
- Record,
17
- Ordering,
18
- Condition,
19
7
  Actionable,
20
- Relatable,
8
+ Condition,
9
+ Directive,
10
+ Executable,
11
+ Ordering,
21
12
  Progressable,
13
+ Record,
14
+ Relatable,
22
15
  Sendable,
23
- Executable,
24
- Directive,
16
+ )
17
+ from .exceptions import (
18
+ ActionError,
19
+ FieldError,
20
+ ItemNotFoundError,
21
+ LionOperationError,
22
+ LionTypeError,
23
+ LionValueError,
24
+ ModelLimitExceededError,
25
+ RelationError,
25
26
  )
26
27
  from .util import SYSTEM_FIELDS
27
28
 
28
-
29
29
  __all__ = [
30
30
  "Element",
31
31
  "Record",
@@ -1,37 +1,21 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  """Component class, base building block in LionAGI."""
18
2
 
19
- from abc import ABC
20
3
  import contextlib
4
+ from abc import ABC
21
5
  from collections.abc import Sequence
22
6
  from functools import singledispatchmethod
23
- from typing import Any, TypeVar, Type, TypeAlias, Union
7
+ from typing import Any, Type, TypeAlias, TypeVar, Union
24
8
 
25
9
  from pandas import DataFrame, Series
26
- from pydantic import BaseModel, Field, ValidationError, AliasChoices
10
+ from pydantic import AliasChoices, BaseModel, Field, ValidationError
27
11
 
28
12
  from lionagi.libs import ParseUtil, SysUtil
29
13
  from lionagi.libs.ln_convert import strip_lower, to_dict, to_str
30
14
  from lionagi.libs.ln_func_call import lcall
31
- from lionagi.libs.ln_nested import nget, nset, ninsert, flatten, unflatten
15
+ from lionagi.libs.ln_nested import flatten, nget, ninsert, nset, unflatten
32
16
 
33
17
  from .exceptions import FieldError, LionTypeError, LionValueError
34
- from .util import base_lion_fields, llama_meta_fields, lc_meta_fields
18
+ from .util import base_lion_fields, lc_meta_fields, llama_meta_fields
35
19
 
36
20
  T = TypeVar("T")
37
21
 
@@ -1,26 +1,10 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  """This module defines abstract base classes for LionAGI."""
18
2
 
19
3
  from abc import ABC, abstractmethod
20
4
  from collections.abc import Generator
21
5
  from typing import Any, Iterator, TypeVar
22
6
 
23
- from pydantic import Field, BaseModel, field_validator
7
+ from pydantic import BaseModel, Field, field_validator
24
8
 
25
9
  from .component import LionIDable, get_lion_id
26
10
  from .exceptions import LionTypeError
@@ -1,19 +1,3 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
1
  # import logging
18
2
 
19
3
  # # Configure logging
@@ -1,20 +1,5 @@
1
- """
2
- Copyright 2024 HaiyangLi
1
+ from typing import Generic, TypeVar
3
2
 
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- from typing import TypeVar, Generic
18
3
  from .abc import Element, Field, Sendable
19
4
  from .pile import Pile, pile
20
5
  from .progression import Progression, progression
@@ -1,31 +1,11 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- from collections.abc import Mapping
1
+ import contextlib
18
2
  from collections import deque
3
+ from collections.abc import Mapping
19
4
  from typing import Tuple
5
+
20
6
  from pydantic import Field
21
- import contextlib
22
- from .abc import (
23
- Record,
24
- LionTypeError,
25
- ItemNotFoundError,
26
- LionIDable,
27
- Element,
28
- )
7
+
8
+ from .abc import Element, ItemNotFoundError, LionIDable, LionTypeError, Record
29
9
  from .pile import Pile, pile
30
10
  from .progression import Progression, progression
31
11
 
@@ -1,24 +1,11 @@
1
- """
2
- Copyright 2024 HaiyangLi
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- """
16
-
17
- import os
18
1
  import asyncio
2
+ import os
3
+
19
4
  import numpy as np
20
5
  from dotenv import load_dotenv
21
- from lionagi.libs import SysUtil, BaseService, StatusTracker, APIUtil, to_list, ninsert
6
+
7
+ from lionagi.libs import APIUtil, BaseService, StatusTracker, SysUtil, ninsert, to_list
8
+
22
9
  from .abc import Component, ModelLimitExceededError
23
10
 
24
11
  load_dotenv()
@@ -107,9 +94,7 @@ class iModel:
107
94
  else:
108
95
  provider = str(provider).lower() if provider else "openai"
109
96
 
110
- from lionagi.integrations.provider._mapping import (
111
- SERVICE_PROVIDERS_MAPPING,
112
- )
97
+ from lionagi.integrations.provider._mapping import SERVICE_PROVIDERS_MAPPING
113
98
 
114
99
  self.provider_schema = (
115
100
  provider_schema or SERVICE_PROVIDERS_MAPPING[provider]["schema"]