-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_bot.py
More file actions
32 lines (22 loc) · 786 Bytes
/
agent_bot.py
File metadata and controls
32 lines (22 loc) · 786 Bytes
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
from typing import TypedDict, List
from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI
from langgraph.graph import StateGraph, START, END
from dotenv import load_dotenv
load_dotenv()
class AgentState(TypedDict):
messages : List[HumanMessage]
llm = ChatOpenAI(model="gpt-4o-mini")
def process(state: AgentState) -> AgentState:
response = llm.invoke(state["messages"])
print(f"AI: {response.text}")
return state
graph = StateGraph(AgentState)
graph.add_node("process", process)
graph.add_edge(START, "process")
graph.add_edge("process", END)
agent = graph.compile()
user_input = input("Enter: ")
while user_input != "exit":
agent.invoke({"messages": [HumanMessage(content=user_input)]})
user_input = input("Enter: ")