Skip to content

Commit 0c42585

Browse files
authored
Merge pull request #86 from aerospike/uv-lock-fix
chore: accommodate ruff formating rules
2 parents 26e1d86 + 8bcd7b2 commit 0c42585

5 files changed

Lines changed: 1170 additions & 948 deletions

File tree

cookbooks/agent-path-correction/README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ from langgraph.graph.message import add_messages
8787

8888
Intent = Literal["refund", "replacement", "escalate"]
8989

90+
9091
class SupportState(TypedDict):
9192
messages: Annotated[list[BaseMessage], add_messages]
9293
item: str | None
@@ -115,6 +116,7 @@ _CATALOG = {
115116
"monitor": ("AeroPro 4K Monitor", "ORD-33170"),
116117
}
117118

119+
118120
def _lookup_order(text: str) -> tuple[str | None, str | None]:
119121
lowered = text.lower()
120122
for keyword, (item, order_id) in _CATALOG.items():
@@ -162,6 +164,7 @@ def _classify_intent(text: str) -> Intent:
162164
return "refund"
163165
return "escalate"
164166

167+
165168
def classify(state: SupportState) -> SupportState:
166169
intent = _classify_intent(_latest_user_text(state["messages"]))
167170
return {"intent": intent}
@@ -186,6 +189,7 @@ def refund(state: SupportState) -> SupportState:
186189
"messages": [AIMessage(content=f"I can handle that as a refund for order {order_id}.")],
187190
}
188191

192+
189193
def replacement(state: SupportState) -> SupportState:
190194
order_id = state["order_id"]
191195
return {
@@ -195,6 +199,7 @@ def replacement(state: SupportState) -> SupportState:
195199
],
196200
}
197201

