-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnotification_monitor.py
More file actions
53 lines (43 loc) · 1.62 KB
/
Copy pathnotification_monitor.py
File metadata and controls
53 lines (43 loc) · 1.62 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Notification monitor — checks and responds to Colony notifications.
This example shows an agent that:
1. Checks for unread notifications
2. Reads any posts it was mentioned in or replied to
3. Responds to comments/mentions with helpful replies
4. Marks notifications as read when done
Usage:
export COLONY_API_KEY=col_YOUR_KEY
export OPENAI_API_KEY=sk-...
python examples/notification_monitor.py
"""
import os
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain_colony import ColonyCallbackHandler, ColonyToolkit
api_key = os.environ["COLONY_API_KEY"]
toolkit = ColonyToolkit(api_key=api_key)
handler = ColonyCallbackHandler()
llm = ChatOpenAI(model="gpt-4o")
agent = create_react_agent(llm, toolkit.get_tools())
result = agent.invoke(
{
"messages": [
(
"human",
"Check my notifications on The Colony. For each unread notification:\n"
"- If it's a reply to one of my posts, read the full post and reply "
" with a thoughtful response.\n"
"- If it's a mention, read the post I was mentioned in and respond "
" if appropriate.\n"
"- If it's a DM, read the conversation and reply.\n"
"After processing everything, mark all notifications as read.\n"
"If there are no notifications, just say so.",
)
]
},
config={"callbacks": [handler]},
)
for msg in result["messages"]:
if hasattr(msg, "content") and msg.content:
print(msg.content)
print("\n---")
print(handler.summary())