lionagi 0.0.316__tar.gz → 0.1.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. {lionagi-0.0.316/lionagi.egg-info → lionagi-0.1.0}/PKG-INFO +1 -1
  2. lionagi-0.1.0/lionagi/core/__init__.py +26 -0
  3. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/agent/base_agent.py +26 -30
  4. lionagi-0.0.316/lionagi/core/branch/base_branch.py → lionagi-0.1.0/lionagi/core/branch/base.py +13 -14
  5. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/branch/branch.py +22 -20
  6. lionagi-0.0.316/lionagi/core/branch/branch_flow_mixin.py → lionagi-0.1.0/lionagi/core/branch/flow_mixin.py +6 -6
  7. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/branch/util.py +1 -1
  8. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/__init__.py +10 -1
  9. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/cot.py +61 -26
  10. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/plan.py +10 -8
  11. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/predict.py +5 -5
  12. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/react.py +8 -8
  13. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/score.py +4 -4
  14. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/select.py +4 -4
  15. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/utils.py +7 -4
  16. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/vote.py +2 -2
  17. lionagi-0.1.0/lionagi/core/execute/base_executor.py +50 -0
  18. lionagi-0.1.0/lionagi/core/execute/branch_executor.py +233 -0
  19. lionagi-0.1.0/lionagi/core/execute/instruction_map_executor.py +131 -0
  20. lionagi-0.1.0/lionagi/core/execute/structure_executor.py +218 -0
  21. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/flow/monoflow/ReAct.py +4 -4
  22. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/flow/monoflow/chat.py +6 -6
  23. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/flow/monoflow/chat_mixin.py +24 -34
  24. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/flow/monoflow/followup.py +4 -4
  25. lionagi-0.1.0/lionagi/core/flow/polyflow/__init__.py +1 -0
  26. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/flow/polyflow/chat.py +15 -12
  27. lionagi-0.0.316/lionagi/core/prompt/action_template.py → lionagi-0.1.0/lionagi/core/form/action_form.py +2 -2
  28. {lionagi-0.0.316/lionagi/core/prompt → lionagi-0.1.0/lionagi/core/form}/field_validator.py +40 -31
  29. lionagi-0.1.0/lionagi/core/form/form.py +302 -0
  30. lionagi-0.1.0/lionagi/core/form/mixin.py +214 -0
  31. lionagi-0.0.316/lionagi/core/prompt/scored_template.py → lionagi-0.1.0/lionagi/core/form/scored_form.py +2 -2
  32. lionagi-0.1.0/lionagi/core/generic/__init__.py +37 -0
  33. lionagi-0.1.0/lionagi/core/generic/action.py +26 -0
  34. lionagi-0.1.0/lionagi/core/generic/component.py +457 -0
  35. lionagi-0.1.0/lionagi/core/generic/condition.py +44 -0
  36. lionagi-0.1.0/lionagi/core/generic/data_logger.py +305 -0
  37. lionagi-0.1.0/lionagi/core/generic/edge.py +110 -0
  38. lionagi-0.1.0/lionagi/core/generic/mail.py +90 -0
  39. lionagi-0.1.0/lionagi/core/generic/mailbox.py +36 -0
  40. lionagi-0.1.0/lionagi/core/generic/node.py +285 -0
  41. lionagi-0.1.0/lionagi/core/generic/relation.py +70 -0
  42. lionagi-0.1.0/lionagi/core/generic/signal.py +22 -0
  43. lionagi-0.1.0/lionagi/core/generic/structure.py +362 -0
  44. lionagi-0.1.0/lionagi/core/generic/transfer.py +20 -0
  45. lionagi-0.1.0/lionagi/core/generic/work.py +40 -0
  46. lionagi-0.1.0/lionagi/core/graph/graph.py +126 -0
  47. lionagi-0.1.0/lionagi/core/graph/tree.py +190 -0
  48. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/mail/mail_manager.py +12 -10
  49. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/mail/schema.py +9 -2
  50. lionagi-0.1.0/lionagi/core/messages/schema.py +325 -0
  51. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/session/session.py +25 -23
  52. lionagi-0.1.0/lionagi/core/tool/__init__.py +5 -0
  53. lionagi-0.1.0/lionagi/core/tool/tool.py +28 -0
  54. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/tool/tool_manager.py +75 -75
  55. lionagi-0.1.0/lionagi/integrations/chunker/__init__.py +0 -0
  56. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/chunker/chunk.py +7 -7
  57. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/config/oai_configs.py +4 -4
  58. lionagi-0.1.0/lionagi/integrations/loader/__init__.py +0 -0
  59. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/loader/load.py +6 -6
  60. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/loader/load_util.py +8 -8
  61. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/libs/ln_api.py +3 -3
  62. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/libs/ln_parse.py +43 -6
  63. lionagi-0.1.0/lionagi/libs/ln_validate.py +288 -0
  64. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/libs/sys_util.py +28 -6
  65. lionagi-0.1.0/lionagi/tests/__init__.py +0 -0
  66. lionagi-0.1.0/lionagi/tests/integrations/__init__.py +0 -0
  67. lionagi-0.1.0/lionagi/tests/libs/__init__.py +0 -0
  68. lionagi-0.1.0/lionagi/tests/libs/test_async.py +0 -0
  69. lionagi-0.1.0/lionagi/tests/libs/test_field_validators.py +353 -0
  70. lionagi-0.1.0/lionagi/tests/test_core/__init__.py +0 -0
  71. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/tests/test_core/test_base_branch.py +0 -1
  72. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/tests/test_core/test_branch.py +3 -0
  73. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/tests/test_core/test_session_base_util.py +1 -0
  74. lionagi-0.1.0/lionagi/version.py +1 -0
  75. {lionagi-0.0.316 → lionagi-0.1.0/lionagi.egg-info}/PKG-INFO +1 -1
  76. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi.egg-info/SOURCES.txt +45 -30
  77. lionagi-0.0.316/lionagi/core/__init__.py +0 -15
  78. lionagi-0.0.316/lionagi/core/agent/__init__.py +0 -3
  79. lionagi-0.0.316/lionagi/core/branch/__init__.py +0 -4
  80. lionagi-0.0.316/lionagi/core/branch/executable_branch.py +0 -347
  81. lionagi-0.0.316/lionagi/core/flow/polyflow/__init__.py +0 -1
  82. lionagi-0.0.316/lionagi/core/mail/__init__.py +0 -8
  83. lionagi-0.0.316/lionagi/core/messages/__init__.py +0 -3
  84. lionagi-0.0.316/lionagi/core/messages/schema.py +0 -533
  85. lionagi-0.0.316/lionagi/core/prompt/prompt_template.py +0 -312
  86. lionagi-0.0.316/lionagi/core/schema/__init__.py +0 -22
  87. lionagi-0.0.316/lionagi/core/schema/action_node.py +0 -29
  88. lionagi-0.0.316/lionagi/core/schema/base_mixin.py +0 -296
  89. lionagi-0.0.316/lionagi/core/schema/base_node.py +0 -199
  90. lionagi-0.0.316/lionagi/core/schema/condition.py +0 -24
  91. lionagi-0.0.316/lionagi/core/schema/data_logger.py +0 -354
  92. lionagi-0.0.316/lionagi/core/schema/data_node.py +0 -93
  93. lionagi-0.0.316/lionagi/core/schema/prompt_template.py +0 -67
  94. lionagi-0.0.316/lionagi/core/schema/structure.py +0 -912
  95. lionagi-0.0.316/lionagi/core/session/__init__.py +0 -3
  96. lionagi-0.0.316/lionagi/core/tool/__init__.py +0 -3
  97. lionagi-0.0.316/lionagi/core/tool/manual.py +0 -1
  98. lionagi-0.0.316/lionagi/version.py +0 -1
  99. {lionagi-0.0.316 → lionagi-0.1.0}/LICENSE +0 -0
  100. {lionagi-0.0.316 → lionagi-0.1.0}/README.md +0 -0
  101. {lionagi-0.0.316 → lionagi-0.1.0}/README.rst +0 -0
  102. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/__init__.py +0 -0
  103. {lionagi-0.0.316/lionagi/core/branch/base → lionagi-0.1.0/lionagi/core/agent}/__init__.py +0 -0
  104. {lionagi-0.0.316/lionagi/core/flow → lionagi-0.1.0/lionagi/core/branch}/__init__.py +0 -0
  105. /lionagi-0.0.316/lionagi/core/flow/base/__init__.py → /lionagi-0.1.0/lionagi/core/branch/executable_branch.py +0 -0
  106. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/direct/sentiment.py +0 -0
  107. {lionagi-0.0.316/lionagi/core/prompt → lionagi-0.1.0/lionagi/core/execute}/__init__.py +0 -0
  108. {lionagi-0.0.316/lionagi/integrations/bridge/langchain_ → lionagi-0.1.0/lionagi/core/flow}/__init__.py +0 -0
  109. {lionagi-0.0.316/lionagi/core/flow/base → lionagi-0.1.0/lionagi/core/flow}/baseflow.py +0 -0
  110. /lionagi-0.0.316/lionagi/integrations/bridge/llamaindex_/__init__.py → /lionagi-0.1.0/lionagi/core/flow/mono_chat_mixin.py +0 -0
  111. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/core/flow/monoflow/__init__.py +0 -0
  112. {lionagi-0.0.316/lionagi/integrations/bridge/pydantic_ → lionagi-0.1.0/lionagi/core/form}/__init__.py +0 -0
  113. {lionagi-0.0.316/lionagi/integrations/chunker → lionagi-0.1.0/lionagi/core/graph}/__init__.py +0 -0
  114. {lionagi-0.0.316/lionagi/integrations/loader → lionagi-0.1.0/lionagi/core/mail}/__init__.py +0 -0
  115. {lionagi-0.0.316/lionagi/tests → lionagi-0.1.0/lionagi/core/messages}/__init__.py +0 -0
  116. {lionagi-0.0.316/lionagi/tests/test_core → lionagi-0.1.0/lionagi/core/session}/__init__.py +0 -0
  117. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/__init__.py +0 -0
  118. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/bridge/__init__.py +0 -0
  119. {lionagi-0.0.316/lionagi/tests/test_integrations → lionagi-0.1.0/lionagi/integrations/bridge/langchain_}/__init__.py +0 -0
  120. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/bridge/langchain_/documents.py +0 -0
  121. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/bridge/langchain_/langchain_bridge.py +0 -0
  122. {lionagi-0.0.316/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/integrations/bridge/llamaindex_}/__init__.py +0 -0
  123. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/index.py +0 -0
  124. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +0 -0
  125. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/node_parser.py +0 -0
  126. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/reader.py +0 -0
  127. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/bridge/llamaindex_/textnode.py +0 -0
  128. /lionagi-0.0.316/lionagi/tests/test_libs/test_async.py → /lionagi-0.1.0/lionagi/integrations/bridge/pydantic_/__init__.py +0 -0
  129. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +0 -0
  130. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/config/__init__.py +0 -0
  131. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/config/mlx_configs.py +0 -0
  132. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/config/ollama_configs.py +0 -0
  133. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/config/openrouter_configs.py +0 -0
  134. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/provider/__init__.py +0 -0
  135. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/provider/litellm.py +0 -0
  136. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/provider/mistralai.py +0 -0
  137. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/provider/mlx_service.py +0 -0
  138. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/provider/oai.py +0 -0
  139. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/provider/ollama.py +0 -0
  140. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/provider/openrouter.py +0 -0
  141. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/provider/services.py +0 -0
  142. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/integrations/provider/transformers.py +0 -0
  143. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/libs/__init__.py +0 -0
  144. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/libs/ln_async.py +0 -0
  145. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/libs/ln_convert.py +0 -0
  146. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/libs/ln_dataframe.py +0 -0
  147. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/libs/ln_func_call.py +0 -0
  148. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/libs/ln_nested.py +0 -0
  149. {lionagi-0.0.316/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_api.py +0 -0
  150. {lionagi-0.0.316/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_convert.py +0 -0
  151. {lionagi-0.0.316/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_func_call.py +0 -0
  152. {lionagi-0.0.316/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_nested.py +0 -0
  153. {lionagi-0.0.316/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_parse.py +0 -0
  154. {lionagi-0.0.316/lionagi/tests/test_libs → lionagi-0.1.0/lionagi/tests/libs}/test_sys_util.py +0 -0
  155. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/tests/test_core/test_chat_flow.py +0 -0
  156. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/tests/test_core/test_mail_manager.py +0 -0
  157. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/tests/test_core/test_prompts.py +0 -0
  158. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/tests/test_core/test_session.py +0 -0
  159. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi/tests/test_core/test_tool_manager.py +0 -0
  160. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi.egg-info/dependency_links.txt +0 -0
  161. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi.egg-info/requires.txt +0 -0
  162. {lionagi-0.0.316 → lionagi-0.1.0}/lionagi.egg-info/top_level.txt +0 -0
  163. {lionagi-0.0.316 → lionagi-0.1.0}/pyproject.toml +0 -0
  164. {lionagi-0.0.316 → lionagi-0.1.0}/setup.cfg +0 -0
  165. {lionagi-0.0.316 → lionagi-0.1.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lionagi
3
- Version: 0.0.316
3
+ Version: 0.1.0
4
4
  Summary: Towards automated general intelligence.
5
5
  Author: HaiyangLi
6
6
  Author-email: Haiyang Li <ocean@lionagi.ai>
@@ -0,0 +1,26 @@
1
+ from . import *
2
+
3
+ from .branch.branch import Branch
4
+ from .session.session import Session
5
+ from .generic import (
6
+ ActionNode,
7
+ ActionSelection,
8
+ Condition,
9
+ )
10
+ from .agent.base_agent import BaseAgent
11
+ from .messages.schema import Instruction, System, Response
12
+ from .tool import func_to_tool
13
+
14
+
15
+ __all__ = [
16
+ "ActionNode",
17
+ "ActionSelection",
18
+ "Branch",
19
+ "Condition",
20
+ "Session",
21
+ "System",
22
+ "Instruction",
23
+ "Response",
24
+ "BaseAgent",
25
+ "func_to_tool",
26
+ ]
@@ -2,37 +2,28 @@
2
2
  This module contains the BaseAgent class, which serves as a base class for agents.
3
3
  """
4
4
 
5
- from lionagi.core.mail.schema import StartMail
6
- from lionagi.core.schema.base_node import BaseRelatableNode
7
- from lionagi.core.mail.mail_manager import MailManager
5
+ from pydantic import Field
6
+ from typing import Any, Callable
8
7
 
9
8
  from lionagi.libs import func_call, AsyncUtil
10
9
 
11
10
 
12
- class BaseAgent(BaseRelatableNode):
13
- """
14
- A base class for agents.
15
-
16
- Attributes:
17
- structure: The structure of the agent.
18
- executable: The executable object of the agent.
19
- start: The StartMail object for triggering the agent.
20
- mailManager: The MailManager object for managing agent communication.
21
- output_parser: A function for parsing the agent's output (optional).
22
- start_context: The initial context for the agent (optional).
23
-
24
- Methods:
25
- __init__(self, structure, executable_obj, output_parser=None) -> None:
26
- Initializes the BaseAgent instance.
11
+ from lionagi.core.mail.schema import StartMail
12
+ from lionagi.core.generic import Node
13
+ from lionagi.core.mail.mail_manager import MailManager
14
+ from lionagi.core.execute.base_executor import BaseExecutor
15
+ from lionagi.core.execute.structure_executor import StructureExecutor
27
16
 
28
- async mail_manager_control(self, refresh_time=1) -> None:
29
- Controls the mail manager execution based on the structure and executable states.
30
17
 
31
- async execute(self, context=None) -> Any:
32
- Executes the agent with the given context and returns the parsed output (if available).
33
- """
18
+ class BaseAgent(Node):
34
19
 
35
- def __init__(self, structure, executable_obj, output_parser=None) -> None:
20
+ def __init__(
21
+ self,
22
+ structure: StructureExecutor,
23
+ executable: BaseExecutor,
24
+ output_parser=None,
25
+ **kwargs,
26
+ ) -> None:
36
27
  """
37
28
  Initializes the BaseAgent instance.
38
29
 
@@ -42,12 +33,16 @@ class BaseAgent(BaseRelatableNode):
42
33
  output_parser: A function for parsing the agent's output (optional).
43
34
  """
44
35
  super().__init__()
45
- self.structure = structure
46
- self.executable = executable_obj
47
- self.start = StartMail()
48
- self.mailManager = MailManager([self.structure, self.executable, self.start])
49
- self.output_parser = output_parser
50
- self.start_context = None
36
+ self.structure: StructureExecutor = structure
37
+ self.executable: BaseExecutor = executable
38
+ for v, k in kwargs.items():
39
+ executable.__setattr__(v, k)
40
+ self.start: StartMail = StartMail()
41
+ self.mailManager: MailManager = MailManager(
42
+ [self.structure, self.executable, self.start]
43
+ )
44
+ self.output_parser: Callable | None = output_parser
45
+ self.start_context: Any | None = None
51
46
 
52
47
  async def mail_manager_control(self, refresh_time=1):
53
48
  """
@@ -92,3 +87,4 @@ class BaseAgent(BaseRelatableNode):
92
87
 
93
88
  if self.output_parser:
94
89
  return self.output_parser(self)
90
+
@@ -1,22 +1,21 @@
1
1
  from abc import ABC
2
2
  from typing import Any
3
3
 
4
- from lionagi.libs.sys_util import PATH_TYPE
4
+ from pathlib import Path
5
5
  from lionagi.libs import convert, dataframe, SysUtil
6
6
 
7
- from ..schema.base_node import BaseRelatableNode
8
- from ..schema.data_logger import DataLogger, DLog
9
- from ..messages.schema import (
7
+ from lionagi.core.generic import BaseNode, DataLogger, DLog
8
+ from lionagi.core.messages.schema import (
10
9
  BranchColumns,
11
10
  System,
12
11
  Response,
13
12
  Instruction,
14
13
  BaseMessage,
15
14
  )
16
- from .util import MessageUtil
15
+ from lionagi.core.branch.util import MessageUtil
17
16
 
18
17
 
19
- class BaseBranch(BaseRelatableNode, ABC):
18
+ class BaseBranch(BaseNode, ABC):
20
19
  """
21
20
  Base class for managing branches of conversation, incorporating messages
22
21
  and logging functionality.
@@ -24,7 +23,7 @@ class BaseBranch(BaseRelatableNode, ABC):
24
23
  Attributes:
25
24
  messages (dataframe.ln_DataFrame): Holds the messages in the branch.
26
25
  datalogger (DataLogger): Logs data related to the branch's operation.
27
- persist_path (PATH_TYPE): Filesystem path for data persistence.
26
+ persist_path (str | Path): Filesystem path for data persistence.
28
27
  """
29
28
 
30
29
  _columns: list[str] = BranchColumns.COLUMNS.value
@@ -33,7 +32,7 @@ class BaseBranch(BaseRelatableNode, ABC):
33
32
  self,
34
33
  messages: dataframe.ln_DataFrame | None = None,
35
34
  datalogger: DataLogger | None = None,
36
- persist_path: PATH_TYPE | None = None,
35
+ persist_path: str | Path | None = None,
37
36
  name=None,
38
37
  **kwargs,
39
38
  ) -> None:
@@ -97,6 +96,7 @@ class BaseBranch(BaseRelatableNode, ABC):
97
96
  if self.name is not None:
98
97
  _msg.sender = self.name
99
98
 
99
+ setattr(_msg, "node_id", _msg.id_)
100
100
  _msg.content = _msg.msg_content
101
101
  self.messages.loc[len(self.messages)] = _msg.to_pd_series()
102
102
 
@@ -332,7 +332,7 @@ class BaseBranch(BaseRelatableNode, ABC):
332
332
 
333
333
  def to_csv_file(
334
334
  self,
335
- filename: PATH_TYPE = "messages.csv",
335
+ filename: str | Path = "messages.csv",
336
336
  dir_exist_ok: bool = True,
337
337
  timestamp: bool = True,
338
338
  time_prefix: bool = False,
@@ -375,7 +375,7 @@ class BaseBranch(BaseRelatableNode, ABC):
375
375
 
376
376
  def to_json_file(
377
377
  self,
378
- filename: PATH_TYPE = "messages.json",
378
+ filename: str | Path = "messages.json",
379
379
  dir_exist_ok: bool = True,
380
380
  timestamp: bool = True,
381
381
  time_prefix: bool = False,
@@ -420,7 +420,7 @@ class BaseBranch(BaseRelatableNode, ABC):
420
420
 
421
421
  def log_to_csv(
422
422
  self,
423
- filename: PATH_TYPE = "log.csv",
423
+ filename: str | Path = "log.csv",
424
424
  dir_exist_ok: bool = True,
425
425
  timestamp: bool = True,
426
426
  time_prefix: bool = False,
@@ -456,7 +456,7 @@ class BaseBranch(BaseRelatableNode, ABC):
456
456
 
457
457
  def log_to_json(
458
458
  self,
459
- filename: PATH_TYPE = "log.json",
459
+ filename: str | Path = "log.json",
460
460
  dir_exist_ok: bool = True,
461
461
  timestamp: bool = True,
462
462
  time_prefix: bool = False,
@@ -636,7 +636,6 @@ class BaseBranch(BaseRelatableNode, ABC):
636
636
  case_sensitive=case_sensitive,
637
637
  )
638
638
 
639
- # noinspection PyTestUnpassedFixture
640
639
  def _info(self, use_sender: bool = False) -> dict[str, int]:
641
640
  """
642
641
  Helper method to generate summaries of messages either by role or sender.
@@ -651,4 +650,4 @@ class BaseBranch(BaseRelatableNode, ABC):
651
650
  messages = self.messages["sender"] if use_sender else self.messages["role"]
652
651
  result = messages.value_counts().to_dict()
653
652
  result["total"] = len(self.messages)
654
- return result
653
+ return result
@@ -4,19 +4,18 @@ This module contains the Branch class, which represents a branch in a conversati
4
4
 
5
5
  from collections import deque
6
6
  from typing import Any, Union, TypeVar, Callable
7
+ from pathlib import Path
7
8
 
8
- from lionagi.libs.sys_util import PATH_TYPE
9
9
  from lionagi.libs import StatusTracker, BaseService, convert, dataframe
10
10
 
11
- from ..schema import TOOL_TYPE, Tool, DataLogger
12
- from ..tool import ToolManager, func_to_tool
11
+ from lionagi.core.generic import DataLogger
12
+ from lionagi.core.tool import ToolManager, func_to_tool, Tool, TOOL_TYPE
13
+ from lionagi.core.messages.schema import System
14
+ from lionagi.core.mail.schema import BaseMail
13
15
 
14
- from ..messages import System
15
- from ..mail import BaseMail
16
-
17
- from .util import MessageUtil
18
- from .base_branch import BaseBranch
19
- from .branch_flow_mixin import BranchFlowMixin
16
+ from lionagi.core.branch.util import MessageUtil
17
+ from lionagi.core.branch.base import BaseBranch
18
+ from lionagi.core.branch.flow_mixin import BranchFlowMixin
20
19
 
21
20
  from dotenv import load_dotenv
22
21
 
@@ -95,7 +94,7 @@ class Branch(BaseBranch, BranchFlowMixin):
95
94
  llmconfig: dict[str, str | int | dict] | None = None,
96
95
  tools: list[Callable | Tool] | None = None,
97
96
  datalogger: None | DataLogger = None,
98
- persist_path: PATH_TYPE | None = None, # instruction_sets=None,
97
+ persist_path: str | Path | None = None, # instruction_sets=None,
99
98
  tool_manager: ToolManager | None = None,
100
99
  **kwargs,
101
100
  ):
@@ -111,7 +110,7 @@ class Branch(BaseBranch, BranchFlowMixin):
111
110
  llmconfig (dict[str, str | int | dict]): The configuration for the language model (optional).
112
111
  tools (list[Callable | Tool]): The tools to register in the branch (optional).
113
112
  datalogger (DataLogger): The data logger for the branch (optional).
114
- persist_path (PATH_TYPE): The path to persist the branch data (optional).
113
+ persist_path (str | Path): The path to persist the branch data (optional).
115
114
  tool_manager (ToolManager): The tool manager for the branch (optional).
116
115
  **kwargs: Additional keyword arguments.
117
116
 
@@ -165,7 +164,7 @@ class Branch(BaseBranch, BranchFlowMixin):
165
164
  llmconfig: dict[str, str | int | dict] | None = None,
166
165
  tools: TOOL_TYPE | None = None,
167
166
  datalogger: None | DataLogger = None,
168
- persist_path: PATH_TYPE | None = None, # instruction_sets=None,
167
+ persist_path: str | Path | None = None, # instruction_sets=None,
169
168
  tool_manager: ToolManager | None = None,
170
169
  read_kwargs=None,
171
170
  **kwargs,
@@ -180,7 +179,7 @@ class Branch(BaseBranch, BranchFlowMixin):
180
179
  llmconfig (dict[str, str | int | dict]): The configuration for the language model (optional).
181
180
  tools (TOOL_TYPE): The tools to register in the branch (optional).
182
181
  datalogger (DataLogger): The data logger for the branch (optional).
183
- persist_path (PATH_TYPE): The path to persist the branch data (optional).
182
+ persist_path (str | Path): The path to persist the branch data (optional).
184
183
  tool_manager (ToolManager): The tool manager for the branch (optional).
185
184
  read_kwargs: Additional keyword arguments for reading the CSV file (optional).
186
185
  **kwargs: Additional keyword arguments.
@@ -211,7 +210,7 @@ class Branch(BaseBranch, BranchFlowMixin):
211
210
  llmconfig: dict[str, str | int | dict] | None = None,
212
211
  tools: TOOL_TYPE | None = None,
213
212
  datalogger: None | DataLogger = None,
214
- persist_path: PATH_TYPE | None = None, # instruction_sets=None,
213
+ persist_path: str | Path | None = None, # instruction_sets=None,
215
214
  tool_manager: ToolManager | None = None,
216
215
  read_kwargs=None,
217
216
  **kwargs,
@@ -226,7 +225,7 @@ class Branch(BaseBranch, BranchFlowMixin):
226
225
  llmconfig (dict[str, str | int | dict]): The configuration for the language model (optional).
227
226
  tools (TOOL_TYPE): The tools to register in the branch (optional).
228
227
  datalogger (DataLogger): The data logger for the branch (optional).
229
- persist_path (PATH_TYPE): The path to persist the branch data (optional).
228
+ persist_path (str | Path): The path to persist the branch data (optional).
230
229
  tool_manager (ToolManager): The tool manager for the branch (optional).
231
230
  read_kwargs: Additional keyword arguments for reading the JSON string file (optional).
232
231
  **kwargs: Additional keyword arguments.
@@ -348,7 +347,7 @@ class Branch(BaseBranch, BranchFlowMixin):
348
347
  print("tools deletion failed")
349
348
  return False
350
349
 
351
- def send(self, recipient: str, category: str, package: Any) -> None:
350
+ def send(self, recipient_id: str, category: str, package: Any) -> None:
352
351
  """
353
352
  Sends a mail to a recipient.
354
353
 
@@ -357,10 +356,13 @@ class Branch(BaseBranch, BranchFlowMixin):
357
356
  category (str): The category of the mail.
358
357
  package (Any): The package to send in the mail.
359
358
  """
360
- mail_ = BaseMail(
361
- sender=self.sender, recipient=recipient, category=category, package=package
359
+ mail = BaseMail(
360
+ sender_id=self.id_,
361
+ recipient_id=recipient_id,
362
+ category=category,
363
+ package=package,
362
364
  )
363
- self.pending_outs.append(mail_)
365
+ self.pending_outs.append(mail)
364
366
 
365
367
  def receive(
366
368
  self,
@@ -468,4 +470,4 @@ class Branch(BaseBranch, BranchFlowMixin):
468
470
  }:
469
471
  return True
470
472
  except Exception:
471
- return False
473
+ return False
@@ -1,9 +1,9 @@
1
1
  from abc import ABC
2
2
  from typing import Any, Optional, Union, TypeVar
3
3
 
4
- from ..schema import TOOL_TYPE, Tool
5
- from ..messages import Instruction, System
6
- from ..flow.monoflow import MonoChat, MonoFollowup, MonoReAct
4
+ from lionagi.core.tool import Tool, TOOL_TYPE
5
+ from lionagi.core.messages.schema import Instruction, System
6
+ from lionagi.core.flow.monoflow import MonoChat, MonoFollowup, MonoReAct
7
7
 
8
8
  T = TypeVar("T", bound=Tool)
9
9
 
@@ -20,7 +20,7 @@ class BranchFlowMixin(ABC):
20
20
  out: bool = True,
21
21
  invoke: bool = True,
22
22
  output_fields=None,
23
- prompt_template=None,
23
+ form=None,
24
24
  **kwargs,
25
25
  ) -> Any:
26
26
  flow = MonoChat(self)
@@ -33,7 +33,7 @@ class BranchFlowMixin(ABC):
33
33
  out=out,
34
34
  invoke=invoke,
35
35
  output_fields=output_fields,
36
- prompt_template=prompt_template,
36
+ form=form,
37
37
  **kwargs,
38
38
  )
39
39
 
@@ -93,4 +93,4 @@ class BranchFlowMixin(ABC):
93
93
  output_prompt=output_prompt,
94
94
  out=out,
95
95
  **kwargs,
96
- )
96
+ )
@@ -320,4 +320,4 @@ class MessageUtil:
320
320
  else:
321
321
  with contextlib.suppress(Exception):
322
322
  answers.append(nested.nget(content, ["system_info"]))
323
- return "\n".join(answers)
323
+ return "\n".join(answers)
@@ -7,4 +7,13 @@ from .plan import plan
7
7
  from .cot import chain_of_thoughts, chain_of_react
8
8
 
9
9
 
10
- __all__ = ["predict", "select", "score", "vote", "react", "plan", "chain_of_thoughts", "chain_of_react"]
10
+ __all__ = [
11
+ "predict",
12
+ "select",
13
+ "score",
14
+ "vote",
15
+ "react",
16
+ "plan",
17
+ "chain_of_thoughts",
18
+ "chain_of_react",
19
+ ]
@@ -1,10 +1,8 @@
1
- from typing import Callable
2
1
  from lionagi.libs import convert
3
- from ..tool import func_to_tool
4
- from ..schema import Tool
5
- from .predict import predict
6
- from .plan import plan
7
- from .react import react
2
+
3
+ from lionagi.core.direct.predict import predict
4
+ from lionagi.core.direct.plan import plan
5
+ from lionagi.core.direct.react import react
8
6
 
9
7
  from .utils import _process_tools
10
8
 
@@ -18,37 +16,56 @@ async def chain_of_thoughts(
18
16
  num_steps=3,
19
17
  directive_kwargs={},
20
18
  return_branch=False,
21
- **kwargs
19
+ **kwargs,
22
20
  ):
23
-
21
+
24
22
  out_, outs, answer, reasons, confidence_score = "", [], "", [], 0
25
23
  if branch is not None:
26
- out_ = await plan(sentence, branch=branch, instruction=instruction, num_steps=num_steps, **kwargs)
24
+ out_ = await plan(
25
+ sentence,
26
+ branch=branch,
27
+ instruction=instruction,
28
+ num_steps=num_steps,
29
+ **kwargs,
30
+ )
27
31
  else:
28
- out_, branch = await plan(sentence, instruction=instruction, branch=branch, num_steps=num_steps, return_branch=True, **kwargs)
29
-
32
+ out_, branch = await plan(
33
+ sentence,
34
+ instruction=instruction,
35
+ branch=branch,
36
+ num_steps=num_steps,
37
+ return_branch=True,
38
+ **kwargs,
39
+ )
40
+
30
41
  for i in range(len(out_.plan)):
31
- _out = await predict(branch=branch, instruction=out_.plan[f"step_{i+1}"], reason=reason, confidence_score=confidence_score, **directive_kwargs)
42
+ _out = await predict(
43
+ branch=branch,
44
+ instruction=out_.plan[f"step_{i+1}"],
45
+ reason=reason,
46
+ confidence_score=confidence_score,
47
+ **directive_kwargs,
48
+ )
32
49
  answer += _out.answer
33
50
  if reason:
34
51
  reasons.append(_out.reason)
35
52
  if confidence_score:
36
53
  confidence_score += _out.confidence_score
37
54
  outs.append(_out)
38
-
55
+
39
56
  setattr(out_, "chain_output", outs)
40
57
  setattr(out_, "chain_answer", answer)
41
-
58
+
42
59
  if reason:
43
60
  setattr(out_, "chain_reasons", reasons)
44
61
  if confidence_score:
45
- setattr(out_, "chain_confidence_score", confidence_score/len(outs))
46
-
62
+ setattr(out_, "chain_confidence_score", confidence_score / len(outs))
63
+
47
64
  if return_branch:
48
65
  return out_, branch
49
-
66
+
50
67
  return out_
51
-
68
+
52
69
 
53
70
  async def chain_of_react(
54
71
  sentence=None,
@@ -59,24 +76,42 @@ async def chain_of_react(
59
76
  directive_system=None,
60
77
  directive_kwargs={},
61
78
  return_branch=False,
62
- **kwargs
79
+ **kwargs,
63
80
  ):
64
81
  out_, outs, reasons, actions, action_responses = "", [], [], [], []
65
82
  if branch is not None:
66
- out_ = await plan(sentence, branch=branch, instruction=instruction, num_steps=num_steps, **kwargs)
83
+ out_ = await plan(
84
+ sentence,
85
+ branch=branch,
86
+ instruction=instruction,
87
+ num_steps=num_steps,
88
+ **kwargs,
89
+ )
67
90
  else:
68
- out_, branch = await plan(sentence, instruction=instruction, branch=branch, num_steps=num_steps, return_branch=True, **kwargs)
69
-
91
+ out_, branch = await plan(
92
+ sentence,
93
+ instruction=instruction,
94
+ branch=branch,
95
+ num_steps=num_steps,
96
+ return_branch=True,
97
+ **kwargs,
98
+ )
99
+
70
100
  _process_tools(tools, branch)
71
-
101
+
72
102
  for i in range(len(out_.plan)):
73
- _out = await react(branch=branch, system=directive_system, instruction=out_.plan[f"step_{i+1}"], **directive_kwargs)
103
+ _out = await react(
104
+ branch=branch,
105
+ system=directive_system,
106
+ instruction=out_.plan[f"step_{i+1}"],
107
+ **directive_kwargs,
108
+ )
74
109
  outs.append(_out)
75
110
  reasons.append(_out.reason)
76
111
  actions.append(_out.actions)
77
112
  if _out.action_needed:
78
113
  action_responses.append(_out.action_response)
79
-
114
+
80
115
  setattr(out_, "chain_output", convert.to_list(outs))
81
116
  setattr(out_, "chain_reason", convert.to_list(reasons))
82
117
  setattr(out_, "chain_actions", convert.to_list(actions))
@@ -84,5 +119,5 @@ async def chain_of_react(
84
119
 
85
120
  if return_branch:
86
121
  return out_, branch
87
-
122
+
88
123
  return out_
@@ -2,18 +2,20 @@
2
2
 
3
3
  from lionagi.libs import func_call, ParseUtil
4
4
  from lionagi.integrations.bridge.pydantic_.pydantic_bridge import Field
5
- from ..prompt.scored_template import ScoredTemplate
6
- from ..branch import Branch
5
+ from lionagi.core.form.scored_form import ScoredForm
6
+ from lionagi.core.branch.branch import Branch
7
7
 
8
8
 
9
- class PlanTemplate(ScoredTemplate):
9
+ class PlanTemplate(ScoredForm):
10
10
  template_name: str = "default_plan"
11
11
  sentence: str | list | dict = Field(
12
12
  default_factory=str,
13
13
  description="the given sentence(s) or context to generate a plan for",
14
14
  )
15
- plan: dict | str= Field(
16
- default_factory=dict, description="the generated step by step plan, return as a dictionary following {step_n: {plan: ..., reason: ...}} format")
15
+ plan: dict | str = Field(
16
+ default_factory=dict,
17
+ description="the generated step by step plan, return as a dictionary following {step_n: {plan: ..., reason: ...}} format",
18
+ )
17
19
  signature: str = "sentence -> plan"
18
20
 
19
21
  def __init__(
@@ -89,7 +91,7 @@ async def _plan(
89
91
 
90
92
  await func_call.rcall(
91
93
  branch.chat,
92
- prompt_template=_template,
94
+ form=_template,
93
95
  retries=retries,
94
96
  delay=delay,
95
97
  backoff_factor=backoff_factor,
@@ -97,7 +99,7 @@ async def _plan(
97
99
  timeout=timeout,
98
100
  **kwargs,
99
101
  )
100
-
102
+
101
103
  _template.plan = ParseUtil.fuzzy_parse_json(_template.plan)
102
104
 
103
105
  return (_template, branch) if return_branch else _template
@@ -159,4 +161,4 @@ async def plan(
159
161
  return await _inner()
160
162
 
161
163
  elif num_instances > 1:
162
- return await func_call.alcall(range(num_instances), _inner)
164
+ return await func_call.alcall(range(num_instances), _inner)
@@ -9,11 +9,11 @@ confidence score, and reason for the prediction.
9
9
  from lionagi.libs import func_call
10
10
  from lionagi.integrations.bridge.pydantic_.pydantic_bridge import Field
11
11
 
12
- from ..prompt.scored_template import ScoredTemplate
13
- from ..branch import Branch
12
+ from lionagi.core.form.scored_form import ScoredForm
13
+ from lionagi.core.branch.branch import Branch
14
14
 
15
15
 
16
- class PredictTemplate(ScoredTemplate):
16
+ class PredictTemplate(ScoredForm):
17
17
  """
18
18
  A class for predicting the next sentence(s) based on a given sentence.
19
19
 
@@ -68,7 +68,7 @@ class PredictTemplate(ScoredTemplate):
68
68
  """
69
69
  super().__init__(**kwargs)
70
70
 
71
- self.sentence = sentence or ''
71
+ self.sentence = sentence or ""
72
72
  self.num_sentences = num_sentences
73
73
  self.task = f"follow instruction to predict the next {self.num_sentences} sentence(s). Instruction: {instruction}."
74
74
 
@@ -154,7 +154,7 @@ async def predict(
154
154
 
155
155
  await func_call.rcall(
156
156
  branch.chat,
157
- prompt_template=predict_template,
157
+ form=predict_template,
158
158
  retries=retries,
159
159
  delay=delay,
160
160
  backoff_factor=backoff_factor,
@@ -1,14 +1,14 @@
1
- from lionagi.libs import func_call, convert, AsyncUtil
1
+ from lionagi.libs import func_call, AsyncUtil
2
2
 
3
3
  from lionagi.integrations.bridge.pydantic_.pydantic_bridge import Field
4
- from ..prompt.action_template import ActionedTemplate
5
- from ..branch import Branch
6
- from .utils import _process_tools
4
+ from lionagi.core.form.action_form import ActionForm
5
+ from lionagi.core.branch.branch import Branch
6
+ from lionagi.core.direct.utils import _process_tools
7
7
 
8
8
 
9
- class ReactTemplate(ActionedTemplate):
9
+ class ReactTemplate(ActionForm):
10
10
  template_name: str = "default_react"
11
- sentence: str | list | dict | None= Field(
11
+ sentence: str | list | dict | None = Field(
12
12
  default_factory=str,
13
13
  description="the given sentence(s) to reason and take actions on",
14
14
  )
@@ -61,7 +61,7 @@ async def _react(
61
61
 
62
62
  if branch and tools:
63
63
  _process_tools(tools, branch)
64
-
64
+
65
65
  branch = branch or Branch(
66
66
  name=branch_name,
67
67
  system=system,
@@ -83,7 +83,7 @@ async def _react(
83
83
 
84
84
  await func_call.rcall(
85
85
  branch.chat,
86
- prompt_template=_template,
86
+ form=_template,
87
87
  retries=retries,
88
88
  delay=delay,
89
89
  backoff_factor=backoff_factor,
@@ -12,11 +12,11 @@ ScoreTemplate class and a language model.
12
12
  from pydantic import Field
13
13
  import numpy as np
14
14
  from lionagi.libs import func_call, convert
15
- from ..prompt.scored_template import ScoredTemplate
16
- from ..branch import Branch
15
+ from lionagi.core.form.scored_form import ScoredForm
16
+ from lionagi.core.branch.branch import Branch
17
17
 
18
18
 
19
- class ScoreTemplate(ScoredTemplate):
19
+ class ScoreTemplate(ScoredForm):
20
20
  """
21
21
  A class for scoring a given context using a language model.
22
22
 
@@ -169,7 +169,7 @@ async def _score(
169
169
 
170
170
  await func_call.rcall(
171
171
  branch.chat,
172
- prompt_template=_template,
172
+ form=_template,
173
173
  retries=retries,
174
174
  delay=delay,
175
175
  backoff_factor=backoff_factor,