-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlesson15b.py
26 lines (22 loc) · 921 Bytes
/
lesson15b.py
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
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
class DiagnosticState(TypedDict):
symptoms: str
diagnosis: str
def analyze_symptoms(state: DiagnosticState):
if "slow" in state['symptoms']:
state['diagnosis'] = "Possible network issue."
elif "error" in state['symptoms']:
state['diagnosis'] = "Check application logs for errors."
else:
state['diagnosis'] = "Further investigation needed."
return state
# Define the workflow
builder = StateGraph(DiagnosticState)
builder.add_node("analyze_symptoms", analyze_symptoms)
builder.add_edge(START, "analyze_symptoms")
builder.add_edge("analyze_symptoms", END)
graph = builder.compile()
# Sample invocation
result = graph.invoke({"symptoms": "application slow response", "diagnosis": ""})
print(result) # Output: {'symptoms': 'application slow response', 'diagnosis': 'Possible network issue.'}