lionagi 0.1.2__py3-none-any.whl → 0.2.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. lionagi/__init__.py +60 -5
  2. lionagi/core/__init__.py +0 -25
  3. lionagi/core/_setting/_setting.py +59 -0
  4. lionagi/core/action/__init__.py +14 -0
  5. lionagi/core/action/function_calling.py +136 -0
  6. lionagi/core/action/manual.py +1 -0
  7. lionagi/core/action/node.py +109 -0
  8. lionagi/core/action/tool.py +114 -0
  9. lionagi/core/action/tool_manager.py +356 -0
  10. lionagi/core/agent/base_agent.py +27 -13
  11. lionagi/core/agent/eval/evaluator.py +1 -0
  12. lionagi/core/agent/eval/vote.py +40 -0
  13. lionagi/core/agent/learn/learner.py +59 -0
  14. lionagi/core/agent/plan/unit_template.py +1 -0
  15. lionagi/core/collections/__init__.py +17 -0
  16. lionagi/core/{generic/data_logger.py → collections/_logger.py} +69 -55
  17. lionagi/core/collections/abc/__init__.py +53 -0
  18. lionagi/core/collections/abc/component.py +615 -0
  19. lionagi/core/collections/abc/concepts.py +297 -0
  20. lionagi/core/collections/abc/exceptions.py +150 -0
  21. lionagi/core/collections/abc/util.py +45 -0
  22. lionagi/core/collections/exchange.py +161 -0
  23. lionagi/core/collections/flow.py +426 -0
  24. lionagi/core/collections/model.py +419 -0
  25. lionagi/core/collections/pile.py +913 -0
  26. lionagi/core/collections/progression.py +236 -0
  27. lionagi/core/collections/util.py +64 -0
  28. lionagi/core/director/direct.py +314 -0
  29. lionagi/core/director/director.py +2 -0
  30. lionagi/core/{execute/branch_executor.py → engine/branch_engine.py} +134 -97
  31. lionagi/core/{execute/instruction_map_executor.py → engine/instruction_map_engine.py} +80 -55
  32. lionagi/{experimental/directive/evaluator → core/engine}/script_engine.py +17 -1
  33. lionagi/core/executor/base_executor.py +90 -0
  34. lionagi/core/{execute/structure_executor.py → executor/graph_executor.py} +62 -66
  35. lionagi/core/{execute → executor}/neo4j_executor.py +70 -67
  36. lionagi/core/generic/__init__.py +3 -33
  37. lionagi/core/generic/edge.py +29 -79
  38. lionagi/core/generic/edge_condition.py +16 -0
  39. lionagi/core/generic/graph.py +236 -0
  40. lionagi/core/generic/hyperedge.py +1 -0
  41. lionagi/core/generic/node.py +156 -221
  42. lionagi/core/generic/tree.py +48 -0
  43. lionagi/core/generic/tree_node.py +79 -0
  44. lionagi/core/mail/__init__.py +12 -0
  45. lionagi/core/mail/mail.py +25 -0
  46. lionagi/core/mail/mail_manager.py +139 -58
  47. lionagi/core/mail/package.py +45 -0
  48. lionagi/core/mail/start_mail.py +36 -0
  49. lionagi/core/message/__init__.py +19 -0
  50. lionagi/core/message/action_request.py +133 -0
  51. lionagi/core/message/action_response.py +135 -0
  52. lionagi/core/message/assistant_response.py +95 -0
  53. lionagi/core/message/instruction.py +234 -0
  54. lionagi/core/message/message.py +101 -0
  55. lionagi/core/message/system.py +86 -0
  56. lionagi/core/message/util.py +283 -0
  57. lionagi/core/report/__init__.py +4 -0
  58. lionagi/core/report/base.py +217 -0
  59. lionagi/core/report/form.py +231 -0
  60. lionagi/core/report/report.py +166 -0
  61. lionagi/core/report/util.py +28 -0
  62. lionagi/core/rule/_default.py +16 -0
  63. lionagi/core/rule/action.py +99 -0
  64. lionagi/core/rule/base.py +238 -0
  65. lionagi/core/rule/boolean.py +56 -0
  66. lionagi/core/rule/choice.py +47 -0
  67. lionagi/core/rule/mapping.py +96 -0
  68. lionagi/core/rule/number.py +71 -0
  69. lionagi/core/rule/rulebook.py +109 -0
  70. lionagi/core/rule/string.py +52 -0
  71. lionagi/core/rule/util.py +35 -0
  72. lionagi/core/session/branch.py +431 -0
  73. lionagi/core/session/directive_mixin.py +287 -0
  74. lionagi/core/session/session.py +229 -903
  75. lionagi/core/structure/__init__.py +1 -0
  76. lionagi/core/structure/chain.py +1 -0
  77. lionagi/core/structure/forest.py +1 -0
  78. lionagi/core/structure/graph.py +1 -0
  79. lionagi/core/structure/tree.py +1 -0
  80. lionagi/core/unit/__init__.py +5 -0
  81. lionagi/core/unit/parallel_unit.py +245 -0
  82. lionagi/core/unit/template/action.py +81 -0
  83. lionagi/core/unit/template/base.py +51 -0
  84. lionagi/core/unit/template/plan.py +84 -0
  85. lionagi/core/unit/template/predict.py +109 -0
  86. lionagi/core/unit/template/score.py +124 -0
  87. lionagi/core/unit/template/select.py +104 -0
  88. lionagi/core/unit/unit.py +362 -0
  89. lionagi/core/unit/unit_form.py +305 -0
  90. lionagi/core/unit/unit_mixin.py +1168 -0
  91. lionagi/core/unit/util.py +71 -0
  92. lionagi/core/validator/validator.py +364 -0
  93. lionagi/core/work/work.py +76 -0
  94. lionagi/core/work/work_function.py +101 -0
  95. lionagi/core/work/work_queue.py +103 -0
  96. lionagi/core/work/worker.py +258 -0
  97. lionagi/core/work/worklog.py +120 -0
  98. lionagi/experimental/compressor/base.py +46 -0
  99. lionagi/experimental/compressor/llm_compressor.py +247 -0
  100. lionagi/experimental/compressor/llm_summarizer.py +61 -0
  101. lionagi/experimental/compressor/util.py +70 -0
  102. lionagi/experimental/directive/__init__.py +19 -0
  103. lionagi/experimental/directive/parser/base_parser.py +69 -2
  104. lionagi/experimental/directive/{template_ → template}/base_template.py +17 -1
  105. lionagi/{libs/ln_tokenizer.py → experimental/directive/tokenizer.py} +16 -0
  106. lionagi/experimental/{directive/evaluator → evaluator}/ast_evaluator.py +16 -0
  107. lionagi/experimental/{directive/evaluator → evaluator}/base_evaluator.py +16 -0
  108. lionagi/experimental/knowledge/base.py +10 -0
  109. lionagi/experimental/memory/__init__.py +0 -0
  110. lionagi/experimental/strategies/__init__.py +0 -0
  111. lionagi/experimental/strategies/base.py +1 -0
  112. lionagi/integrations/bridge/langchain_/documents.py +4 -0
  113. lionagi/integrations/bridge/llamaindex_/index.py +30 -0
  114. lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +6 -0
  115. lionagi/integrations/chunker/chunk.py +161 -24
  116. lionagi/integrations/config/oai_configs.py +34 -3
  117. lionagi/integrations/config/openrouter_configs.py +14 -2
  118. lionagi/integrations/loader/load.py +122 -21
  119. lionagi/integrations/loader/load_util.py +6 -77
  120. lionagi/integrations/provider/_mapping.py +46 -0
  121. lionagi/integrations/provider/litellm.py +2 -1
  122. lionagi/integrations/provider/mlx_service.py +16 -9
  123. lionagi/integrations/provider/oai.py +91 -4
  124. lionagi/integrations/provider/ollama.py +6 -5
  125. lionagi/integrations/provider/openrouter.py +115 -8
  126. lionagi/integrations/provider/services.py +2 -2
  127. lionagi/integrations/provider/transformers.py +18 -22
  128. lionagi/integrations/storage/__init__.py +3 -3
  129. lionagi/integrations/storage/neo4j.py +52 -60
  130. lionagi/integrations/storage/storage_util.py +44 -46
  131. lionagi/integrations/storage/structure_excel.py +43 -26
  132. lionagi/integrations/storage/to_excel.py +11 -4
  133. lionagi/libs/__init__.py +22 -1
  134. lionagi/libs/ln_api.py +75 -20
  135. lionagi/libs/ln_context.py +37 -0
  136. lionagi/libs/ln_convert.py +21 -9
  137. lionagi/libs/ln_func_call.py +69 -28
  138. lionagi/libs/ln_image.py +107 -0
  139. lionagi/libs/ln_nested.py +26 -11
  140. lionagi/libs/ln_parse.py +82 -23
  141. lionagi/libs/ln_queue.py +16 -0
  142. lionagi/libs/ln_tokenize.py +164 -0
  143. lionagi/libs/ln_validate.py +16 -0
  144. lionagi/libs/special_tokens.py +172 -0
  145. lionagi/libs/sys_util.py +95 -24
  146. lionagi/lions/coder/code_form.py +13 -0
  147. lionagi/lions/coder/coder.py +50 -3
  148. lionagi/lions/coder/util.py +30 -25
  149. lionagi/tests/libs/test_func_call.py +23 -21
  150. lionagi/tests/libs/test_nested.py +36 -21
  151. lionagi/tests/libs/test_parse.py +1 -1
  152. lionagi/tests/test_core/collections/__init__.py +0 -0
  153. lionagi/tests/test_core/collections/test_component.py +206 -0
  154. lionagi/tests/test_core/collections/test_exchange.py +138 -0
  155. lionagi/tests/test_core/collections/test_flow.py +145 -0
  156. lionagi/tests/test_core/collections/test_pile.py +171 -0
  157. lionagi/tests/test_core/collections/test_progression.py +129 -0
  158. lionagi/tests/test_core/generic/test_edge.py +67 -0
  159. lionagi/tests/test_core/generic/test_graph.py +96 -0
  160. lionagi/tests/test_core/generic/test_node.py +106 -0
  161. lionagi/tests/test_core/generic/test_tree_node.py +73 -0
  162. lionagi/tests/test_core/test_branch.py +115 -294
  163. lionagi/tests/test_core/test_form.py +46 -0
  164. lionagi/tests/test_core/test_report.py +105 -0
  165. lionagi/tests/test_core/test_validator.py +111 -0
  166. lionagi/version.py +1 -1
  167. lionagi-0.2.1.dist-info/LICENSE +202 -0
  168. lionagi-0.2.1.dist-info/METADATA +272 -0
  169. lionagi-0.2.1.dist-info/RECORD +240 -0
  170. lionagi/core/branch/base.py +0 -653
  171. lionagi/core/branch/branch.py +0 -474
  172. lionagi/core/branch/flow_mixin.py +0 -96
  173. lionagi/core/branch/util.py +0 -323
  174. lionagi/core/direct/__init__.py +0 -19
  175. lionagi/core/direct/cot.py +0 -123
  176. lionagi/core/direct/plan.py +0 -164
  177. lionagi/core/direct/predict.py +0 -166
  178. lionagi/core/direct/react.py +0 -171
  179. lionagi/core/direct/score.py +0 -279
  180. lionagi/core/direct/select.py +0 -170
  181. lionagi/core/direct/sentiment.py +0 -1
  182. lionagi/core/direct/utils.py +0 -110
  183. lionagi/core/direct/vote.py +0 -64
  184. lionagi/core/execute/base_executor.py +0 -47
  185. lionagi/core/flow/baseflow.py +0 -23
  186. lionagi/core/flow/monoflow/ReAct.py +0 -240
  187. lionagi/core/flow/monoflow/__init__.py +0 -9
  188. lionagi/core/flow/monoflow/chat.py +0 -95
  189. lionagi/core/flow/monoflow/chat_mixin.py +0 -253
  190. lionagi/core/flow/monoflow/followup.py +0 -215
  191. lionagi/core/flow/polyflow/__init__.py +0 -1
  192. lionagi/core/flow/polyflow/chat.py +0 -251
  193. lionagi/core/form/action_form.py +0 -26
  194. lionagi/core/form/field_validator.py +0 -287
  195. lionagi/core/form/form.py +0 -302
  196. lionagi/core/form/mixin.py +0 -214
  197. lionagi/core/form/scored_form.py +0 -13
  198. lionagi/core/generic/action.py +0 -26
  199. lionagi/core/generic/component.py +0 -532
  200. lionagi/core/generic/condition.py +0 -46
  201. lionagi/core/generic/mail.py +0 -90
  202. lionagi/core/generic/mailbox.py +0 -36
  203. lionagi/core/generic/relation.py +0 -70
  204. lionagi/core/generic/signal.py +0 -22
  205. lionagi/core/generic/structure.py +0 -362
  206. lionagi/core/generic/transfer.py +0 -20
  207. lionagi/core/generic/work.py +0 -40
  208. lionagi/core/graph/graph.py +0 -126
  209. lionagi/core/graph/tree.py +0 -190
  210. lionagi/core/mail/schema.py +0 -63
  211. lionagi/core/messages/schema.py +0 -325
  212. lionagi/core/tool/__init__.py +0 -5
  213. lionagi/core/tool/tool.py +0 -28
  214. lionagi/core/tool/tool_manager.py +0 -283
  215. lionagi/experimental/report/form.py +0 -64
  216. lionagi/experimental/report/report.py +0 -138
  217. lionagi/experimental/report/util.py +0 -47
  218. lionagi/experimental/tool/function_calling.py +0 -43
  219. lionagi/experimental/tool/manual.py +0 -66
  220. lionagi/experimental/tool/schema.py +0 -59
  221. lionagi/experimental/tool/tool_manager.py +0 -138
  222. lionagi/experimental/tool/util.py +0 -16
  223. lionagi/experimental/validator/rule.py +0 -139
  224. lionagi/experimental/validator/validator.py +0 -56
  225. lionagi/experimental/work/__init__.py +0 -10
  226. lionagi/experimental/work/async_queue.py +0 -54
  227. lionagi/experimental/work/schema.py +0 -73
  228. lionagi/experimental/work/work_function.py +0 -67
  229. lionagi/experimental/work/worker.py +0 -56
  230. lionagi/experimental/work2/form.py +0 -371
  231. lionagi/experimental/work2/report.py +0 -289
  232. lionagi/experimental/work2/schema.py +0 -30
  233. lionagi/experimental/work2/tests.py +0 -72
  234. lionagi/experimental/work2/work_function.py +0 -89
  235. lionagi/experimental/work2/worker.py +0 -12
  236. lionagi/integrations/bridge/llamaindex_/get_index.py +0 -294
  237. lionagi/tests/test_core/generic/test_component.py +0 -89
  238. lionagi/tests/test_core/test_base_branch.py +0 -426
  239. lionagi/tests/test_core/test_chat_flow.py +0 -63
  240. lionagi/tests/test_core/test_mail_manager.py +0 -75
  241. lionagi/tests/test_core/test_prompts.py +0 -51
  242. lionagi/tests/test_core/test_session.py +0 -254
  243. lionagi/tests/test_core/test_session_base_util.py +0 -313
  244. lionagi/tests/test_core/test_tool_manager.py +0 -95
  245. lionagi-0.1.2.dist-info/LICENSE +0 -9
  246. lionagi-0.1.2.dist-info/METADATA +0 -174
  247. lionagi-0.1.2.dist-info/RECORD +0 -206
  248. /lionagi/core/{branch → _setting}/__init__.py +0 -0
  249. /lionagi/core/{execute → agent/eval}/__init__.py +0 -0
  250. /lionagi/core/{flow → agent/learn}/__init__.py +0 -0
  251. /lionagi/core/{form → agent/plan}/__init__.py +0 -0
  252. /lionagi/core/{branch/executable_branch.py → agent/plan/plan.py} +0 -0
  253. /lionagi/core/{graph → director}/__init__.py +0 -0
  254. /lionagi/core/{messages → engine}/__init__.py +0 -0
  255. /lionagi/{experimental/directive/evaluator → core/engine}/sandbox_.py +0 -0
  256. /lionagi/{experimental/directive/evaluator → core/executor}/__init__.py +0 -0
  257. /lionagi/{experimental/directive/template_ → core/rule}/__init__.py +0 -0
  258. /lionagi/{experimental/report → core/unit/template}/__init__.py +0 -0
  259. /lionagi/{experimental/tool → core/validator}/__init__.py +0 -0
  260. /lionagi/{experimental/validator → core/work}/__init__.py +0 -0
  261. /lionagi/experimental/{work2 → compressor}/__init__.py +0 -0
  262. /lionagi/{core/flow/mono_chat_mixin.py → experimental/directive/template/__init__.py} +0 -0
  263. /lionagi/experimental/directive/{schema.py → template/schema.py} +0 -0
  264. /lionagi/experimental/{work2/util.py → evaluator/__init__.py} +0 -0
  265. /lionagi/experimental/{work2/work.py → knowledge/__init__.py} +0 -0
  266. /lionagi/{tests/libs/test_async.py → experimental/knowledge/graph.py} +0 -0
  267. {lionagi-0.1.2.dist-info → lionagi-0.2.1.dist-info}/WHEEL +0 -0
  268. {lionagi-0.1.2.dist-info → lionagi-0.2.1.dist-info}/top_level.txt +0 -0
