Update sample code for: LangGraph Tutorial: Build Stateful AI Agents in Python by martin-martin · Pull Request #784 · realpython/materials · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python-langgraph/README.md
2 changes: 1 addition & 1 deletion python-langgraph/chains/binary_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BinaryAnswer(BaseModel):
]
)

binary_question_model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
binary_question_model = ChatOpenAI(model="gpt-5.4-nano", temperature=0)

BINARY_QUESTION_CHAIN = (
binary_question_prompt
Expand Down
2 changes: 1 addition & 1 deletion python-langgraph/chains/escalation_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EscalationCheck(BaseModel):
]
)

escalation_check_model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
escalation_check_model = ChatOpenAI(model="gpt-5.4-nano", temperature=0)

ESCALATION_CHECK_CHAIN = (
escalation_prompt
Expand Down
2 changes: 1 addition & 1 deletion python-langgraph/chains/notice_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def compliance_deadline(self) -> date | None:
]
)

notice_parser_model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
notice_parser_model = ChatOpenAI(model="gpt-5.4-nano", temperature=0)

NOTICE_PARSER_CHAIN = (
info_parse_prompt
Expand Down
10 changes: 5 additions & 5 deletions python-langgraph/example_emails.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
EMAILS = [
# Email 1
"""
Date: October 15, 2024
Date: May 15, 2026
From: Occupational Safety and Health Administration (OSHA)
To: Blue Ridge Construction, project 111232345 - Downtown Office Complex
Location: Dallas, TX
Expand All @@ -21,7 +21,7 @@
Conduct an inspection of all scaffolding structures and reinforce unstable
sections. Ensure all workers on-site are provided with necessary PPE and conduct
safety training on proper usage.
Deadline for Compliance: All violations must be rectified by November 10, 2024.
Deadline for Compliance: All violations must be rectified by June 10, 2026.
Failure to comply may result in fines of up to $25,000 per violation.

Contact: For questions or to confirm compliance, please reach out to the OSHA
Expand All @@ -44,7 +44,7 @@
""",
# Email 4
"""
Date: January 10, 2025
Date: June 10, 2026
From: City of Los Angeles Building and Safety Department
To: West Coast Development, project 345678123 - Sunset Luxury
Condominiums
Expand All @@ -62,8 +62,8 @@
standards. Install additional fire extinguishers in compliance with
fire code requirements. Reinforce or replace temporary support beams
to ensure structural stability. Deadline for Compliance: Violations
must be addressed no later than February 5,
2025. Failure to comply may result in
must be addressed no later than August 5,
2026. Failure to comply may result in
a stop-work order and additional fines.
Contact: For questions or to schedule a re-inspection, please contact
the Building and Safety Department at
Expand Down
3 changes: 1 addition & 2 deletions python-langgraph/graphs/email_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def extract_notice_data(
initial_state = {
"notice_message": email,
"notice_email_extract": None,
"critical_fields_missing": False,
"escalation_text_criteria": escalation_criteria,
"escalation_dollar_criteria": 100_000,
"requires_escalation": False,
Expand Down Expand Up @@ -110,7 +109,7 @@ def determine_email_action(email: str) -> str:
]
tool_node = ToolNode(tools)

EMAIL_AGENT_MODEL = ChatOpenAI(model="gpt-4o-mini", temperature=0).bind_tools(
EMAIL_AGENT_MODEL = ChatOpenAI(model="gpt-5.4-nano", temperature=0).bind_tools(
tools
)

Expand Down
6 changes: 3 additions & 3 deletions python-langgraph/graphs/notice_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def check_escalation_status_node(state: GraphState) -> GraphState:

if (
text_check
or state["notice_email_extract"].max_potential_fine
or (state["notice_email_extract"].max_potential_fine or 0)
>= state["escalation_dollar_criteria"]
):
state["requires_escalation"] = True
Expand Down Expand Up @@ -95,10 +95,10 @@ def answer_follow_up_question_node(state: GraphState) -> GraphState:
answer = BINARY_QUESTION_CHAIN.invoke({"question": question})

if state.get("follow_ups"):
state["follow_ups"][state["current_follow_up"]] = answer
state["follow_ups"][state["current_follow_up"]] = answer.is_true

else:
state["follow_ups"] = {state["current_follow_up"]: answer}
state["follow_ups"] = {state["current_follow_up"]: answer.is_true}

return state

Expand Down
6 changes: 3 additions & 3 deletions python-langgraph/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Companion code to Real Python tutorial"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"langchain-openai>=0.3.2",
"langgraph>=0.2.67",
"pydantic[email]>=2.10.6",
"langchain-openai>=1.3.2",
"langgraph>=1.2.5",
"pydantic[email]>=2.13.4",
]
62 changes: 46 additions & 16 deletions python-langgraph/requirements.txt
Loading