202+
198203
def escalate(state: SupportState) -> SupportState:
199204
order_id = state["order_id"]
200205
return {
@@ -218,6 +223,7 @@ rewind to: order id known, decision not yet made.
218223
def route(state: SupportState) -> Intent:
219224
return state["intent"] or "escalate"
220225

226+
221227
builder = StateGraph(SupportState)
222228
builder.add_node("identify_order", identify_order)
223229
builder.add_node("classify", classify)
@@ -228,7 +234,8 @@ builder.add_node("escalate", escalate)
228234
builder.add_edge(START, "identify_order")
229235
builder.add_edge("identify_order", "classify")
230236
builder.add_conditional_edges(
231-
"classify", route,
237+
"classify",
238+
route,
232239
{"refund": "refund", "replacement": "replacement", "escalate": "escalate"},
233240
)
234241
builder.add_edge("refund", END)
@@ -322,8 +329,14 @@ until `identify_order` runs, then carried by every later checkpoint.
322329
history = list(saver.list(prod_config))
323330
for i, tpl in enumerate(reversed(history), start=1):
324331
values = tpl.checkpoint.get("channel_values", {})
325-
print(i, tpl.config["configurable"]["checkpoint_id"], _stage(tpl.metadata.get("step")),
326-
values.get("order_id"), values.get("intent"), values.get("resolution"))
332+
print(
333+
i,
334+
tpl.config["configurable"]["checkpoint_id"],
335+
_stage(tpl.metadata.get("step")),
336+
values.get("order_id"),
337+
values.get("intent"),
338+
values.get("resolution"),
339+
)
327340
```
328341

329342
**In the code:** `demo.py`, `# === Step 9 ===` (Phase 3, after the customer's
@@ -350,11 +363,14 @@ rehydrates it.
350363

351364
```python
352365
fork_point = next(
353-
(tpl for tpl in reversed(history)
354-
if _values(tpl).get("order_id") and not _values(tpl).get("resolution")),
366+
(
367+
tpl
368+
for tpl in reversed(history)
369+
if _values(tpl).get("order_id") and not _values(tpl).get("resolution")
370+
),
355371
history[-1],
356372
)
357-
rehydrated = saver.get_tuple(fork_point.config) # one checkpoint read from Aerospike
373+
rehydrated = saver.get_tuple(fork_point.config) # one checkpoint read from Aerospike
358374
# rehydrated state: order_id == "ORD-10482", intent == None, resolution == None
359375
```
360376

@@ -376,8 +392,8 @@ same `ORD-10482`. LangGraph writes new checkpoints from here; the refund run fro
376392
Phase 1 stays in Aerospike under its own checkpoint ids.
377393

378394
```python
379-
fork_config = fork_point.config # thread_id + checkpoint_ns + checkpoint_id
380-
forked = _resolve(graph, fork_config, CORRECTED_REQUEST) # "...send a replacement instead."
395+
fork_config = fork_point.config # thread_id + checkpoint_ns + checkpoint_id
396+
forked = _resolve(graph, fork_config, CORRECTED_REQUEST) # "...send a replacement instead."
381397
# forked.order_id == "ORD-10482" (reused from the checkpoint)
382398
# forked.resolution == "Replacement selected for order ORD-10482"
383399
```

cookbooks/expiring-chat-sessions/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ from typing import Annotated, TypedDict
7777
from langchain_core.messages import BaseMessage
7878
from langgraph.graph.message import add_messages
7979

80+
8081
class ChatState(TypedDict):
8182
messages: Annotated[list[BaseMessage], add_messages]
8283
```
@@ -101,7 +102,7 @@ and appends the reply. Split this into two pieces in `agent.py`:
101102
**Part A — create the model** (`agent.py`, `# === Step 2 ===`):
102103

103104
```python
104-
def _make_llm() -> BaseChatModel: # generic interface; FakeListChatModel is one impl
105+
def _make_llm() -> BaseChatModel: # generic interface; FakeListChatModel is one impl
105106
return FakeListChatModel(
106107
responses=[
107108
"Hi! I'm your support assistant. How can I help?",
@@ -116,12 +117,13 @@ def _make_llm() -> BaseChatModel: # generic interface; FakeListChatModel
116117

117118
```python
118119
def build_chat_graph(checkpointer: BaseCheckpointSaver) -> CompiledStateGraph:
119-
llm = _make_llm() # <-- Part A is called here
120+
llm = _make_llm() # <-- Part A is called here
120121

121122
def chatbot(state: ChatState) -> ChatState:
122123
system = SystemMessage(content="You are a concise, helpful support assistant.")
123124
response: AIMessage = llm.invoke([system, *state["messages"]])
124125
return {"messages": [response]}
126+
125127
# ... Step 3 continues in the next section
126128
```
127129

@@ -177,6 +179,7 @@ AEROSPIKE_HOST: str = "127.0.0.1"
177179
AEROSPIKE_PORT: int = 3000
178180
AEROSPIKE_NAMESPACE: str = "test"
179181

182+
180183
@contextmanager
181184
def _connect() -> Iterator[aerospike.Client]:
182185
client = aerospike.client({"hosts": [(AEROSPIKE_HOST, AEROSPIKE_PORT)]}).connect()
@@ -203,6 +206,7 @@ automatically when the time elapses.
203206
CHAT_TTL_MINUTES: int = 1
204207
CHAT_REFRESH_ON_READ: bool = False
205208

209+
206210
def _build_checkpointer(client: aerospike.Client) -> AerospikeSaver:
207211
return AerospikeSaver(
208212
client=client,
@@ -241,6 +245,7 @@ THREAD_ID: str = "session-demo-001"
241245

242246
config: RunnableConfig = {"configurable": {"thread_id": THREAD_ID}}
243247

248+
244249
def _say(graph: CompiledStateGraph, config: RunnableConfig, text: str) -> int:
245250
result = graph.invoke({"messages": [HumanMessage(text)]}, config)
246251
return len(result["messages"])
@@ -321,7 +326,7 @@ time.sleep(wait_seconds)
321326

322327
tpl = saver.get_tuple(config)
323328
if tpl is not None:
324-
return 1 # checkpoint still present — TTL has not elapsed yet
329+
return 1 # checkpoint still present — TTL has not elapsed yet
325330

326331
count = _say(graph, config, "Hello again?") # back to 2 messages
327332
```

packages/langgraph-checkpoint-aerospike/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ docker run -d --name aerospike -p 3000-3002:3000-3002 container.aerospike.com/ae
3838
client = aerospike.client({"hosts": [("127.0.0.1", 3000)]}).connect()
3939
checkpointer = AerospikeSaver(client=client, namespace="test")
4040

41+
4142
# 2. Define a minimal LangGraph graph.
4243
class State(TypedDict):
4344
messages: Annotated[list, add_messages]
4445

46+
4547
def chatbot(state: State) -> State:
4648
last = state["messages"][-1].content
4749
return {"messages": [("assistant", f"You said: {last}")]}
4850

51+
4952
builder = StateGraph(State)
5053
builder.add_node("chatbot", chatbot)
5154
builder.add_edge(START, "chatbot")

packages/langgraph-store-aerospike/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ from langgraph.store.aerospike import AerospikeStore
3939
client = aerospike.client({"hosts": [("127.0.0.1", 3000)]}).connect()
4040
store = AerospikeStore(client=client, namespace="test", set="langgraph_store")
4141

42+
4243
# 2. Define a graph whose node reads and writes long-term memory.
4344
class State(TypedDict):
4445
user_id: str
4546
food: str
4647

48+
4749
def remember_preference(state: State) -> State:
4850
store = get_store()
4951
namespace = ("users", state["user_id"])
@@ -56,6 +58,7 @@ def remember_preference(state: State) -> State:
5658
print(profile.value) # {"favorite_food": "pizza"}
5759
return state
5860

61+
5962
builder = StateGraph(State)
6063
builder.add_node("remember_preference", remember_preference)
6164
builder.add_edge(START, "remember_preference")

0 commit comments

Comments
 (0)