@@ -37,15 +37,15 @@ class Neo4j:
37
37
 
38
38
  Args:
39
39
  tx: The Neo4j transaction.
40
- node (dict): The properties of the node to be added, including 'id' and 'timestamp'.
40
+ node (dict): The properties of the node to be added, including 'ln_id' and 'timestamp'.
41
41
  name (str): The name of the structure, which is set on the node.
42
42
  """
43
43
  query = """
44
- MERGE (n:Structure:LionNode {id:$id})
44
+ MERGE (n:Structure:LionNode {ln_id:$ln_id})
45
45
  SET n.timestamp = $timestamp
46
46
  SET n.name = $name
47
47
  """
48
- await tx.run(query, id=node["id"], timestamp=node["timestamp"], name=name)
48
+ await tx.run(query, ln_id=node["ln_id"], timestamp=node["timestamp"], name=name)
49
49
  # heads=node['head_nodes'],
50
50
  # nodes=node['nodes'],
51
51
  # edges=node['edges'])
@@ -57,22 +57,18 @@ class Neo4j:
57
57
 
58
58
  Args:
59
59
  tx: The Neo4j transaction.
60
- node (dict): The properties of the system node including 'id', 'timestamp', 'content', 'sender', and 'recipient'.
60
+ node (dict): The properties of the system node including 'ln_id', 'timestamp', 'content', 'sender', and 'recipient'.
61
61
  """
