-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (27 loc) · 1.02 KB
/
main.py
File metadata and controls
40 lines (27 loc) · 1.02 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
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from langchain.schema import AIMessage, HumanMessage
from agentmail_toolkit.langchain import AgentMailToolkit
agent = create_react_agent(
model=ChatOpenAI(model="gpt-4o"),
prompt="You are an email agent created by AgentMail that can create and manage inboxes as well as send and receive emails.",
tools=AgentMailToolkit().get_tools(),
)
def main():
messages = []
while True:
prompt = input("\n\nUser:\n\n")
if prompt.lower() == "q":
break
messages.append(HumanMessage(prompt))
result = agent.stream({"messages": messages}, stream_mode="messages")
print("\nAssistant:\n")
response = ""
for chunk, _ in result:
if not isinstance(chunk, AIMessage):
continue
print(chunk.content, end="", flush=True)
response += chunk.content
messages.append(AIMessage(response))
if __name__ == "__main__":
main()