23
23
AgentNodeExecutionInputOutput ,
24
24
)
25
25
from prisma .types import (
26
+ AgentGraphExecutionCreateInput ,
26
27
AgentGraphExecutionWhereInput ,
27
28
AgentNodeExecutionCreateInput ,
28
29
AgentNodeExecutionInputOutputCreateInput ,
@@ -121,15 +122,15 @@ class GraphExecution(GraphExecutionMeta):
121
122
122
123
@staticmethod
123
124
def from_db (_graph_exec : AgentGraphExecution ):
124
- if _graph_exec .AgentNodeExecutions is None :
125
+ if _graph_exec .NodeExecutions is None :
125
126
raise ValueError ("Node executions must be included in query" )
126
127
127
128
graph_exec = GraphExecutionMeta .from_db (_graph_exec )
128
129
129
130
complete_node_executions = sorted (
130
131
[
131
132
NodeExecutionResult .from_db (ne , _graph_exec .userId )
132
- for ne in _graph_exec .AgentNodeExecutions
133
+ for ne in _graph_exec .NodeExecutions
133
134
if ne .executionStatus != ExecutionStatus .INCOMPLETE
134
135
],
135
136
key = lambda ne : (ne .queue_time is None , ne .queue_time or ne .add_time ),
@@ -181,15 +182,15 @@ class GraphExecutionWithNodes(GraphExecution):
181
182
182
183
@staticmethod
183
184
def from_db (_graph_exec : AgentGraphExecution ):
184
- if _graph_exec .AgentNodeExecutions is None :
185
+ if _graph_exec .NodeExecutions is None :
185
186
raise ValueError ("Node executions must be included in query" )
186
187
187
188
graph_exec_with_io = GraphExecution .from_db (_graph_exec )
188
189
189
190
node_executions = sorted (
190
191
[
191
192
NodeExecutionResult .from_db (ne , _graph_exec .userId )
192
- for ne in _graph_exec .AgentNodeExecutions
193
+ for ne in _graph_exec .NodeExecutions
193
194
],
194
195
key = lambda ne : (ne .queue_time is None , ne .queue_time or ne .add_time ),
195
196
)
@@ -220,21 +221,21 @@ class NodeExecutionResult(BaseModel):
220
221
end_time : datetime | None
221
222
222
223
@staticmethod
223
- def from_db (execution : AgentNodeExecution , user_id : Optional [str ] = None ):
224
- if execution .executionData :
224
+ def from_db (_node_exec : AgentNodeExecution , user_id : Optional [str ] = None ):
225
+ if _node_exec .executionData :
225
226
# Execution that has been queued for execution will persist its data.
226
- input_data = type_utils .convert (execution .executionData , dict [str , Any ])
227
+ input_data = type_utils .convert (_node_exec .executionData , dict [str , Any ])
227
228
else :
228
229
# For incomplete execution, executionData will not be yet available.
229
230
input_data : BlockInput = defaultdict ()
230
- for data in execution .Input or []:
231
+ for data in _node_exec .Input or []:
231
232
input_data [data .name ] = type_utils .convert (data .data , type [Any ])
232
233
233
234
output_data : CompletedBlockOutput = defaultdict (list )
234
- for data in execution .Output or []:
235
+ for data in _node_exec .Output or []:
235
236
output_data [data .name ].append (type_utils .convert (data .data , type [Any ]))
236
237
237
- graph_execution : AgentGraphExecution | None = execution . AgentGraphExecution
238
+ graph_execution : AgentGraphExecution | None = _node_exec . GraphExecution
238
239
if graph_execution :
239
240
user_id = graph_execution .userId
240
241
elif not user_id :
@@ -246,17 +247,17 @@ def from_db(execution: AgentNodeExecution, user_id: Optional[str] = None):
246
247
user_id = user_id ,
247
248
graph_id = graph_execution .agentGraphId if graph_execution else "" ,
248
249
graph_version = graph_execution .agentGraphVersion if graph_execution else 0 ,
249
- graph_exec_id = execution .agentGraphExecutionId ,
250
- block_id = execution . AgentNode .agentBlockId if execution . AgentNode else "" ,
251
- node_exec_id = execution .id ,
252
- node_id = execution .agentNodeId ,
253
- status = execution .executionStatus ,
250
+ graph_exec_id = _node_exec .agentGraphExecutionId ,
251
+ block_id = _node_exec . Node .agentBlockId if _node_exec . Node else "" ,
252
+ node_exec_id = _node_exec .id ,
253
+ node_id = _node_exec .agentNodeId ,
254
+ status = _node_exec .executionStatus ,
254
255
input_data = input_data ,
255
256
output_data = output_data ,
256
- add_time = execution .addedTime ,
257
- queue_time = execution .queuedTime ,
258
- start_time = execution .startedTime ,
259
- end_time = execution .endedTime ,
257
+ add_time = _node_exec .addedTime ,
258
+ queue_time = _node_exec .queuedTime ,
259
+ start_time = _node_exec .startedTime ,
260
+ end_time = _node_exec .endedTime ,
260
261
)
261
262
262
263
@@ -351,29 +352,29 @@ async def create_graph_execution(
351
352
The id of the AgentGraphExecution and the list of ExecutionResult for each node.
352
353
"""
353
354
result = await AgentGraphExecution .prisma ().create (
354
- data = {
355
- " agentGraphId" : graph_id ,
356
- " agentGraphVersion" : graph_version ,
357
- " executionStatus" : ExecutionStatus .QUEUED ,
358
- "AgentNodeExecutions" : {
359
- "create" : [ # type: ignore
360
- {
361
- " agentNodeId" : node_id ,
362
- " executionStatus" : ExecutionStatus .QUEUED ,
363
- " queuedTime" : datetime .now (tz = timezone .utc ),
364
- " Input" : {
355
+ data = AgentGraphExecutionCreateInput (
356
+ agentGraphId = graph_id ,
357
+ agentGraphVersion = graph_version ,
358
+ executionStatus = ExecutionStatus .QUEUED ,
359
+ NodeExecutions = {
360
+ "create" : [
361
+ AgentNodeExecutionCreateInput (
362
+ agentNodeId = node_id ,
363
+ executionStatus = ExecutionStatus .QUEUED ,
364
+ queuedTime = datetime .now (tz = timezone .utc ),
365
+ Input = {
365
366
"create" : [
366
367
{"name" : name , "data" : Json (data )}
367
368
for name , data in node_input .items ()
368
369
]
369
370
},
370
- }
371
+ )
371
372
for node_id , node_input in nodes_input
372
373
]
373
374
},
374
- " userId" : user_id ,
375
- " agentPresetId" : preset_id ,
376
- } ,
375
+ userId = user_id ,
376
+ agentPresetId = preset_id ,
377
+ ) ,
377
378
include = GRAPH_EXECUTION_INCLUDE_WITH_NODES ,
378
379
)
379
380
@@ -600,7 +601,7 @@ async def get_node_execution_results(
600
601
"agentGraphExecutionId" : graph_exec_id ,
601
602
}
602
603
if block_ids :
603
- where_clause ["AgentNode " ] = {"is" : {"agentBlockId" : {"in" : block_ids }}}
604
+ where_clause ["Node " ] = {"is" : {"agentBlockId" : {"in" : block_ids }}}
604
605
if statuses :
605
606
where_clause ["OR" ] = [{"executionStatus" : status } for status in statuses ]
606
607
0 commit comments