-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (39 loc) · 1.31 KB
/
main.py
File metadata and controls
58 lines (39 loc) · 1.31 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
54
55
56
57
58
from dotenv import load_dotenv
load_dotenv()
from langchain_core.agents import AgentFinish
from langgraph.graph import END, StateGraph
from nodes import execute_tools, run_agent_reasoning_engine
from state import AgentState
import logging
from langchain.globals import set_debug
set_debug(True)
# Optionally, explicitly set loggers for specific libraries
logging.getLogger("langgraph").setLevel(logging.DEBUG)
logging.getLogger("langchain").setLevel(logging.DEBUG)
logging.getLogger("langchain_core").setLevel(logging.DEBUG)
AGENT_REASON = "agent_reason"
ACT = "act"
def should_continue(state: AgentState) -> str:
if isinstance(state["agent_outcome"], AgentFinish):
return END
else:
return ACT
flow = StateGraph(AgentState)
flow.add_node(AGENT_REASON, run_agent_reasoning_engine)
flow.set_entry_point(AGENT_REASON)
flow.add_node(ACT, execute_tools)
flow.add_conditional_edges(
AGENT_REASON,
should_continue,
)
flow.add_edge(ACT, AGENT_REASON)
app = flow.compile()
app.get_graph().draw_mermaid_png(output_file_path="graph.png")
if __name__ == "__main__":
print("Hello ReAct with LangGraph")
res = app.invoke(
input={
"input": "what is the weather in Berlin, germany? List it and then triple it ",
}
)
print(res["agent_outcome"].return_values["output"])