62
62
  query = """
63
- MERGE (n:System:LionNode {id: $id})
63
+ MERGE (n:System:LionNode {ln_id: $ln_id})
64
64
  SET n.timestamp = $timestamp
65
65
  SET n.content = $content
66
- SET n.sender = $sender
67
- SET n.recipient = $recipient
68
66
  """
69
67
  await tx.run(
70
68
  query,
71
- id=node["id"],
69
+ ln_id=node["ln_id"],
72
70
  timestamp=node["timestamp"],
73
71
  content=node["content"],
74
- sender=node["sender"],
75
- recipient=node["recipient"],
76
72
  )
77
73
 
78
74
  @staticmethod
@@ -82,22 +78,18 @@ class Neo4j:
82
78
 
83
79
  Args:
84
80
  tx: The Neo4j transaction.
85
- node (dict): The properties of the instruction node including 'id', 'timestamp', 'content', 'sender', and 'recipient'.
81
+ node (dict): The properties of the instruction node including 'ln_id', 'timestamp', 'content', 'sender', and 'recipient'.
86
82
  """
87
83
  query = """
88
- MERGE (n:Instruction:LionNode {id: $id})
84
+ MERGE (n:Instruction:LionNode {ln_id: $ln_id})
89
85
  SET n.timestamp = $timestamp
