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.
- lionagi/__init__.py +60 -5
- lionagi/core/__init__.py +0 -25
- lionagi/core/_setting/_setting.py +59 -0
- lionagi/core/action/__init__.py +14 -0
- lionagi/core/action/function_calling.py +136 -0
- lionagi/core/action/manual.py +1 -0
- lionagi/core/action/node.py +109 -0
- lionagi/core/action/tool.py +114 -0
- lionagi/core/action/tool_manager.py +356 -0
- lionagi/core/agent/base_agent.py +27 -13
- lionagi/core/agent/eval/evaluator.py +1 -0
- lionagi/core/agent/eval/vote.py +40 -0
- lionagi/core/agent/learn/learner.py +59 -0
- lionagi/core/agent/plan/unit_template.py +1 -0
- lionagi/core/collections/__init__.py +17 -0
- lionagi/core/{generic/data_logger.py → collections/_logger.py} +69 -55
- lionagi/core/collections/abc/__init__.py +53 -0
- lionagi/core/collections/abc/component.py +615 -0
- lionagi/core/collections/abc/concepts.py +297 -0
- lionagi/core/collections/abc/exceptions.py +150 -0
- lionagi/core/collections/abc/util.py +45 -0
- lionagi/core/collections/exchange.py +161 -0
- lionagi/core/collections/flow.py +426 -0
- lionagi/core/collections/model.py +419 -0
- lionagi/core/collections/pile.py +913 -0
- lionagi/core/collections/progression.py +236 -0
- lionagi/core/collections/util.py +64 -0
- lionagi/core/director/direct.py +314 -0
- lionagi/core/director/director.py +2 -0
- lionagi/core/{execute/branch_executor.py → engine/branch_engine.py} +134 -97
- lionagi/core/{execute/instruction_map_executor.py → engine/instruction_map_engine.py} +80 -55
- lionagi/{experimental/directive/evaluator → core/engine}/script_engine.py +17 -1
- lionagi/core/executor/base_executor.py +90 -0
- lionagi/core/{execute/structure_executor.py → executor/graph_executor.py} +62 -66
- lionagi/core/{execute → executor}/neo4j_executor.py +70 -67
- lionagi/core/generic/__init__.py +3 -33
- lionagi/core/generic/edge.py +29 -79
- lionagi/core/generic/edge_condition.py +16 -0
- lionagi/core/generic/graph.py +236 -0
- lionagi/core/generic/hyperedge.py +1 -0
- lionagi/core/generic/node.py +156 -221
- lionagi/core/generic/tree.py +48 -0
- lionagi/core/generic/tree_node.py +79 -0
- lionagi/core/mail/__init__.py +12 -0
- lionagi/core/mail/mail.py +25 -0
- lionagi/core/mail/mail_manager.py +139 -58
- lionagi/core/mail/package.py +45 -0
- lionagi/core/mail/start_mail.py +36 -0
- lionagi/core/message/__init__.py +19 -0
- lionagi/core/message/action_request.py +133 -0
- lionagi/core/message/action_response.py +135 -0
- lionagi/core/message/assistant_response.py +95 -0
- lionagi/core/message/instruction.py +234 -0
- lionagi/core/message/message.py +101 -0
- lionagi/core/message/system.py +86 -0
- lionagi/core/message/util.py +283 -0
- lionagi/core/report/__init__.py +4 -0
- lionagi/core/report/base.py +217 -0
- lionagi/core/report/form.py +231 -0
- lionagi/core/report/report.py +166 -0
- lionagi/core/report/util.py +28 -0
- lionagi/core/rule/_default.py +16 -0
- lionagi/core/rule/action.py +99 -0
- lionagi/core/rule/base.py +238 -0
- lionagi/core/rule/boolean.py +56 -0
- lionagi/core/rule/choice.py +47 -0
- lionagi/core/rule/mapping.py +96 -0
- lionagi/core/rule/number.py +71 -0
- lionagi/core/rule/rulebook.py +109 -0
- lionagi/core/rule/string.py +52 -0
- lionagi/core/rule/util.py +35 -0
- lionagi/core/session/branch.py +431 -0
- lionagi/core/session/directive_mixin.py +287 -0
- lionagi/core/session/session.py +229 -903
- lionagi/core/structure/__init__.py +1 -0
- lionagi/core/structure/chain.py +1 -0
- lionagi/core/structure/forest.py +1 -0
- lionagi/core/structure/graph.py +1 -0
- lionagi/core/structure/tree.py +1 -0
- lionagi/core/unit/__init__.py +5 -0
- lionagi/core/unit/parallel_unit.py +245 -0
- lionagi/core/unit/template/action.py +81 -0
- lionagi/core/unit/template/base.py +51 -0
- lionagi/core/unit/template/plan.py +84 -0
- lionagi/core/unit/template/predict.py +109 -0
- lionagi/core/unit/template/score.py +124 -0
- lionagi/core/unit/template/select.py +104 -0
- lionagi/core/unit/unit.py +362 -0
- lionagi/core/unit/unit_form.py +305 -0
- lionagi/core/unit/unit_mixin.py +1168 -0
- lionagi/core/unit/util.py +71 -0
- lionagi/core/validator/validator.py +364 -0
- lionagi/core/work/work.py +76 -0
- lionagi/core/work/work_function.py +101 -0
- lionagi/core/work/work_queue.py +103 -0
- lionagi/core/work/worker.py +258 -0
- lionagi/core/work/worklog.py +120 -0
- lionagi/experimental/compressor/base.py +46 -0
- lionagi/experimental/compressor/llm_compressor.py +247 -0
- lionagi/experimental/compressor/llm_summarizer.py +61 -0
- lionagi/experimental/compressor/util.py +70 -0
- lionagi/experimental/directive/__init__.py +19 -0
- lionagi/experimental/directive/parser/base_parser.py +69 -2
- lionagi/experimental/directive/{template_ → template}/base_template.py +17 -1
- lionagi/{libs/ln_tokenizer.py → experimental/directive/tokenizer.py} +16 -0
- lionagi/experimental/{directive/evaluator → evaluator}/ast_evaluator.py +16 -0
- lionagi/experimental/{directive/evaluator → evaluator}/base_evaluator.py +16 -0
- lionagi/experimental/knowledge/base.py +10 -0
- lionagi/experimental/memory/__init__.py +0 -0
- lionagi/experimental/strategies/__init__.py +0 -0
- lionagi/experimental/strategies/base.py +1 -0
- lionagi/integrations/bridge/langchain_/documents.py +4 -0
- lionagi/integrations/bridge/llamaindex_/index.py +30 -0
- lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +6 -0
- lionagi/integrations/chunker/chunk.py +161 -24
- lionagi/integrations/config/oai_configs.py +34 -3
- lionagi/integrations/config/openrouter_configs.py +14 -2
- lionagi/integrations/loader/load.py +122 -21
- lionagi/integrations/loader/load_util.py +6 -77
- lionagi/integrations/provider/_mapping.py +46 -0
- lionagi/integrations/provider/litellm.py +2 -1
- lionagi/integrations/provider/mlx_service.py +16 -9
- lionagi/integrations/provider/oai.py +91 -4
- lionagi/integrations/provider/ollama.py +6 -5
- lionagi/integrations/provider/openrouter.py +115 -8
- lionagi/integrations/provider/services.py +2 -2
- lionagi/integrations/provider/transformers.py +18 -22
- lionagi/integrations/storage/__init__.py +3 -3
- lionagi/integrations/storage/neo4j.py +52 -60
- lionagi/integrations/storage/storage_util.py +44 -46
- lionagi/integrations/storage/structure_excel.py +43 -26
- lionagi/integrations/storage/to_excel.py +11 -4
- lionagi/libs/__init__.py +22 -1
- lionagi/libs/ln_api.py +75 -20
- lionagi/libs/ln_context.py +37 -0
- lionagi/libs/ln_convert.py +21 -9
- lionagi/libs/ln_func_call.py +69 -28
- lionagi/libs/ln_image.py +107 -0
- lionagi/libs/ln_nested.py +26 -11
- lionagi/libs/ln_parse.py +82 -23
- lionagi/libs/ln_queue.py +16 -0
- lionagi/libs/ln_tokenize.py +164 -0
- lionagi/libs/ln_validate.py +16 -0
- lionagi/libs/special_tokens.py +172 -0
- lionagi/libs/sys_util.py +95 -24
- lionagi/lions/coder/code_form.py +13 -0
- lionagi/lions/coder/coder.py +50 -3
- lionagi/lions/coder/util.py +30 -25
- lionagi/tests/libs/test_func_call.py +23 -21
- lionagi/tests/libs/test_nested.py +36 -21
- lionagi/tests/libs/test_parse.py +1 -1
- lionagi/tests/test_core/collections/__init__.py +0 -0
- lionagi/tests/test_core/collections/test_component.py +206 -0
- lionagi/tests/test_core/collections/test_exchange.py +138 -0
- lionagi/tests/test_core/collections/test_flow.py +145 -0
- lionagi/tests/test_core/collections/test_pile.py +171 -0
- lionagi/tests/test_core/collections/test_progression.py +129 -0
- lionagi/tests/test_core/generic/test_edge.py +67 -0
- lionagi/tests/test_core/generic/test_graph.py +96 -0
- lionagi/tests/test_core/generic/test_node.py +106 -0
- lionagi/tests/test_core/generic/test_tree_node.py +73 -0
- lionagi/tests/test_core/test_branch.py +115 -294
- lionagi/tests/test_core/test_form.py +46 -0
- lionagi/tests/test_core/test_report.py +105 -0
- lionagi/tests/test_core/test_validator.py +111 -0
- lionagi/version.py +1 -1
- lionagi-0.2.1.dist-info/LICENSE +202 -0
- lionagi-0.2.1.dist-info/METADATA +272 -0
- lionagi-0.2.1.dist-info/RECORD +240 -0
- lionagi/core/branch/base.py +0 -653
- lionagi/core/branch/branch.py +0 -474
- lionagi/core/branch/flow_mixin.py +0 -96
- lionagi/core/branch/util.py +0 -323
- lionagi/core/direct/__init__.py +0 -19
- lionagi/core/direct/cot.py +0 -123
- lionagi/core/direct/plan.py +0 -164
- lionagi/core/direct/predict.py +0 -166
- lionagi/core/direct/react.py +0 -171
- lionagi/core/direct/score.py +0 -279
- lionagi/core/direct/select.py +0 -170
- lionagi/core/direct/sentiment.py +0 -1
- lionagi/core/direct/utils.py +0 -110
- lionagi/core/direct/vote.py +0 -64
- lionagi/core/execute/base_executor.py +0 -47
- lionagi/core/flow/baseflow.py +0 -23
- lionagi/core/flow/monoflow/ReAct.py +0 -240
- lionagi/core/flow/monoflow/__init__.py +0 -9
- lionagi/core/flow/monoflow/chat.py +0 -95
- lionagi/core/flow/monoflow/chat_mixin.py +0 -253
- lionagi/core/flow/monoflow/followup.py +0 -215
- lionagi/core/flow/polyflow/__init__.py +0 -1
- lionagi/core/flow/polyflow/chat.py +0 -251
- lionagi/core/form/action_form.py +0 -26
- lionagi/core/form/field_validator.py +0 -287
- lionagi/core/form/form.py +0 -302
- lionagi/core/form/mixin.py +0 -214
- lionagi/core/form/scored_form.py +0 -13
- lionagi/core/generic/action.py +0 -26
- lionagi/core/generic/component.py +0 -532
- lionagi/core/generic/condition.py +0 -46
- lionagi/core/generic/mail.py +0 -90
- lionagi/core/generic/mailbox.py +0 -36
- lionagi/core/generic/relation.py +0 -70
- lionagi/core/generic/signal.py +0 -22
- lionagi/core/generic/structure.py +0 -362
- lionagi/core/generic/transfer.py +0 -20
- lionagi/core/generic/work.py +0 -40
- lionagi/core/graph/graph.py +0 -126
- lionagi/core/graph/tree.py +0 -190
- lionagi/core/mail/schema.py +0 -63
- lionagi/core/messages/schema.py +0 -325
- lionagi/core/tool/__init__.py +0 -5
- lionagi/core/tool/tool.py +0 -28
- lionagi/core/tool/tool_manager.py +0 -283
- lionagi/experimental/report/form.py +0 -64
- lionagi/experimental/report/report.py +0 -138
- lionagi/experimental/report/util.py +0 -47
- lionagi/experimental/tool/function_calling.py +0 -43
- lionagi/experimental/tool/manual.py +0 -66
- lionagi/experimental/tool/schema.py +0 -59
- lionagi/experimental/tool/tool_manager.py +0 -138
- lionagi/experimental/tool/util.py +0 -16
- lionagi/experimental/validator/rule.py +0 -139
- lionagi/experimental/validator/validator.py +0 -56
- lionagi/experimental/work/__init__.py +0 -10
- lionagi/experimental/work/async_queue.py +0 -54
- lionagi/experimental/work/schema.py +0 -73
- lionagi/experimental/work/work_function.py +0 -67
- lionagi/experimental/work/worker.py +0 -56
- lionagi/experimental/work2/form.py +0 -371
- lionagi/experimental/work2/report.py +0 -289
- lionagi/experimental/work2/schema.py +0 -30
- lionagi/experimental/work2/tests.py +0 -72
- lionagi/experimental/work2/work_function.py +0 -89
- lionagi/experimental/work2/worker.py +0 -12
- lionagi/integrations/bridge/llamaindex_/get_index.py +0 -294
- lionagi/tests/test_core/generic/test_component.py +0 -89
- lionagi/tests/test_core/test_base_branch.py +0 -426
- lionagi/tests/test_core/test_chat_flow.py +0 -63
- lionagi/tests/test_core/test_mail_manager.py +0 -75
- lionagi/tests/test_core/test_prompts.py +0 -51
- lionagi/tests/test_core/test_session.py +0 -254
- lionagi/tests/test_core/test_session_base_util.py +0 -313
- lionagi/tests/test_core/test_tool_manager.py +0 -95
- lionagi-0.1.2.dist-info/LICENSE +0 -9
- lionagi-0.1.2.dist-info/METADATA +0 -174
- lionagi-0.1.2.dist-info/RECORD +0 -206
- /lionagi/core/{branch → _setting}/__init__.py +0 -0
- /lionagi/core/{execute → agent/eval}/__init__.py +0 -0
- /lionagi/core/{flow → agent/learn}/__init__.py +0 -0
- /lionagi/core/{form → agent/plan}/__init__.py +0 -0
- /lionagi/core/{branch/executable_branch.py → agent/plan/plan.py} +0 -0
- /lionagi/core/{graph → director}/__init__.py +0 -0
- /lionagi/core/{messages → engine}/__init__.py +0 -0
- /lionagi/{experimental/directive/evaluator → core/engine}/sandbox_.py +0 -0
- /lionagi/{experimental/directive/evaluator → core/executor}/__init__.py +0 -0
- /lionagi/{experimental/directive/template_ → core/rule}/__init__.py +0 -0
- /lionagi/{experimental/report → core/unit/template}/__init__.py +0 -0
- /lionagi/{experimental/tool → core/validator}/__init__.py +0 -0
- /lionagi/{experimental/validator → core/work}/__init__.py +0 -0
- /lionagi/experimental/{work2 → compressor}/__init__.py +0 -0
- /lionagi/{core/flow/mono_chat_mixin.py → experimental/directive/template/__init__.py} +0 -0
- /lionagi/experimental/directive/{schema.py → template/schema.py} +0 -0
- /lionagi/experimental/{work2/util.py → evaluator/__init__.py} +0 -0
- /lionagi/experimental/{work2/work.py → knowledge/__init__.py} +0 -0
- /lionagi/{tests/libs/test_async.py → experimental/knowledge/graph.py} +0 -0
- {lionagi-0.1.2.dist-info → lionagi-0.2.1.dist-info}/WHEEL +0 -0
- {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 '
|
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 {
|
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,
|
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 '
|
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 {
|
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
|
-
|
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 '
|
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 {
|
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
|
-
|
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 '
|
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 {
|
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
|
-
|
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
|
120
|
+
async def add_directiveSelection_node(tx, node):
|
129
121
|
"""
|
130
|
-
Asynchronously adds an
|
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
|
126
|
+
node (dict): The properties of the directive selection node including 'ln_id', 'directive', and 'directiveKwargs'.
|
135
127
|
"""
|
136
128
|
query = """
|
137
|
-
MERGE (n:
|
138
|
-
SET n.
|
139
|
-
SET n.
|
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
|
-
|
144
|
-
|
145
|
-
|
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 '
|
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 {
|
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
|
-
|
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 '
|
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.
|
182
|
-
MATCH (n:LionNode) WHERE n.
|
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.
|
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
|
-
|
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 '
|
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.
|
210
|
-
MATCH (n:LionNode) WHERE n.
|
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.
|
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
|
-
|
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.
|
229
|
+
head_id = head.ln_id
|
238
230
|
query = """
|
239
|
-
MATCH (m:Structure) WHERE m.
|
240
|
-
MATCH (n:LionNode) WHERE n.
|
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.
|
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:
|
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 == "
|
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 == "
|
289
|
-
[await self.
|
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 '
|
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.
|
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.
|
416
|
+
MATCH (n:LionNode) WHERE n.ln_id = $ln_id
|
425
417
|
RETURN labels(n), n{.*}
|
426
418
|
"""
|
427
|
-
result = await tx.run(query,
|
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.
|
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.
|
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.
|
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.
|
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:
|
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
|
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.
|
7
|
-
from lionagi.core.
|
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.
|
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
|
-
"
|
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(
|
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
|
-
"
|
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.
|
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,
|
57
|
-
node_output["
|
58
|
-
node_output["
|
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.
|
61
|
-
node_output["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
|
-
"
|
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
|
-
|
187
|
-
node
|
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
|
-
|
206
|
-
node
|
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
|
208
|
+
def parse_directiveSelection(info_dict):
|
215
209
|
"""
|
216
|
-
Parses dictionary information into an
|
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 =
|
225
|
-
node.
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
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(
|
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(
|
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.
|
6
|
+
from lionagi.core.executor.graph_executor import GraphExecutor
|
7
7
|
from lionagi.core.agent.base_agent import BaseAgent
|
8
|
-
from lionagi.core.
|
9
|
-
from lionagi.core.
|
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
|
-
|
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["
|
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["
|
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["
|
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(
|
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(
|
161
|
-
|
162
|
-
|
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"] == "
|
185
|
-
return ParseNode.
|
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[
|
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.
|
224
|
-
|
225
|
-
|
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"][
|
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.
|
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.
|
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 =
|
283
|
+
self.structure = GraphExecutor()
|
267
284
|
heads = self.get_heads()
|
268
|
-
self.parse(heads)
|
285
|
+
self.parse(heads)
|