forked from agent0ai/agent-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify_user.py
More file actions
37 lines (30 loc) · 1.51 KB
/
notify_user.py
File metadata and controls
37 lines (30 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from python.helpers.tool import Tool, Response
from agent import AgentContext
from python.helpers.notification import NotificationPriority, NotificationType
class NotifyUserTool(Tool):
async def execute(self, **kwargs):
message = self.args.get("message", "")
title = self.args.get("title", "")
detail = self.args.get("detail", "")
notification_type = self.args.get("type", NotificationType.INFO)
priority = self.args.get("priority", NotificationPriority.HIGH) # by default, agents should notify with high priority
timeout = int(self.args.get("timeout", 30)) # agent's notifications should have longer timeouts
try:
notification_type = NotificationType(notification_type)
except ValueError:
return Response(message=f"Invalid notification type: {notification_type}", break_loop=False)
try:
priority = NotificationPriority(priority)
except ValueError:
return Response(message=f"Invalid notification priority: {priority}", break_loop=False)
if not message:
return Response(message="Message is required", break_loop=False)
AgentContext.get_notification_manager().add_notification(
message=message,
title=title,
detail=detail,
type=notification_type,
priority=priority,
display_time=timeout,
)
return Response(message=self.agent.read_prompt("fw.notify_user.notification_sent.md"), break_loop=False)