Skip to content

Commit 542b744

Browse files
committed
fix: align chat agent with langgraph dev runtime
1 parent 7e43110 commit 542b744

5 files changed

Lines changed: 679 additions & 9 deletions

File tree

examples/chat-agent/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies = [
1212
[tool.uv]
1313
dev-dependencies = [
1414
"pytest>=8.0",
15-
"langgraph-cli>=0.1",
15+
"langgraph-cli[inmem]>=0.1",
1616
]
1717

1818
[build-system]

examples/chat-agent/src/chat_agent/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from dotenv import load_dotenv
66
from langchain_core.messages import SystemMessage
77
from langchain_core.runnables import RunnableConfig
8-
from langgraph.checkpoint.memory import MemorySaver
98
from langgraph.graph import END, START, MessagesState, StateGraph
109

1110
from chat_agent.config import Configuration
@@ -40,5 +39,6 @@ def call_model(state: MessagesState, config: RunnableConfig) -> dict:
4039
_builder.add_edge(START, "call_model")
4140
_builder.add_edge("call_model", END)
4241

43-
# Compile with MemorySaver — persists thread state for the server lifetime
44-
graph = _builder.compile(checkpointer=MemorySaver())
42+
# LangGraph API manages persistence for deployed graphs, so keep the exported
43+
# graph free of a custom checkpointer.
44+
graph = _builder.compile()

examples/chat-agent/tests/test_agent_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def test_single_turn():
2828

2929
@pytest.mark.integration
3030
@pytest.mark.skipif(not os.getenv("OPENAI_API_KEY"), reason=SKIP_REASON)
31-
def test_thread_persistence():
32-
"""MemorySaver persists messages across invocations on the same thread_id."""
31+
def test_repeated_invocation_with_thread_id():
32+
"""Repeated calls with the same thread_id should still produce valid responses."""
3333
from langchain_core.messages import AIMessage, HumanMessage
3434
from chat_agent.agent import graph
3535

@@ -46,4 +46,4 @@ def test_thread_persistence():
4646
)
4747
last = result["messages"][-1]
4848
assert isinstance(last, AIMessage)
49-
assert "PINEAPPLE" in last.content
49+
assert len(last.content) > 0

examples/chat-agent/tests/test_agent_smoke.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,22 @@ def test_graph_import_does_not_import_langchain_openai():
6666
spec.loader.exec_module(module)
6767

6868
assert "langchain_openai" not in sys.modules
69+
70+
71+
@pytest.mark.smoke
72+
def test_graph_does_not_define_a_custom_checkpointer():
73+
"""LangGraph API manages persistence itself, so the exported graph should not set one."""
74+
agent_path = Path(__file__).resolve().parents[1] / "src" / "chat_agent" / "agent.py"
75+
76+
import sys
77+
78+
sys.path.insert(0, str(agent_path.parents[1] / "src"))
79+
80+
spec = spec_from_file_location("deployed_agent_no_checkpointer", agent_path)
81+
assert spec is not None
82+
assert spec.loader is not None
83+
84+
module = module_from_spec(spec)
85+
spec.loader.exec_module(module)
86+
87+
assert getattr(module.graph, "checkpointer", None) is None

0 commit comments

Comments
 (0)