Skip to content

Commit 58516c1

Browse files
committed
Fix lint errors in langgraph samples
- Fix import sorting (I001) across all sample modules - Apply ruff formatting to 11 files - Add type annotations for mypy (executor_agent, critique, plan) - Use cast() for structured output return types
1 parent fe7134d commit 58516c1

File tree

15 files changed

+33
-39
lines changed

15 files changed

+33
-39
lines changed

langgraph_samples/agentic_rag/graph.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import os
3030
from typing import Annotated, Any, Literal, Sequence, cast
3131

32-
from langchain.agents import create_agent
3332
from langchain_core.documents import Document
3433
from langchain_core.messages import BaseMessage, HumanMessage
3534
from langchain_core.output_parsers import StrOutputParser
@@ -42,6 +41,8 @@
4241
from pydantic import BaseModel, Field
4342
from typing_extensions import TypedDict
4443

44+
from langchain.agents import create_agent
45+
4546
# Sample documents about AI agents and LangGraph for the knowledge base
4647
SAMPLE_DOCUMENTS = [
4748
Document(

langgraph_samples/agentic_rag/workflow.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ async def run(self, query: str) -> dict[str, Any]:
5454

5555
# Execute the agent
5656
# The input format is a dict with "messages"
57-
result = await app.ainvoke(
58-
{"messages": [{"role": "user", "content": query}]}
59-
)
57+
result = await app.ainvoke({"messages": [{"role": "user", "content": query}]})
6058

6159
return result

langgraph_samples/approval_workflow/activities.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ async def notify_approver(request_info: dict) -> str:
3636
print(f"Workflow ID: {workflow_id}")
3737
print(f"Request: {message}")
3838
print(f"\nTo respond, run:")
39-
print(f" Approve: uv run python -m langgraph_samples.approval_workflow.run_respond {workflow_id} --approve --reason 'Your reason'")
40-
print(f" Reject: uv run python -m langgraph_samples.approval_workflow.run_respond {workflow_id} --reject --reason 'Your reason'")
39+
print(
40+
f" Approve: uv run python -m langgraph_samples.approval_workflow.run_respond {workflow_id} --approve --reason 'Your reason'"
41+
)
42+
print(
43+
f" Reject: uv run python -m langgraph_samples.approval_workflow.run_respond {workflow_id} --reject --reason 'Your reason'"
44+
)
4145
print()
4246

4347
return f"Notification sent for workflow {workflow_id}"

langgraph_samples/approval_workflow/run_workflow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ async def main() -> None:
4040
)
4141

4242
print(f"Workflow started. Waiting for result...")
43-
print(f"\nTo approve/reject, use the run_respond script (see worker output for commands)")
43+
print(
44+
f"\nTo approve/reject, use the run_respond script (see worker output for commands)"
45+
)
4446

4547
# Wait for the workflow to complete
4648
result = await handle.result()

langgraph_samples/approval_workflow/workflow.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
with workflow.unsafe.imports_passed_through():
1818
from langgraph.types import Command
19+
from temporalio.contrib.langgraph import compile as lg_compile
1920

2021
from langgraph_samples.approval_workflow.activities import (
2122
notify_approver,
2223
)
23-
from temporalio.contrib.langgraph import compile as lg_compile
2424

2525

2626
@dataclass
@@ -147,7 +147,9 @@ async def run(
147147

148148
workflow.logger.info(
149149
"Received approval response: approved=%s",
150-
self._approval_response.get("approved") if self._approval_response else None,
150+
self._approval_response.get("approved")
151+
if self._approval_response
152+
else None,
151153
)
152154

153155
# Resume with the approval response

langgraph_samples/deep_research/graph.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"""
2424

2525
import os
26-
from typing import Annotated, Any, Literal
26+
from typing import Annotated, Any, Literal, cast
2727

2828
from langchain_community.tools import DuckDuckGoSearchRun
2929
from langchain_core.messages import BaseMessage, HumanMessage
@@ -142,7 +142,7 @@ def plan_research(state: ResearchState) -> dict[str, Any]:
142142
)
143143

144144
planner = plan_prompt | model.with_structured_output(ResearchPlan)
145-
plan = planner.invoke({"topic": topic_str})
145+
plan = cast(ResearchPlan, planner.invoke({"topic": topic_str}))
146146

147147
return {
148148
"topic": topic_str,
@@ -253,9 +253,7 @@ def synthesize_report(state: ResearchState) -> dict[str, Any]:
253253
findings = []
254254
for result in results:
255255
if result.get("relevant", False):
256-
findings.append(
257-
f"### {result['purpose']}\n{result['results']}"
258-
)
256+
findings.append(f"### {result['purpose']}\n{result['results']}")
259257

260258
if not findings:
261259
findings_text = "Limited information was found on this topic."

langgraph_samples/deep_research/workflow.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class DeepResearchWorkflow:
3232
"""
3333

3434
@workflow.run
35-
async def run(
36-
self, topic: str, max_iterations: int = 2
37-
) -> dict[str, Any]:
35+
async def run(self, topic: str, max_iterations: int = 2) -> dict[str, Any]:
3836
"""Run deep research on a topic.
3937
4038
Args:

langgraph_samples/hello_world/graph.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from langgraph.graph import END, START, StateGraph
1010
from typing_extensions import TypedDict
1111

12-
1312
# =============================================================================
1413
# State Definition
1514
# =============================================================================

langgraph_samples/plan_and_execute/graph.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import os
2424
from typing import Annotated, Any, Literal
2525

26-
from langchain.agents import create_agent
2726
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage
2827
from langchain_core.output_parsers import StrOutputParser
2928
from langchain_core.prompts import ChatPromptTemplate
@@ -34,6 +33,8 @@
3433
from pydantic import BaseModel, Field
3534
from typing_extensions import TypedDict
3635

36+
from langchain.agents import create_agent
37+
3738

3839
class PlanStep(BaseModel):
3940
"""A single step in the execution plan."""
@@ -167,7 +168,7 @@ def build_plan_and_execute_graph() -> Any:
167168

168169
# Build executor agent with tools
169170
tools = [calculate, lookup, analyze]
170-
executor_agent = create_agent(model, tools)
171+
executor_agent: Any = create_agent(model, tools)
171172

172173
def create_plan(state: PlanExecuteState) -> dict[str, Any]:
173174
"""Create an execution plan from the objective.
@@ -243,9 +244,7 @@ def execute_step(state: PlanExecuteState) -> dict[str, Any]:
243244
if result.get("messages"):
244245
last_msg = result["messages"][-1]
245246
result_content = (
246-
last_msg.content
247-
if hasattr(last_msg, "content")
248-
else str(last_msg)
247+
last_msg.content if hasattr(last_msg, "content") else str(last_msg)
249248
)
250249

251250
step_result = StepResult(

langgraph_samples/react_agent/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import os
1212
from typing import Any
1313

14-
from langchain.agents import create_agent
1514
from langchain_openai import ChatOpenAI
1615

16+
from langchain.agents import create_agent
1717
from langgraph_samples.react_agent.tools import calculate, get_weather
1818

1919

0 commit comments

Comments
 (0)