Skip to content

Commit 25db7e8

Browse files
Merge pull request #16 from VCalazans/FEAT/CREATE-DELAY-NODE
✨ feat: Create node dealay
2 parents 24d7950 + d01644c commit 25db7e8

File tree

1 file changed

+55
-5
lines changed

1 file changed

+55
-5
lines changed

src/services/custom_agents/workflow_agent.py

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
│ Creation date: May 13, 2025 │
77
│ Contact: [email protected]
88
├──────────────────────────────────────────────────────────────────────────────┤
9+
│ @contributors: │
10+
│ Victor Calazans - delay node implementation (May 17, 2025) │
11+
├──────────────────────────────────────────────────────────────────────────────┤
912
│ @copyright © Evolution API 2025. All rights reserved. │
1013
│ Licensed under the Apache License, Version 2.0 │
1114
│ │
@@ -320,10 +323,9 @@ async def condition_node_function(
320323
)
321324
]
322325
),
323-
)
324-
]
326+
) ]
325327
content = content + condition_content
326-
328+
327329
yield {
328330
"content": content,
329331
"status": "condition_evaluated",
@@ -332,7 +334,7 @@ async def condition_node_function(
332334
"conversation_history": conversation_history,
333335
"session_id": session_id,
334336
}
335-
337+
336338
async def message_node_function(
337339
state: State, node_id: str, node_data: Dict[str, Any]
338340
) -> AsyncGenerator[State, None]:
@@ -365,15 +367,63 @@ async def message_node_function(
365367
"status": "message_added",
366368
"node_outputs": node_outputs,
367369
"cycle_count": state.get("cycle_count", 0),
370+
"conversation_history": conversation_history, "session_id": session_id,
371+
}
372+
373+
async def delay_node_function(
374+
state: State, node_id: str, node_data: Dict[str, Any]
375+
) -> AsyncGenerator[State, None]:
376+
delay_data = node_data.get("delay", {})
377+
delay_value = delay_data.get("value", 0)
378+
delay_unit = delay_data.get("unit", "seconds")
379+
delay_description = delay_data.get("description", "")
380+
381+
# Convert to seconds based on unit
382+
delay_seconds = delay_value
383+
if delay_unit == "minutes":
384+
delay_seconds = delay_value * 60
385+
elif delay_unit == "hours":
386+
delay_seconds = delay_value * 3600
387+
388+
label = node_data.get("label", "delay_node")
389+
print(f"\n⏱️ DELAY-NODE: {delay_value} {delay_unit} - {delay_description}")
390+
391+
content = state.get("content", [])
392+
session_id = state.get("session_id", "")
393+
conversation_history = state.get("conversation_history", [])
394+
395+
# Store node output information
396+
node_outputs = state.get("node_outputs", {})
397+
node_outputs[node_id] = {
398+
"delay_value": delay_value,
399+
"delay_unit": delay_unit,
400+
"delay_seconds": delay_seconds,
401+
"delay_start_time": datetime.now().isoformat(),
402+
}
403+
404+
# Actually perform the delay
405+
import asyncio
406+
await asyncio.sleep(delay_seconds)
407+
408+
409+
# Update node outputs with completion information
410+
node_outputs[node_id]["delay_end_time"] = datetime.now().isoformat()
411+
node_outputs[node_id]["delay_completed"] = True
412+
413+
yield {
414+
"content": content,
415+
"status": "delay_completed",
416+
"node_outputs": node_outputs, "cycle_count": state.get("cycle_count", 0),
368417
"conversation_history": conversation_history,
369418
"session_id": session_id,
370419
}
371-
420+
372421
return {
373422
"start-node": start_node_function,
374423
"agent-node": agent_node_function,
375424
"condition-node": condition_node_function,
376425
"message-node": message_node_function,
426+
"delay-node": delay_node_function,
377427
}
378428

379429
def _evaluate_condition(self, condition: Dict[str, Any], state: State) -> bool:

0 commit comments

Comments
 (0)