lionagi 0.1.1__py3-none-any.whl → 0.2.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) 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} +83 -67
  35. lionagi/core/{execute → executor}/neo4j_executor.py +70 -67
  36. lionagi/core/generic/__init__.py +3 -33
  37. lionagi/core/generic/edge.py +42 -92
  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 +74 -0
  94. lionagi/core/work/work_function.py +92 -0
  95. lionagi/core/work/work_queue.py +81 -0
  96. lionagi/core/work/worker.py +195 -0
  97. lionagi/core/work/worklog.py +124 -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/__init__.py +0 -0
  109. lionagi/experimental/knowledge/base.py +10 -0
  110. lionagi/experimental/knowledge/graph.py +0 -0
  111. lionagi/experimental/memory/__init__.py +0 -0
  112. lionagi/experimental/strategies/__init__.py +0 -0
  113. lionagi/experimental/strategies/base.py +1 -0
  114. lionagi/integrations/bridge/langchain_/documents.py +4 -0
  115. lionagi/integrations/bridge/llamaindex_/index.py +30 -0
  116. lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +6 -0
  117. lionagi/integrations/chunker/chunk.py +161 -24
  118. lionagi/integrations/config/oai_configs.py +34 -3
  119. lionagi/integrations/config/openrouter_configs.py +14 -2
  120. lionagi/integrations/loader/load.py +122 -21
  121. lionagi/integrations/loader/load_util.py +6 -77
  122. lionagi/integrations/provider/_mapping.py +46 -0
  123. lionagi/integrations/provider/litellm.py +2 -1
  124. lionagi/integrations/provider/mlx_service.py +16 -9
  125. lionagi/integrations/provider/oai.py +91 -4
  126. lionagi/integrations/provider/ollama.py +6 -5
  127. lionagi/integrations/provider/openrouter.py +115 -8
  128. lionagi/integrations/provider/services.py +2 -2
  129. lionagi/integrations/provider/transformers.py +18 -22
  130. lionagi/integrations/storage/__init__.py +3 -3
  131. lionagi/integrations/storage/neo4j.py +52 -60
  132. lionagi/integrations/storage/storage_util.py +45 -47
  133. lionagi/integrations/storage/structure_excel.py +285 -0
  134. lionagi/integrations/storage/to_excel.py +23 -7
  135. lionagi/libs/__init__.py +26 -1
  136. lionagi/libs/ln_api.py +75 -20
  137. lionagi/libs/ln_context.py +37 -0
  138. lionagi/libs/ln_convert.py +21 -9
  139. lionagi/libs/ln_func_call.py +69 -28
  140. lionagi/libs/ln_image.py +107 -0
  141. lionagi/libs/ln_nested.py +26 -11
  142. lionagi/libs/ln_parse.py +82 -23
  143. lionagi/libs/ln_queue.py +16 -0
  144. lionagi/libs/ln_tokenize.py +164 -0
  145. lionagi/libs/ln_validate.py +16 -0
  146. lionagi/libs/special_tokens.py +172 -0
  147. lionagi/libs/sys_util.py +95 -24
  148. lionagi/lions/coder/code_form.py +13 -0
  149. lionagi/lions/coder/coder.py +50 -3
  150. lionagi/lions/coder/util.py +30 -25
  151. lionagi/tests/libs/test_func_call.py +23 -21
  152. lionagi/tests/libs/test_nested.py +36 -21
  153. lionagi/tests/libs/test_parse.py +1 -1
  154. lionagi/tests/test_core/collections/__init__.py +0 -0
  155. lionagi/tests/test_core/collections/test_component.py +206 -0
  156. lionagi/tests/test_core/collections/test_exchange.py +138 -0
  157. lionagi/tests/test_core/collections/test_flow.py +145 -0
  158. lionagi/tests/test_core/collections/test_pile.py +171 -0
  159. lionagi/tests/test_core/collections/test_progression.py +129 -0
  160. lionagi/tests/test_core/generic/__init__.py +0 -0
  161. lionagi/tests/test_core/generic/test_edge.py +67 -0
  162. lionagi/tests/test_core/generic/test_graph.py +96 -0
  163. lionagi/tests/test_core/generic/test_node.py +106 -0
  164. lionagi/tests/test_core/generic/test_tree_node.py +73 -0
  165. lionagi/tests/test_core/test_branch.py +115 -294
  166. lionagi/tests/test_core/test_form.py +46 -0
  167. lionagi/tests/test_core/test_report.py +105 -0
  168. lionagi/tests/test_core/test_validator.py +111 -0
  169. lionagi/version.py +1 -1
  170. lionagi-0.2.0.dist-info/LICENSE +202 -0
  171. lionagi-0.2.0.dist-info/METADATA +272 -0
  172. lionagi-0.2.0.dist-info/RECORD +240 -0
  173. lionagi/core/branch/base.py +0 -653
  174. lionagi/core/branch/branch.py +0 -474
  175. lionagi/core/branch/flow_mixin.py +0 -96
  176. lionagi/core/branch/util.py +0 -323
  177. lionagi/core/direct/__init__.py +0 -19
  178. lionagi/core/direct/cot.py +0 -123
  179. lionagi/core/direct/plan.py +0 -164
  180. lionagi/core/direct/predict.py +0 -166
  181. lionagi/core/direct/react.py +0 -171
  182. lionagi/core/direct/score.py +0 -279
  183. lionagi/core/direct/select.py +0 -170
  184. lionagi/core/direct/sentiment.py +0 -1
  185. lionagi/core/direct/utils.py +0 -110
  186. lionagi/core/direct/vote.py +0 -64
  187. lionagi/core/execute/base_executor.py +0 -47
  188. lionagi/core/flow/baseflow.py +0 -23
  189. lionagi/core/flow/monoflow/ReAct.py +0 -238
  190. lionagi/core/flow/monoflow/__init__.py +0 -9
  191. lionagi/core/flow/monoflow/chat.py +0 -95
  192. lionagi/core/flow/monoflow/chat_mixin.py +0 -253
  193. lionagi/core/flow/monoflow/followup.py +0 -213
  194. lionagi/core/flow/polyflow/__init__.py +0 -1
  195. lionagi/core/flow/polyflow/chat.py +0 -251
  196. lionagi/core/form/action_form.py +0 -26
  197. lionagi/core/form/field_validator.py +0 -287
  198. lionagi/core/form/form.py +0 -302
  199. lionagi/core/form/mixin.py +0 -214
  200. lionagi/core/form/scored_form.py +0 -13
  201. lionagi/core/generic/action.py +0 -26
  202. lionagi/core/generic/component.py +0 -455
  203. lionagi/core/generic/condition.py +0 -44
  204. lionagi/core/generic/mail.py +0 -90
  205. lionagi/core/generic/mailbox.py +0 -36
  206. lionagi/core/generic/relation.py +0 -70
  207. lionagi/core/generic/signal.py +0 -22
  208. lionagi/core/generic/structure.py +0 -362
  209. lionagi/core/generic/transfer.py +0 -20
  210. lionagi/core/generic/work.py +0 -40
  211. lionagi/core/graph/graph.py +0 -126
  212. lionagi/core/graph/tree.py +0 -190
  213. lionagi/core/mail/schema.py +0 -63
  214. lionagi/core/messages/schema.py +0 -325
  215. lionagi/core/tool/__init__.py +0 -5
  216. lionagi/core/tool/tool.py +0 -28
  217. lionagi/core/tool/tool_manager.py +0 -282
  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/work/_logger.py +0 -25
  224. lionagi/experimental/work/schema.py +0 -30
  225. lionagi/experimental/work/tests.py +0 -72
  226. lionagi/experimental/work/work_function.py +0 -89
  227. lionagi/experimental/work/worker.py +0 -12
  228. lionagi/integrations/bridge/llamaindex_/get_index.py +0 -294
  229. lionagi/tests/test_core/test_base_branch.py +0 -426
  230. lionagi/tests/test_core/test_chat_flow.py +0 -63
  231. lionagi/tests/test_core/test_mail_manager.py +0 -75
  232. lionagi/tests/test_core/test_prompts.py +0 -51
  233. lionagi/tests/test_core/test_session.py +0 -254
  234. lionagi/tests/test_core/test_session_base_util.py +0 -313
  235. lionagi/tests/test_core/test_tool_manager.py +0 -95
  236. lionagi-0.1.1.dist-info/LICENSE +0 -9
  237. lionagi-0.1.1.dist-info/METADATA +0 -174
  238. lionagi-0.1.1.dist-info/RECORD +0 -190
  239. /lionagi/core/{branch → _setting}/__init__.py +0 -0
  240. /lionagi/core/{execute → agent/eval}/__init__.py +0 -0
  241. /lionagi/core/{flow → agent/learn}/__init__.py +0 -0
  242. /lionagi/core/{form → agent/plan}/__init__.py +0 -0
  243. /lionagi/core/{branch/executable_branch.py → agent/plan/plan.py} +0 -0
  244. /lionagi/core/{graph → director}/__init__.py +0 -0
  245. /lionagi/core/{messages → engine}/__init__.py +0 -0
  246. /lionagi/{experimental/directive/evaluator → core/engine}/sandbox_.py +0 -0
  247. /lionagi/{experimental/directive/evaluator → core/executor}/__init__.py +0 -0
  248. /lionagi/{experimental/directive/template_ → core/rule}/__init__.py +0 -0
  249. /lionagi/{experimental/tool → core/unit/template}/__init__.py +0 -0
  250. /lionagi/{experimental/work → core/validator}/__init__.py +0 -0
  251. /lionagi/core/{flow/mono_chat_mixin.py → work/__init__.py} +0 -0
  252. /lionagi/experimental/{work/exchange.py → compressor/__init__.py} +0 -0
  253. /lionagi/experimental/{work/util.py → directive/template/__init__.py} +0 -0
  254. /lionagi/experimental/directive/{schema.py → template/schema.py} +0 -0
  255. /lionagi/{tests/libs/test_async.py → experimental/evaluator/__init__.py} +0 -0
  256. {lionagi-0.1.1.dist-info → lionagi-0.2.0.dist-info}/WHEEL +0 -0
  257. {lionagi-0.1.1.dist-info → lionagi-0.2.0.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
- "type": structure.class_name(),
30
+ "type": structure.class_name,
33
31
  }
34
32
  summary_list.append(structure_output.copy())
35
- structure_output["head_nodes"] = [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
- "type": node.class_name(),
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