90
86
  SET n.content = $content
91
- SET n.sender = $sender
92
- SET n.recipient = $recipient
93
87
  """
94
88
  await tx.run(
95
89
  query,
96
- id=node["id"],
90
+ ln_id=node["ln_id"],
97
91
  timestamp=node["timestamp"],
98
92
  content=node["content"],
99
- sender=node["sender"],
100
- recipient=node["recipient"],
101
93
  )
102
94
 
103
95
  # TODO: tool.manual
@@ -108,41 +100,41 @@ class Neo4j:
108
100
 
109
101
  Args:
110
102
  tx: The Neo4j transaction.
111
- node (dict): The properties of the tool node including 'id', 'timestamp', 'function', and 'parser'.
103
+ node (dict): The properties of the tool node including 'ln_id', 'timestamp', 'function', and 'parser'.
112
104
  """
113
105
  query = """
114
- MERGE (n:Tool:LionNode {id: $id})
106
+ MERGE (n:Tool:LionNode {ln_id: $ln_id})
115
107
  SET n.timestamp = $timestamp
116
108
  SET n.function = $function
117
109
  SET n.parser = $parser
118
110
  """
119
111
  await tx.run(
120
112
  query,
121
- id=node["id"],
113
+ ln_id=node["ln_id"],
122
114
  timestamp=node["timestamp"],
123
115
  function=node["function"],
124
116
  parser=node["parser"],
125
117
  )
126
118
 
127
119
  @staticmethod
128
- async def add_actionSelection_node(tx, node):
120
+ async def add_directiveSelection_node(tx, node):
129
121
  """
130
- Asynchronously adds an action selection node to the graph.
122
+ Asynchronously adds an directive selection node to the graph.
131
123
 
132
124
  Args:
133
125
  tx: The Neo4j transaction.
134
- node (dict): The properties of the action selection node including 'id', 'action', and 'actionKwargs'.
126
+ node (dict): The properties of the directive selection node including 'ln_id', 'directive', and 'directiveKwargs'.
135
127
  """
136
128
  query = """
137
- MERGE (n:ActionSelection:LionNode {id: $id})
138
- SET n.action = $action
139
- SET n.actionKwargs = $actionKwargs
129
+ MERGE (n:DirectiveSelection:LionNode {ln_id: $ln_id})
130
+ SET n.directive = $directive
131
+ SET n.directiveKwargs = $directiveKwargs
140
132
  """
141
133
  await tx.run(
142
134
  query,
143
- id=node["id"],
144
- action=node["action"],
145
- actionKwargs=node["action_kwargs"],
135
+ ln_id=node["ln_id"],
136
+ directive=node["directive"],
137
+ directiveKwargs=node["directive_kwargs"],
146
138
  )
147
139
 
148
140
  @staticmethod
@@ -152,17 +144,17 @@ class Neo4j:
152
144
 
153
145
  Args:
154
146
  tx: The Neo4j transaction.
155
- node (dict): The properties of the agent node including 'id', 'timestamp', 'structureId', and 'outputParser'.
147
+ node (dict): The properties of the agent node including 'ln_id', 'timestamp', 'structureId', and 'outputParser'.
156
148
  """
157
149
  query = """
158
- MERGE (n:Agent:LionNode {id:$id})
150
+ MERGE (n:Agent:LionNode {ln_id:$ln_id})
159
151
  SET n.timestamp = $timestamp
160
152
  SET n.structureId = $structureId
161
153
  SET n.outputParser = $outputParser
162
154
  """
163
155
  await tx.run(
164
156
  query,
165
- id=node["id"],
157
+ ln_id=node["ln_id"],
166
158
  timestamp=node["timestamp"],
167
159
  structureId=node["structure_id"],
168
160
  outputParser=node["output_parser"],
@@ -175,20 +167,20 @@ class Neo4j:
175
167
 
176
168
  Args:
177
169
  tx: The Neo4j transaction.
178
- edge (dict): The properties of the edge including 'id', 'timestamp', 'head', 'tail', 'label', and 'condition'.
170
+ edge (dict): The properties of the edge including 'ln_id', 'timestamp', 'head', 'tail', 'label', and 'condition'.
179
171
  """
