-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
from typing import TypedDict
from langgraph.checkpoint.memory import MemorySaver
from langgraph.graph import StateGraph, START, END
from langgraph.types import Command, interrupt
from langchain_core.messages import AnyMessage
from langgraph.checkpoint.redis import RedisSaver
from typing_extensions import TypedDict, Annotated
import operator
import uuid
with RedisSaver.from_conn_string('redis://:passport@ip:port') as cp:
cp.setup()
class State(TypedDict):
messages: Annotated[list[AnyMessage], operator.add]
def review_node(state: State):
# Ask a reviewer to edit the generated content
random_str = str(uuid.uuid4())
print('random_str:', random_str)
print('-------- entry interrupt --------')
input = interrupt("123")
print(input['test'])
print('-------- exit interrupt --------')
return {"messages": [random_str]}
builder = StateGraph(State)
builder.add_node("review", review_node)
builder.add_edge(START, "review")
builder.add_edge("review", END)
checkpointer = cp
graph = builder.compile(checkpointer=checkpointer)
config = {"configurable": {"thread_id": "review-32"}}
initial = graph.invoke({}, config=config)
print(initial)
print('-------- first invoke --------')
print(checkpointer)
# Resume with the edited text from the reviewer
final_state = graph.invoke(Command(resume="123"), config=config)
print(final_state["messages"]) # -> "Improved draft after review"
print('-------- second invoke --------')
print(checkpointer)
this code will cause a error
Traceback (most recent call last):
File "interrupt_redis.py", line 45, in <module>
final_state = graph.invoke(Command(resume="123"), config=config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/miniconda3/envs/ai-agent/lib/python3.11/site-packages/langgraph/pregel/main.py", line 3094, in invoke
for chunk in self.stream(
File "/miniconda3/envs/ai-agent/lib/python3.11/site-packages/langgraph/pregel/main.py", line 2615, in stream
with SyncPregelLoop(
File "/miniconda3/envs/ai-agent/lib/python3.11/site-packages/langgraph/pregel/_loop.py", line 1084, in __enter__
self.updated_channels = self._first(
^^^^^^^^^^^^
File "/miniconda3/envs/ai-agent/lib/python3.11/site-packages/langgraph/pregel/_loop.py", line 633, in _first
if len(self._pending_interrupts()) > 1:
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/miniconda3/envs/ai-agent/lib/python3.11/site-packages/langgraph/pregel/_loop.py", line 580, in _pending_interrupts
pending_interrupts[task_id] = value[0].id
^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'id'
I want to know what caused this and why it happened, and if there were any errors in my code
Metadata
Metadata
Assignees
Labels
No labels