Skip to content

Commit 4c042b0

Browse files
author
hfhoffman1144
committed
usage
1 parent aaea7a3 commit 4c042b0

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

python-langgraph/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,25 @@ OPENAI_API_KEY=<YOUR-OPENAI-API-KEY>
2020

2121
## Usage
2222

23-
TODO: A short note on how to run the project. You can tell them to go to the tutorial for more information.
23+
Once your environment is set up, you can run the final graph agent on an example input with the following code:
24+
25+
```python
26+
from graphs.email_agent import email_agent_graph
27+
from example_emails import EMAILS
28+
29+
escalation_criteria = """"There's an immediate risk of electrical,
30+
water, or fire damage"""
31+
32+
message_with_criteria = f"""
33+
The escalation criteria is: {escalation_criteria}
34+
35+
Here's the email:
36+
{EMAILS[3]}
37+
"""
38+
message_3 = {"messages": [("human", message_with_criteria)]}
39+
40+
for chunk in email_agent_graph.stream(message_3, stream_mode="values"):
41+
chunk["messages"][-1].pretty_print()
42+
```
43+
44+
See the tutorial for all the details on what's going on here.

python-langgraph/chains/notice_extraction.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ class NoticeEmailExtract(BaseModel):
6464
@property
6565
def date_of_notice(self) -> date | None:
6666
try:
67-
return datetime.strptime(
68-
self.date_of_notice_str, "%Y-%m-%d"
69-
).date()
67+
return datetime.strptime(self.date_of_notice_str, "%Y-%m-%d").date()
7068
except Exception as e:
7169
print(e)
7270
return None
@@ -75,9 +73,7 @@ def date_of_notice(self) -> date | None:
7573
@property
7674
def compliance_deadline(self) -> date | None:
7775
try:
78-
return datetime.strptime(
79-
self.compliance_deadline_str, "%Y-%m-%d"
80-
).date()
76+
return datetime.strptime(self.compliance_deadline_str, "%Y-%m-%d").date()
8177
except Exception as e:
8278
print(e)
8379
return None
@@ -103,7 +99,6 @@ def compliance_deadline(self) -> date | None:
10399

104100
notice_parser_model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
105101

106-
NOTICE_PARSER_CHAIN = (
107-
info_parse_prompt
108-
| notice_parser_model.with_structured_output(NoticeEmailExtract)
102+
NOTICE_PARSER_CHAIN = info_parse_prompt | notice_parser_model.with_structured_output(
103+
NoticeEmailExtract
109104
)

python-langgraph/graphs/email_agent.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def forward_email(email_message: str, send_to_email: str) -> bool:
2626

2727

2828
@tool
29-
def send_wrong_email_notification_to_sender(sender_email: str, correct_department: str):
29+
def send_wrong_email_notification_to_sender(
30+
sender_email: str, correct_department: str
31+
):
3032
"""
3133
Send an email back to the sender informing them that
3234
they have the wrong address. The email should be sent
@@ -41,7 +43,9 @@ def send_wrong_email_notification_to_sender(sender_email: str, correct_departmen
4143

4244

4345
@tool
44-
def extract_notice_data(email: str, escalation_criteria: str) -> NoticeEmailExtract:
46+
def extract_notice_data(
47+
email: str, escalation_criteria: str
48+
) -> NoticeEmailExtract:
4549
"""
4650
Extract structured fields from a regulatory notice.
4751
This should be used when the email message comes from
@@ -105,7 +109,9 @@ def determine_email_action(email: str) -> str:
105109
]
106110
tool_node = ToolNode(tools)
107111

108-
EMAIL_AGENT_MODEL = ChatOpenAI(model="gpt-4o-mini", temperature=0).bind_tools(tools)
112+
EMAIL_AGENT_MODEL = ChatOpenAI(model="gpt-4o-mini", temperature=0).bind_tools(
113+
tools
114+
)
109115

110116

111117
def call_agent_model_node(state: MessagesState) -> dict[str, list[AIMessage]]:

python-langgraph/utils/graph_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def create_legal_ticket(
3232
]
3333

3434
if current_follow_ups:
35-
follow_ups = [f for f in follow_ups if f not in current_follow_ups.keys()]
35+
follow_ups = [
36+
f for f in follow_ups if f not in current_follow_ups.keys()
37+
]
3638

3739
follow_up = random.choice(follow_ups)
3840

0 commit comments

Comments
 (0)