180
172
  query = """
181
- MATCH (m:LionNode) WHERE m.id = $head
182
- MATCH (n:LionNode) WHERE n.id = $tail
173
+ MATCH (m:LionNode) WHERE m.ln_id = $head
174
+ MATCH (n:LionNode) WHERE n.ln_id = $tail
183
175
  MERGE (m)-[r:FORWARD]->(n)
184
- SET r.id = $id
176
+ SET r.ln_id = $ln_id
185
177
  SET r.timestamp = $timestamp
186
178
  SET r.label = $label
187
179
  SET r.condition = $condition
188
180
  """
189
181
  await tx.run(
190
182
  query,
191
- id=edge["id"],
183
+ ln_id=edge["ln_id"],
192
184
  timestamp=edge["timestamp"],
193
185
  head=edge["head"],
194
186
  tail=edge["tail"],
@@ -203,20 +195,20 @@ class Neo4j:
203
195
 
204
196
  Args:
205
197
  tx: The Neo4j transaction.
206
- edge (dict): The properties of the edge including 'id', 'timestamp', 'head', 'tail', 'label', and 'condition'.
198
+ edge (dict): The properties of the edge including 'ln_id', 'timestamp', 'head', 'tail', 'label', and 'condition'.
207
199
  """
208
200
  query = """
209
- MATCH (m:LionNode) WHERE m.id = $head
210
- MATCH (n:LionNode) WHERE n.id = $tail
201
+ MATCH (m:LionNode) WHERE m.ln_id = $head
202
+ MATCH (n:LionNode) WHERE n.ln_id = $tail
211
203
  MERGE (m)-[r:BUNDLE]->(n)
212
- SET r.id = $id
204
+ SET r.ln_id = $ln_id
213
205
  SET r.timestamp = $timestamp
214
206
  SET r.label = $label
215
207
  SET r.condition = $condition
216
208
  """
217
209
  await tx.run(
218
210
  query,
219
- id=edge["id"],
211
+ ln_id=edge["ln_id"],
220
212
  timestamp=edge["timestamp"],
221
213
  head=edge["head"],
222
214
  tail=edge["tail"],
@@ -234,13 +226,13 @@ class Neo4j:
234
226
  structure: The structure node from which head relationships are established.
235
227
  """
236
228
  for head in structure.get_heads():
237
- head_id = head.id_
229
+ head_id = head.ln_id
238
230
  query = """
239
- MATCH (m:Structure) WHERE m.id = $structureId
240
- MATCH (n:LionNode) WHERE n.id = $headId
231
+ MATCH (m:Structure) WHERE m.ln_id = $structureId
232
+ MATCH (n:LionNode) WHERE n.ln_id = $headId
241
233
  MERGE (m)-[:HEAD]->(n)
242
234
  """
243
- await tx.run(query, structureId=structure.id_, headId=head_id)
235
+ await tx.run(query, structureId=structure.ln_id, headId=head_id)
244
236
 
245
237
  @staticmethod
246
238
  async def add_single_condition_cls(tx, condCls):
@@ -252,7 +244,7 @@ class Neo4j:
252
244
  condCls (dict): The properties of the condition class node including 'className' and 'code'.
253
245
  """
254
246
  query = """
255
- MERGE (n:Condition:LionNode {className: $className})
247
+ MERGE (n:EdgeCondition:LionNode {className: $className})
256
248
  SET n.code = $code
257
249
  """
258
250
  await tx.run(query, className=condCls["class_name"], code=condCls["class"])
@@ -274,7 +266,7 @@ class Neo4j:
274
266
  """
275
267
  for node in node_dict:
276
268
  node_list = node_dict[node]
277
- if node == "StructureExecutor":
269
+ if node == "GraphExecutor":
278
270
  [
279
271
  await self.add_structure_node(tx, i, structure_name)
280
272
  for i in node_list
@@ -285,8 +277,8 @@ class Neo4j:
285
277
  [await self.add_instruction_node(tx, i) for i in node_list]
286
278
  elif node == "Tool":
287
279
  [await self.add_tool_node(tx, i) for i in node_list]
288
- elif node == "ActionSelection":
289
- [await self.add_actionSelection_node(tx, i) for i in node_list]
280
+ elif node == "DirectiveSelection":
281
+ [await self.add_directiveSelection_node(tx, i) for i in node_list]
290
282
  elif node == "BaseAgent":
291
283
  [await self.add_baseAgent_node(tx, i) for i in node_list]
292
284
  else:
@@ -335,7 +327,7 @@ class Neo4j:
335
327
  @staticmethod
336
328
  async def check_id_constraint(tx):
337
329
  """
338
- Asynchronously applies a unique constraint on the 'id' attribute for all nodes of type 'LionNode' in the graph.
330
+ Asynchronously applies a unique constraint on the 'ln_id' attribute for all nodes of type 'LionNode' in the graph.
339
331
 
340
332
  This constraint ensures that each node in the graph has a unique identifier.
341
333
 
@@ -344,7 +336,7 @@ class Neo4j:
344
336
  """
345
337
  query = """
346
338
  CREATE CONSTRAINT node_id IF NOT EXISTS
347
- FOR (n:LionNode) REQUIRE (n.id) IS UNIQUE
339
+ FOR (n:LionNode) REQUIRE (n.ln_id) IS UNIQUE
348
340
  """
349
341
  await tx.run(query)
350
342
 
@@ -421,10 +413,10 @@ class Neo4j:
421
413
  A dictionary containing the properties of the node if found, otherwise None.
422
414
  """
423
415
  query = """
424
- MATCH (n:LionNode) WHERE n.id = $id
416
+ MATCH (n:LionNode) WHERE n.ln_id = $ln_id
425
417
  RETURN labels(n), n{.*}
426
418
  """
427
- result = await tx.run(query, id=node_id)
419
+ result = await tx.run(query, ln_id=node_id)
428
420
  result = [record.values() async for record in result]
429
421
  if result:
430
422
  return result[0]
@@ -445,7 +437,7 @@ class Neo4j:
445
437
  """
446
438
  query = """
447
439
  MATCH (n:Structure) WHERE n.name = $name
448
- RETURN n.id
440
+ RETURN n.ln_id
449
441
  """
450
442
  result = await tx.run(query, name=name)
451
443
  result = [record.values() async for record in result]
@@ -465,7 +457,7 @@ class Neo4j:
465
457
  A list of dictionaries representing the properties and labels of each head node connected to the structure.
466
458
  """
467
459
  query = """
468
- MATCH (n:Structure)-[r:HEAD]->(m) WHERE n.id = $nodeId
460
+ MATCH (n:Structure)-[r:HEAD]->(m) WHERE n.ln_id = $nodeId
469
461
  RETURN r{.*}, labels(m), m{.*}
470
462
  """
471
463
  result = await tx.run(query, nodeId=node_id)
@@ -485,7 +477,7 @@ class Neo4j:
485
477
  A list of dictionaries representing the properties and labels of each node connected by a forward relationship.
486
478
  """
487
479
  query = """
488
- MATCH (n:LionNode)-[r:FORWARD]->(m) WHERE n.id = $nodeId
480
+ MATCH (n:LionNode)-[r:FORWARD]->(m) WHERE n.ln_id = $nodeId
489
481
  RETURN r{.*}, labels(m), m{.*}
490
482
  """
491
483
  result = await tx.run(query, nodeId=node_id)
@@ -505,7 +497,7 @@ class Neo4j:
505
497
  A list of dictionaries representing the properties and labels of each node connected by a bundle relationship.
506
498
  """
507
499
  query = """
508
- MATCH (n:LionNode)-[r:BUNDLE]->(m) WHERE n.id = $nodeId
500
+ MATCH (n:LionNode)-[r:BUNDLE]->(m) WHERE n.ln_id = $nodeId
509
501
  RETURN labels(m), m{.*}
510
502
  """
511
503
  result = await tx.run(query, nodeId=node_id)
@@ -525,7 +517,7 @@ class Neo4j:
525
517
  The code of the condition class if found, otherwise None.
526
518
  """
527
519
  query = """
528
- MATCH (n:Condition) WHERE n.className = $name
520
+ MATCH (n:EdgeCondition) WHERE n.className = $name
529
521
  RETURN n.code
530
522
  """
531
523
  result = await tx.run(query, name=name)
@@ -557,7 +549,7 @@ class Neo4j:
557
549
  to any existing structure.
558
550
  """
559
551
  if not structure_name and not structure_id:
560
- raise ValueError("Please provide the structure name or id")
552
+ raise ValueError("Please provide the structure name or ln_id")
561
553
  if structure_name:
562
554
  id = await self.match_structure_id(tx, structure_name)
563
555
  if not id:
@@ -2,13 +2,11 @@ import json
2
2
  import inspect
3
3
  import re
4
4
 
5
- from lionagi.core import System, Instruction
6
- from lionagi.core.tool import Tool
7
- from lionagi.core.generic.action import ActionSelection
5
+ from lionagi.core.message import System, Instruction, RoledMessage
6
+ from lionagi.core.action import Tool, DirectiveSelection, func_to_tool
7
+ from lionagi.core.action import DirectiveSelection
8
8
  from lionagi.core.agent.base_agent import BaseAgent
9
- from lionagi.core.generic.condition import Condition
10
-
11
- from lionagi.core import func_to_tool
9
+ from lionagi.core.generic.edge_condition import EdgeCondition
12
10
 
13
11
 
14
12
  def output_node_list(structure):
@@ -27,38 +25,42 @@ def output_node_list(structure):
27
25
  output = {}
28
26
 
29
27
  structure_output = {
30
- "id": structure.id_,
28
+ "ln_id": structure.ln_id,
31
29
  "timestamp": structure.timestamp,
32
30
  "type": structure.class_name,
33
31
  }
34
32
  summary_list.append(structure_output.copy())
35
- structure_output["head_nodes"] = json.dumps([i.id_ for i in structure.get_heads()])
33
+ structure_output["head_nodes"] = json.dumps(
34
+ [i.ln_id for i in structure.get_heads()]
35
+ )
36
36
  # structure_output['nodes'] = json.dumps([i for i in structure.internal_nodes.keys()])
37
37
  # structure_output['edges'] = json.dumps([i for i in structure.internal_edges.keys()])
38
38
  output[structure_output["type"]] = [structure_output]
39
39
  for node in structure.internal_nodes.values():
40
40
  node_output = {
41
- "id": node.id_,
41
+ "ln_id": node.ln_id,
42
42
  "timestamp": node.timestamp,
43
43
  "type": node.class_name,
44
44
  }
45
45
  summary_list.append(node_output.copy())
46
46
  if isinstance(node, System) or isinstance(node, Instruction):
47
47
  node_output["content"] = json.dumps(node.content)
48
- node_output["sender"] = node.sender
49
- node_output["recipient"] = node.recipient
48
+ # node_output["sender"] = node.sender
49
+ # node_output["recipient"] = node.recipient
50
50
  elif isinstance(node, Tool):
51
- node_output["function"] = inspect.getsource(node.func)
51
+ node_output["function"] = inspect.getsource(node.function)
52
52
  # node_output['manual'] = node.manual
53
53
  node_output["parser"] = (
54
54
  inspect.getsource(node.parser) if node.parser else None
55
55
  )
56
- elif isinstance(node, ActionSelection):
57
- node_output["action"] = node.action
58
- node_output["action_kwargs"] = json.dumps(node.action_kwargs)
56
+ elif isinstance(node, DirectiveSelection):
57
+ node_output["directive"] = node.directive
58
+ node_output["directive_kwargs"] = json.dumps(node.directive_kwargs)
59
59
  elif isinstance(node, BaseAgent):
60
- node_output["structure_id"] = node.structure.id_
61
- node_output["output_parser"] = inspect.getsource(node.output_parser)
60
+ node_output["structure_id"] = node.structure.ln_id
61
+ node_output["output_parser"] = (
62
+ inspect.getsource(node.output_parser) if node.output_parser else None
63
+ )
62
64
  else:
63
65
  raise ValueError("Not supported node type detected")
64
66
  if node_output["type"] not in output:
@@ -84,7 +86,7 @@ def output_edge_list(structure):
84
86
  edge_cls_dict = {}
85
87
  for edge in structure.internal_edges.values():
86
88
  edge_output = {
87
- "id": edge.id_,
89
+ "ln_id": edge.ln_id,
88
90
  "timestamp": edge.timestamp,
89
91
  "head": edge.head,
90
92
  "tail": edge.tail,
@@ -183,12 +185,8 @@ class ParseNode:
183
185
  Returns:
184
186
  System: An instantiated System node filled with properties from info_dict.
185
187
  """
186
- node = System(" ")
187
- node.id_ = info_dict["id"]
188
- node.timestamp = info_dict["timestamp"]
189
- node.content = json.loads(info_dict["content"])
190
- node.sender = info_dict["sender"]
191
- node.recipient = info_dict["recipient"]
188
+ info_dict["system"] = json.loads(info_dict.pop("content"))["system_info"]
189
+ node = System.from_obj(info_dict)
192
190
  return node
193
191
 
194
192
  @staticmethod
@@ -202,18 +200,14 @@ class ParseNode:
202
200
  Returns:
203
201
  Instruction: An instantiated Instruction node filled with properties from info_dict.
204
202
  """
205
- node = Instruction(" ")
206
- node.id_ = info_dict["id"]
207
- node.timestamp = info_dict["timestamp"]
208
- node.content = json.loads(info_dict["content"])
209
- node.sender = info_dict["sender"]
210
- node.recipient = info_dict["recipient"]
203
+ info_dict["instruction"] = json.loads(info_dict.pop("content"))["instruction"]
204
+ node = Instruction.from_obj(info_dict)
211
205
  return node
212
206
 
213
207
  @staticmethod
214
- def parse_actionSelection(info_dict):
208
+ def parse_directiveSelection(info_dict):
215
209
  """
216
- Parses dictionary information into an ActionSelection node object.
210
+ Parses dictionary information into an DirectiveSelection node object.
217
211
 
218
212
  Args:
219
213
  info_dict (dict): A dictionary containing properties of an action selection node.
@@ -221,15 +215,14 @@ class ParseNode:
221
215
  Returns:
222
216
  ActionSelection: An instantiated ActionSelection node filled with properties from info_dict.
223
217
  """
224
- node = ActionSelection()
225
- node.id_ = info_dict["id"]
226
- node.action = info_dict["action"]
227
- if "action_kwargs" in info_dict:
228
- if info_dict["action_kwargs"]:
229
- node.action_kwargs = json.loads(info_dict["action_kwargs"])
230
- elif "actionKwargs" in info_dict:
231
- if info_dict["actionKwargs"]:
232
- node.action_kwargs = json.loads(info_dict["actionKwargs"])
218
+ node = DirectiveSelection(ln_id=info_dict["ln_id"])
219
+ node.directive = info_dict["directive"]
220
+ if "directive_kwargs" in info_dict:
221
+ if info_dict["directive_kwargs"]:
222
+ node.directive_kwargs = json.loads(info_dict["directive_kwargs"])
223
+ elif "directiveKwargs" in info_dict:
224
+ if info_dict["directiveKwargs"]:
225
+ node.directive_kwargs = json.loads(info_dict["directiveKwargs"])
233
226
  return node
234
227
 
235
228
  @staticmethod
@@ -253,14 +246,19 @@ class ParseNode:
253
246
  )
254
247
 
255
248
  func = ParseNode.convert_to_def(func_code)
256
- tool = func_to_tool(func)
249
+ tool = func_to_tool(
250
+ func, ln_id=info_dict["ln_id"], timestamp=info_dict["timestamp"]
251
+ )
257
252
  if func.__doc__:
258
253
  if re.search(r":param \w+:", func.__doc__):
259
- tool = func_to_tool(func, docstring_style="reST")
254
+ tool = func_to_tool(
255
+ func,
256
+ docstring_style="reST",
257
+ ln_id=info_dict["ln_id"],
258
+ timestamp=info_dict["timestamp"],
259
+ )
260
260
 
261
261
  tool = tool[0]
262
- tool.id_ = info_dict["id"]
263
- tool.timestamp = info_dict["timestamp"]
264
262
  return tool
265
263
 
266
264
  @staticmethod
@@ -286,4 +284,4 @@ class ParseNode:
286
284
  if key == "self":
287
285
  continue
288
286
  init_params[key] = args[key]
289
- return cls(**init_params)
287
+ return cls(**init_params)
@@ -3,10 +3,10 @@ import json
3
3
  from pathlib import Path
4
4
 
5
5
  from lionagi.integrations.storage.storage_util import ParseNode
6
- from lionagi.core.execute.structure_executor import StructureExecutor
6
+ from lionagi.core.executor.graph_executor import GraphExecutor
7
7
  from lionagi.core.agent.base_agent import BaseAgent
8
- from lionagi.core.execute.base_executor import BaseExecutor
9
- from lionagi.core.execute.instruction_map_executor import InstructionMapExecutor
8
+ from lionagi.core.executor.base_executor import BaseExecutor
9
+ from lionagi.core.engine.instruction_map_engine import InstructionMapEngine
10
10
 
11
11
 
12
12
  def excel_reload(structure_name=None, structure_id=None, dir="structure_storage"):
@@ -52,10 +52,13 @@ class StructureExcel:
52
52
  parse(node_list, parent_node=None): Recursively parses nodes and their relationships from the structure.
53
53
  reload(): Reloads the structure from the Excel file based on the initially provided parameters.
54
54
  """
55
- structure: StructureExecutor = StructureExecutor()
56
- default_agent_executable: BaseExecutor = InstructionMapExecutor()
57
55
 
58
- def __init__(self, structure_name=None, structure_id=None, file_path="structure_storage"):
56
+ structure: GraphExecutor = GraphExecutor()
57
+ default_agent_executable: BaseExecutor = InstructionMapEngine()
58
+
59
+ def __init__(
60
+ self, structure_name=None, structure_id=None, file_path="structure_storage"
61
+ ):
59
62
  """
60
63
  Initializes the StructureExcel class with specified parameters.
61
64
 
@@ -91,7 +94,8 @@ class StructureExcel:
91
94
  continue
92
95
  if len(filename) > 1:
93
96
  raise ValueError(
94
- f"Multiple files starting with the same structure name {structure_name} has found, please specify the structure id")
97
+ f"Multiple files starting with the same structure name {structure_name} has found, please specify the structure id"
98
+ )
95
99
  self.filename = f"{file_path}/{filename[0]}"
96
100
  self.file = pd.read_excel(self.filename, sheet_name=None)
97
101
  elif structure_id and not structure_name:
@@ -100,7 +104,8 @@ class StructureExcel:
100
104
  filename = [file.name for file in files]
101
105
  if len(filename) > 1:
102
106
  raise ValueError(
103
- f"Multiple files with the same structure id {structure_id} has found, please double check the stored structure")
107
+ f"Multiple files with the same structure id {structure_id} has found, please double check the stored structure"
108
+ )
104
109
  self.filename = f"{file_path}/{filename[0]}"
105
110
  self.file = pd.read_excel(self.filename, sheet_name=None)
106
111
  self.nodes = self.file["Nodes"]
@@ -115,7 +120,7 @@ class StructureExcel:
115
120
  Returns:
116
121
  list: A list of identifiers for the head nodes in the structure.
117
122
  """
118
- structure_df = self.file["StructureExecutor"]
123
+ structure_df = self.file["GraphExecutor"]
119
124
  head_list = json.loads(structure_df["head_nodes"].iloc[0])
120
125
  return head_list
121
126
 
@@ -132,9 +137,9 @@ class StructureExcel:
132
137
  Returns:
133
138
  dict: A dictionary containing the properties and values for the specified node.
134
139
  """
135
- node_type = self.nodes[self.nodes["id"] == node_id]["type"].iloc[0]
140
+ node_type = self.nodes[self.nodes["ln_id"] == node_id]["type"].iloc[0]
136
141
  node_file = self.file[node_type]
137
- row = node_file[node_file["id"] == node_id].iloc[0]
142
+ row = node_file[node_file["ln_id"] == node_id].iloc[0]
138
143
  info_dict = row.to_dict()
139
144
  return info_dict
140
145
 
@@ -154,12 +159,18 @@ class StructureExcel:
154
159
  """
155
160
  output_parser = ParseNode.convert_to_def(info_dict["output_parser"])
156
161
 
157
- structure_excel = StructureExcel(structure_id=info_dict["structure_id"], file_path=self.file_path)
162
+ structure_excel = StructureExcel(
163
+ structure_id=info_dict["structure_id"], file_path=self.file_path
164
+ )
158
165
  structure_excel.reload()
159
166
  structure = structure_excel.structure
160
- agent = BaseAgent(structure=structure, executable=self.default_agent_executable, output_parser=output_parser)
161
- agent.id_ = info_dict["id"]
162
- agent.timestamp = info_dict["timestamp"]
167
+ agent = BaseAgent(
168
+ structure=structure,
169
+ executable=self.default_agent_executable,
170
+ output_parser=output_parser,
171
+ ln_id=info_dict["ln_id"],
172
+ timestamp=info_dict["timestamp"],
173
+ )
163
174
  return agent
164
175
 
165
176
  def parse_node(self, info_dict):
@@ -181,8 +192,8 @@ class StructureExcel:
181
192
  return ParseNode.parse_instruction(info_dict)
182
193
  elif info_dict["type"] == "Tool":
183
194
  return ParseNode.parse_tool(info_dict)
184
- elif info_dict["type"] == "ActionSelection":
185
- return ParseNode.parse_actionSelection(info_dict)
195
+ elif info_dict["type"] == "DirectiveSelection":
196
+ return ParseNode.parse_directiveSelection(info_dict)
186
197
  elif info_dict["type"] == "BaseAgent":
187
198
  return self.parse_agent(info_dict)
188
199
 
@@ -217,19 +228,25 @@ class StructureExcel:
217
228
  """
218
229
  if not parent_node:
219
230
  return
220
- row = self.edges[(self.edges["head"] == parent_node.id_) & (self.edges["tail"] == node.id_)]
231
+ row = self.edges[
232
+ (self.edges["head"] == parent_node.ln_id)
233
+ & (self.edges["tail"] == node.ln_id)
234
+ ]
221
235
  if len(row) > 1:
222
236
  raise ValueError(
223
- f"currently does not support handle multiple edges between two nodes, Error node: from {parent_node.id_} to {node.id_}")
224
- if row['condition'].isna().any():
225
- self.structure.relate_nodes(parent_node, node)
237
+ f"currently does not support handle multiple edges between two nodes, Error node: from {parent_node.ln_id} to {node.ln_id}"
238
+ )
239
+ if row["condition"].isna().any():
240
+ self.structure.add_edge(parent_node, node)
226
241
  else:
227
242
  cond = json.loads(row["condition"].iloc[0])
228
243
  cond_cls = cond["class"]
229
- cond_row = self.file["EdgesCondClass"][self.file["EdgesCondClass"]["class_name"] == cond_cls]
244
+ cond_row = self.file["EdgesCondClass"][
245
+ self.file["EdgesCondClass"]["class_name"] == cond_cls
246
+ ]
230
247
  cond_code = cond_row["class"].iloc[0]
231
248
  condition = ParseNode.parse_condition(cond, cond_code)
232
- self.structure.relate_nodes(parent_node, node, condition=condition)
249
+ self.structure.add_edge(parent_node, node, condition=condition)
233
250
 
234
251
  def parse(self, node_list, parent_node=None):
235
252
  """
@@ -249,7 +266,7 @@ class StructureExcel:
249
266
  info_dict = self._reload_info_dict(node_id)
250
267
  node = self.parse_node(info_dict)
251
268
 
252
- if node.id_ not in self.structure.internal_nodes:
269
+ if node.ln_id not in self.structure.internal_nodes:
253
270
  self.structure.add_node(node)
254
271
  self.relate(parent_node, node)
255
272
 
@@ -263,6 +280,6 @@ class StructureExcel:
263
280
  This method initializes a new StructureExecutor and uses the Excel data to rebuild the entire structure,
264
281
  starting from the head nodes and recursively parsing and connecting all nodes defined within.
265
282
  """
266
- self.structure = StructureExecutor()
283
+ self.structure = GraphExecutor()
267
284
  heads = self.get_heads()
268
- self.parse(heads)
285
+ self.parse(heads)