diff --git a/docs/docs/concepts/durable_execution.md b/docs/docs/concepts/durable_execution.md index ea0a38c03..88822ecea 100644 --- a/docs/docs/concepts/durable_execution.md +++ b/docs/docs/concepts/durable_execution.md @@ -48,7 +48,7 @@ If a [node](./low_level.md#nodes) contains multiple operations, you may find it from typing_extensions import TypedDict import uuid - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import StateGraph, START, END import requests @@ -74,7 +74,7 @@ If a [node](./low_level.md#nodes) contains multiple operations, you may find it builder.add_edge("call_api", END) # Specify a checkpointer - checkpointer = MemorySaver() + checkpointer = InMemorySaver() # Compile the graph with the checkpointer graph = builder.compile(checkpointer=checkpointer) @@ -94,7 +94,7 @@ If a [node](./low_level.md#nodes) contains multiple operations, you may find it from typing_extensions import TypedDict import uuid - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver from langgraph.func import task from langgraph.graph import StateGraph, START, END import requests @@ -129,7 +129,7 @@ If a [node](./low_level.md#nodes) contains multiple operations, you may find it builder.add_edge("call_api", END) # Specify a checkpointer - checkpointer = MemorySaver() + checkpointer = InMemorySaver() # Compile the graph with the checkpointer graph = builder.compile(checkpointer=checkpointer) diff --git a/docs/docs/concepts/functional_api.md b/docs/docs/concepts/functional_api.md index a0c910139..b2a3d97c7 100644 --- a/docs/docs/concepts/functional_api.md +++ b/docs/docs/concepts/functional_api.md @@ -39,7 +39,7 @@ Here are some key differences: Below we demonstrate a simple application that writes an essay and [interrupts](human_in_the_loop.md) to request human review. ```python -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.func import entrypoint, task from langgraph.types import interrupt @@ -50,7 +50,7 @@ def write_essay(topic: str) -> str: time.sleep(1) # A placeholder for a long-running task. return f"An essay about topic: {topic}" -@entrypoint(checkpointer=MemorySaver()) +@entrypoint(checkpointer=InMemorySaver()) def workflow(topic: str) -> dict: """A simple workflow that writes an essay and asks for a review.""" essay = write_essay("cat").result() @@ -82,7 +82,7 @@ def workflow(topic: str) -> dict: from langgraph.func import entrypoint, task from langgraph.types import interrupt - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver @task def write_essay(topic: str) -> str: @@ -90,7 +90,7 @@ def workflow(topic: str) -> dict: time.sleep(1) # This is a placeholder for a long-running task. return f"An essay about topic: {topic}" - @entrypoint(checkpointer=MemorySaver()) + @entrypoint(checkpointer=InMemorySaver()) def workflow(topic: str) -> dict: """A simple workflow that writes an essay and asks for a review.""" essay = write_essay("cat").result() diff --git a/docs/docs/concepts/persistence.md b/docs/docs/concepts/persistence.md index 185db6b62..7091cc03d 100644 --- a/docs/docs/concepts/persistence.md +++ b/docs/docs/concepts/persistence.md @@ -487,12 +487,12 @@ If you want to fallback to pickle for objects not currently supported by our msg you can use the `pickle_fallback` argument of the `JsonPlusSerializer`: ```python -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.checkpoint.serde.jsonplus import JsonPlusSerializer # ... Define the graph ... graph.compile( - checkpointer=MemorySaver(serde=JsonPlusSerializer(pickle_fallback=True)) + checkpointer=InMemorySaver(serde=JsonPlusSerializer(pickle_fallback=True)) ) ``` diff --git a/docs/docs/how-tos/autogen-integration-functional.ipynb b/docs/docs/how-tos/autogen-integration-functional.ipynb index 8f2888fa9..d568b329e 100644 --- a/docs/docs/how-tos/autogen-integration-functional.ipynb +++ b/docs/docs/how-tos/autogen-integration-functional.ipynb @@ -77,7 +77,7 @@ "metadata": {}, "outputs": [ { - "name": "stdin", + "name": "stdout", "output_type": "stream", "text": [ "OPENAI_API_KEY: ········\n" @@ -165,7 +165,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "d129e4e1-3766-429a-b806-cde3d8bc0469", "metadata": {}, "outputs": [], @@ -173,7 +173,7 @@ "from langchain_core.messages import convert_to_openai_messages, BaseMessage\n", "from langgraph.func import entrypoint, task\n", "from langgraph.graph import add_messages\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "\n", "\n", "@task\n", @@ -192,7 +192,7 @@ "\n", "\n", "# add short-term memory for storing conversation history\n", - "checkpointer = MemorySaver()\n", + "checkpointer = InMemorySaver()\n", "\n", "\n", "@entrypoint(checkpointer=checkpointer)\n", @@ -222,12 +222,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001B[33muser_proxy\u001B[0m (to assistant):\n", + "\u001b[33muser_proxy\u001b[0m (to assistant):\n", "\n", "Find numbers between 10 and 30 in fibonacci sequence\n", "\n", "--------------------------------------------------------------------------------\n", - "\u001B[33massistant\u001B[0m (to user_proxy):\n", + "\u001b[33massistant\u001b[0m (to user_proxy):\n", "\n", "To find numbers between 10 and 30 in the Fibonacci sequence, we can generate the Fibonacci sequence and check which numbers fall within this range. Here's a plan:\n", "\n", @@ -253,9 +253,9 @@ "This script will print the Fibonacci numbers between 10 and 30. Please execute the code to see the result.\n", "\n", "--------------------------------------------------------------------------------\n", - "\u001B[31m\n", - ">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...\u001B[0m\n", - "\u001B[33muser_proxy\u001B[0m (to assistant):\n", + "\u001b[31m\n", + ">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...\u001b[0m\n", + "\u001b[33muser_proxy\u001b[0m (to assistant):\n", "\n", "exitcode: 0 (execution succeeded)\n", "Code output: \n", @@ -264,7 +264,7 @@ "\n", "\n", "--------------------------------------------------------------------------------\n", - "\u001B[33massistant\u001B[0m (to user_proxy):\n", + "\u001b[33massistant\u001b[0m (to user_proxy):\n", "\n", "The Fibonacci numbers between 10 and 30 are 13 and 21. \n", "\n", @@ -318,7 +318,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001B[33muser_proxy\u001B[0m (to assistant):\n", + "\u001b[33muser_proxy\u001b[0m (to assistant):\n", "\n", "Multiply the last number by 3\n", "Context: \n", @@ -334,7 +334,7 @@ "TERMINATE\n", "\n", "--------------------------------------------------------------------------------\n", - "\u001B[33massistant\u001B[0m (to user_proxy):\n", + "\u001b[33massistant\u001b[0m (to user_proxy):\n", "\n", "The last number in the Fibonacci sequence between 10 and 30 is 21. Multiplying 21 by 3 gives:\n", "\n", diff --git a/docs/docs/how-tos/autogen-integration.md b/docs/docs/how-tos/autogen-integration.md index 905018a29..5e0db705b 100644 --- a/docs/docs/how-tos/autogen-integration.md +++ b/docs/docs/how-tos/autogen-integration.md @@ -75,7 +75,7 @@ We will now create a LangGraph chatbot graph that calls AutoGen agent. ```python from langchain_core.messages import convert_to_openai_messages from langgraph.graph import StateGraph, MessagesState, START -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver def call_autogen_agent(state: MessagesState): # Convert LangGraph messages to OpenAI format for AutoGen @@ -101,7 +101,7 @@ def call_autogen_agent(state: MessagesState): return {"messages": {"role": "assistant", "content": final_content}} # Create the graph with memory for persistence -checkpointer = MemorySaver() +checkpointer = InMemorySaver() # Build the graph builder = StateGraph(MessagesState) @@ -228,7 +228,7 @@ my-autogen-agent/ import autogen from langchain_core.messages import convert_to_openai_messages from langgraph.graph import StateGraph, MessagesState, START - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver # AutoGen configuration config_list = [{"model": "gpt-4o", "api_key": os.environ["OPENAI_API_KEY"]}] @@ -276,7 +276,7 @@ my-autogen-agent/ # Create and compile the graph def create_graph(): - checkpointer = MemorySaver() + checkpointer = InMemorySaver() builder = StateGraph(MessagesState) builder.add_node("autogen", call_autogen_agent) builder.add_edge(START, "autogen") diff --git a/docs/docs/how-tos/cross-thread-persistence-functional.ipynb b/docs/docs/how-tos/cross-thread-persistence-functional.ipynb index 92376135a..38e931a71 100644 --- a/docs/docs/how-tos/cross-thread-persistence-functional.ipynb +++ b/docs/docs/how-tos/cross-thread-persistence-functional.ipynb @@ -167,7 +167,7 @@ "from langchain_core.messages import BaseMessage\n", "from langgraph.func import entrypoint, task\n", "from langgraph.graph import add_messages\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from langgraph.store.base import BaseStore\n", "\n", "\n", @@ -192,7 +192,7 @@ "\n", "\n", "# NOTE: we're passing the store object here when creating a workflow via entrypoint()\n", - "@entrypoint(checkpointer=MemorySaver(), store=in_memory_store)\n", + "@entrypoint(checkpointer=InMemorySaver(), store=in_memory_store)\n", "def workflow(\n", " inputs: list[BaseMessage],\n", " *,\n", diff --git a/docs/docs/how-tos/human_in_the_loop/add-human-in-the-loop.md b/docs/docs/how-tos/human_in_the_loop/add-human-in-the-loop.md index 31c3d2b27..55b39c514 100644 --- a/docs/docs/how-tos/human_in_the_loop/add-human-in-the-loop.md +++ b/docs/docs/how-tos/human_in_the_loop/add-human-in-the-loop.md @@ -226,7 +226,7 @@ graph.invoke(Command(resume=True), config=thread_config) from langgraph.constants import START, END from langgraph.graph import StateGraph from langgraph.types import interrupt, Command - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver # Define the shared graph state class State(TypedDict): @@ -271,7 +271,7 @@ graph.invoke(Command(resume=True), config=thread_config) builder.add_edge("approved_path", END) builder.add_edge("rejected_path", END) - checkpointer = MemorySaver() + checkpointer = InMemorySaver() graph = builder.compile(checkpointer=checkpointer) # Run until interrupt @@ -339,7 +339,7 @@ graph.invoke( from langgraph.constants import START, END from langgraph.graph import StateGraph from langgraph.types import interrupt, Command - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver # Define the graph state class State(TypedDict): @@ -378,7 +378,7 @@ graph.invoke( builder.add_edge("downstream_use", END) # Set up in-memory checkpointing for interrupt support - checkpointer = MemorySaver() + checkpointer = InMemorySaver() graph = builder.compile(checkpointer=checkpointer) # Invoke the graph until it hits the interrupt @@ -655,7 +655,7 @@ def human_node(state: State): from langgraph.constants import START, END from langgraph.graph import StateGraph from langgraph.types import interrupt, Command - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver # Define graph state class State(TypedDict): @@ -694,7 +694,7 @@ def human_node(state: State): builder.add_edge("report_age", END) # Create the graph with a memory checkpointer - checkpointer = MemorySaver() + checkpointer = InMemorySaver() graph = builder.compile(checkpointer=checkpointer) # Run the graph until the first interrupt @@ -951,7 +951,7 @@ def node_in_parent_graph(state: State): from langgraph.graph import StateGraph from langgraph.constants import START from langgraph.types import interrupt, Command - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver class State(TypedDict): @@ -977,7 +977,7 @@ def node_in_parent_graph(state: State): print(f"Got an answer of {answer}") - checkpointer = MemorySaver() + checkpointer = InMemorySaver() subgraph_builder = StateGraph(State) subgraph_builder.add_node("some_node", node_in_subgraph) @@ -1008,7 +1008,7 @@ def node_in_parent_graph(state: State): builder.add_edge(START, "parent_node") # A checkpointer must be enabled for interrupts to work! - checkpointer = MemorySaver() + checkpointer = InMemorySaver() graph = builder.compile(checkpointer=checkpointer) config = { @@ -1057,7 +1057,7 @@ To avoid issues, refrain from dynamically changing the node's structure between from langgraph.graph import StateGraph from langgraph.constants import START from langgraph.types import interrupt, Command - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver class State(TypedDict): @@ -1091,7 +1091,7 @@ To avoid issues, refrain from dynamically changing the node's structure between builder.add_edge(START, "human_node") # A checkpointer must be enabled for interrupts to work! - checkpointer = MemorySaver() + checkpointer = InMemorySaver() graph = builder.compile(checkpointer=checkpointer) config = { diff --git a/docs/docs/how-tos/human_in_the_loop/wait-user-input.ipynb b/docs/docs/how-tos/human_in_the_loop/wait-user-input.ipynb index bbe14b4f1..c409d2fe2 100644 --- a/docs/docs/how-tos/human_in_the_loop/wait-user-input.ipynb +++ b/docs/docs/how-tos/human_in_the_loop/wait-user-input.ipynb @@ -121,7 +121,7 @@ "\n", "# highlight-next-line\n", "from langgraph.types import Command, interrupt\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from IPython.display import Image, display\n", "\n", "\n", @@ -157,7 +157,7 @@ "builder.add_edge(\"step_3\", END)\n", "\n", "# Set up memory\n", - "memory = MemorySaver()\n", + "memory = InMemorySaver()\n", "\n", "# Add\n", "graph = builder.compile(checkpointer=memory)\n", @@ -435,9 +435,9 @@ "workflow.add_edge(\"ask_human\", \"agent\")\n", "\n", "# Set up memory\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "\n", - "memory = MemorySaver()\n", + "memory = InMemorySaver()\n", "\n", "# Finally, we compile it!\n", "# This compiles it into a LangChain Runnable,\n", diff --git a/docs/docs/how-tos/multi-agent-multi-turn-convo-functional.ipynb b/docs/docs/how-tos/multi-agent-multi-turn-convo-functional.ipynb index d81525f08..a19179044 100644 --- a/docs/docs/how-tos/multi-agent-multi-turn-convo-functional.ipynb +++ b/docs/docs/how-tos/multi-agent-multi-turn-convo-functional.ipynb @@ -224,7 +224,7 @@ "from langgraph.prebuilt import create_react_agent\n", "from langgraph.graph import add_messages\n", "from langgraph.func import entrypoint, task\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from langgraph.types import interrupt, Command\n", "\n", "model = ChatAnthropic(model=\"claude-3-5-sonnet-latest\")\n", @@ -272,7 +272,7 @@ " return response[\"messages\"]\n", "\n", "\n", - "checkpointer = MemorySaver()\n", + "checkpointer = InMemorySaver()\n", "\n", "\n", "def string_to_uuid(input_string):\n", diff --git a/docs/docs/how-tos/multi_agent.md b/docs/docs/how-tos/multi_agent.md index fdd781d4f..eca36301c 100644 --- a/docs/docs/how-tos/multi_agent.md +++ b/docs/docs/how-tos/multi_agent.md @@ -375,7 +375,7 @@ def agent(state) -> Command[Literal["agent", "another_agent", "human"]]: from langgraph.graph import MessagesState, StateGraph, START from langgraph.prebuilt import create_react_agent, InjectedState from langgraph.types import Command, interrupt - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver model = ChatAnthropic(model="claude-3-5-sonnet-latest") @@ -467,7 +467,7 @@ def agent(state) -> Command[Literal["agent", "another_agent", "human"]]: builder.add_edge(START, "travel_advisor") - checkpointer = MemorySaver() + checkpointer = InMemorySaver() graph = builder.compile(checkpointer=checkpointer) ``` diff --git a/docs/docs/how-tos/persistence-functional.ipynb b/docs/docs/how-tos/persistence-functional.ipynb index e6c0a2679..b1a045400 100644 --- a/docs/docs/how-tos/persistence-functional.ipynb +++ b/docs/docs/how-tos/persistence-functional.ipynb @@ -28,9 +28,9 @@ "1. Create an instance of a checkpointer:\n", "\n", " ```python\n", - " from langgraph.checkpoint.memory import MemorySaver\n", + " from langgraph.checkpoint.memory import InMemorySaver\n", " \n", - " checkpointer = MemorySaver() \n", + " checkpointer = InMemorySaver() \n", " ```\n", "\n", "2. Pass `checkpointer` instance to the `entrypoint()` decorator:\n", @@ -184,7 +184,7 @@ "from langchain_core.messages import BaseMessage\n", "from langgraph.graph import add_messages\n", "from langgraph.func import entrypoint, task\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "\n", "\n", "@task\n", @@ -193,7 +193,7 @@ " return response\n", "\n", "\n", - "checkpointer = MemorySaver()\n", + "checkpointer = InMemorySaver()\n", "\n", "\n", "@entrypoint(checkpointer=checkpointer)\n", diff --git a/docs/docs/how-tos/react-agent-from-scratch-functional.ipynb b/docs/docs/how-tos/react-agent-from-scratch-functional.ipynb index 0e5de1bce..eeb8b21b5 100644 --- a/docs/docs/how-tos/react-agent-from-scratch-functional.ipynb +++ b/docs/docs/how-tos/react-agent-from-scratch-functional.ipynb @@ -261,7 +261,7 @@ "\n", "To add thread-level persistence to our agent:\n", "\n", - "1. Select a [checkpointer](../../concepts/persistence#checkpointer-libraries): here we will use [MemorySaver](../../reference/checkpoints/#langgraph.checkpoint.memory.MemorySaver), a simple in-memory checkpointer.\n", + "1. Select a [checkpointer](../../concepts/persistence#checkpointer-libraries): here we will use [InMemorySaver](../../reference/checkpoints/#langgraph.checkpoint.memory.InMemorySaver), a simple in-memory checkpointer.\n", "2. Update our entrypoint to accept the previous messages state as a second argument. Here, we simply append the message updates to the previous sequence of messages.\n", "3. Choose which values will be returned from the workflow and which will be saved by the checkpointer as `previous` using `entrypoint.final` (optional)" ] @@ -272,10 +272,10 @@ "metadata": {}, "outputs": [], "source": [ - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "\n", "# highlight-next-line\n", - "checkpointer = MemorySaver()\n", + "checkpointer = InMemorySaver()\n", "\n", "\n", "# highlight-next-line\n", diff --git a/docs/docs/how-tos/use-functional-api.md b/docs/docs/how-tos/use-functional-api.md index df515c52b..654930f69 100644 --- a/docs/docs/how-tos/use-functional-api.md +++ b/docs/docs/how-tos/use-functional-api.md @@ -26,7 +26,7 @@ my_workflow.invoke({"value": 1, "another_value": 2}) ```python import uuid from langgraph.func import entrypoint, task - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver # Task that checks if a number is even @task @@ -39,7 +39,7 @@ my_workflow.invoke({"value": 1, "another_value": 2}) return "The number is even." if is_even else "The number is odd." # Create a checkpointer for persistence - checkpointer = MemorySaver() + checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) def workflow(inputs: dict) -> str: @@ -63,7 +63,7 @@ my_workflow.invoke({"value": 1, "another_value": 2}) import uuid from langchain.chat_models import init_chat_model from langgraph.func import entrypoint, task - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver llm = init_chat_model('openai:gpt-3.5-turbo') @@ -77,7 +77,7 @@ my_workflow.invoke({"value": 1, "another_value": 2}) ]).content # Create a checkpointer for persistence - checkpointer = MemorySaver() + checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) def workflow(topic: str) -> str: @@ -114,7 +114,7 @@ def graph(numbers: list[int]) -> list[str]: import uuid from langchain.chat_models import init_chat_model from langgraph.func import entrypoint, task - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver # Initialize the LLM model llm = init_chat_model("openai:gpt-3.5-turbo") @@ -129,7 +129,7 @@ def graph(numbers: list[int]) -> list[str]: return response.content # Create a checkpointer for persistence - checkpointer = MemorySaver() + checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) def workflow(topics: list[str]) -> str: @@ -176,7 +176,7 @@ def some_workflow(some_input: dict) -> int: import uuid from typing import TypedDict from langgraph.func import entrypoint - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import StateGraph # Define the shared state type @@ -194,7 +194,7 @@ def some_workflow(some_input: dict) -> int: graph = builder.compile() # Define the functional API workflow - checkpointer = MemorySaver() + checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) def workflow(x: int) -> dict: @@ -227,10 +227,10 @@ def my_workflow(inputs: dict) -> int: ```python import uuid from langgraph.func import entrypoint - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver # Initialize a checkpointer - checkpointer = MemorySaver() + checkpointer = InMemorySaver() # A reusable sub-workflow that multiplies a number @entrypoint() @@ -258,10 +258,10 @@ Example of using the streaming API to stream both updates and custom data. ```python from langgraph.func import entrypoint -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.config import get_stream_writer # (1)! -checkpointer = MemorySaver() +checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) def main(inputs: dict) -> int: @@ -316,7 +316,7 @@ for mode, chunk in main.stream( # (5)! ## Retry policy ```python -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.func import entrypoint, task from langgraph.types import RetryPolicy @@ -337,7 +337,7 @@ def get_info(): raise ValueError('Failure') return "OK" -checkpointer = MemorySaver() +checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) def main(inputs, writer): @@ -392,7 +392,7 @@ for chunk in main.stream({"x": 5}, stream_mode="updates"): ```python import time -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.func import entrypoint, task from langgraph.types import StreamWriter @@ -414,7 +414,7 @@ def get_info(): return "OK" # Initialize an in-memory checkpointer for persistence -checkpointer = MemorySaver() +checkpointer = InMemorySaver() @task def slow_task(): @@ -504,9 +504,9 @@ def step_3(input_query): We can now compose these tasks in an [entrypoint](../concepts/functional_api.md#entrypoint): ```python -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver -checkpointer = MemorySaver() +checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) @@ -577,12 +577,12 @@ def review_tool_call(tool_call: ToolCall) -> Union[ToolCall, ToolMessage]: We can now update our [entrypoint](../concepts/functional_api.md#entrypoint) to review the generated tool calls. If a tool call is accepted or revised, we execute in the same way as before. Otherwise, we just append the `ToolMessage` supplied by the human. The results of prior tasks — in this case the initial model call — are persisted, so that they are not run again following the `interrupt`. ```python -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph.message import add_messages from langgraph.types import Command, interrupt -checkpointer = MemorySaver() +checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) @@ -757,9 +757,9 @@ Use `entrypoint.final` to decouple what is returned to the caller from what is p ```python from typing import Optional from langgraph.func import entrypoint -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver -checkpointer = MemorySaver() +checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) def accumulate(n: int, *, previous: Optional[int]) -> entrypoint.final[int, int]: @@ -777,14 +777,14 @@ print(accumulate.invoke(3, config=config)) # 3 ### Chatbot example -An example of a simple chatbot using the functional API and the `MemorySaver` checkpointer. +An example of a simple chatbot using the functional API and the `InMemorySaver` checkpointer. The bot is able to remember the previous conversation and continue from where it left off. ```python from langchain_core.messages import BaseMessage from langgraph.graph import add_messages from langgraph.func import entrypoint, task -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langchain_anthropic import ChatAnthropic model = ChatAnthropic(model="claude-3-5-sonnet-latest") @@ -794,7 +794,7 @@ def call_model(messages: list[BaseMessage]): response = model.invoke(messages) return response -checkpointer = MemorySaver() +checkpointer = InMemorySaver() @entrypoint(checkpointer=checkpointer) def workflow(inputs: list[BaseMessage], *, previous: list[BaseMessage]): diff --git a/docs/docs/tutorials/chatbots/information-gather-prompting.ipynb b/docs/docs/tutorials/chatbots/information-gather-prompting.ipynb index 13ab735e6..b1eb1ad01 100644 --- a/docs/docs/tutorials/chatbots/information-gather-prompting.ipynb +++ b/docs/docs/tutorials/chatbots/information-gather-prompting.ipynb @@ -256,7 +256,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from langgraph.graph import StateGraph, START\n", "from langgraph.graph.message import add_messages\n", "from typing import Annotated\n", @@ -267,7 +267,7 @@ " messages: Annotated[list, add_messages]\n", "\n", "\n", - "memory = MemorySaver()\n", + "memory = InMemorySaver()\n", "workflow = StateGraph(State)\n", "workflow.add_node(\"info\", info_chain)\n", "workflow.add_node(\"prompt\", prompt_gen_chain)\n", diff --git a/docs/docs/tutorials/customer-support/customer-support.ipynb b/docs/docs/tutorials/customer-support/customer-support.ipynb index 8df8c5c15..c25bd8297 100644 --- a/docs/docs/tutorials/customer-support/customer-support.ipynb +++ b/docs/docs/tutorials/customer-support/customer-support.ipynb @@ -1124,7 +1124,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from langgraph.graph import END, StateGraph, START\n", "from langgraph.prebuilt import tools_condition\n", "\n", @@ -1144,7 +1144,7 @@ "\n", "# The checkpointer lets the graph persist its state\n", "# this is a complete memory for the entire graph.\n", - "memory = MemorySaver()\n", + "memory = InMemorySaver()\n", "part_1_graph = builder.compile(checkpointer=memory)" ] }, @@ -1943,7 +1943,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from langgraph.graph import StateGraph\n", "from langgraph.prebuilt import tools_condition\n", "\n", @@ -1967,7 +1967,7 @@ ")\n", "builder.add_edge(\"tools\", \"assistant\")\n", "\n", - "memory = MemorySaver()\n", + "memory = InMemorySaver()\n", "part_2_graph = builder.compile(\n", " checkpointer=memory,\n", " # NEW: The graph will always halt before executing the \"tools\" node.\n", @@ -2532,7 +2532,7 @@ "source": [ "from typing import Literal\n", "\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from langgraph.graph import StateGraph\n", "from langgraph.prebuilt import tools_condition\n", "\n", @@ -2576,7 +2576,7 @@ "builder.add_edge(\"safe_tools\", \"assistant\")\n", "builder.add_edge(\"sensitive_tools\", \"assistant\")\n", "\n", - "memory = MemorySaver()\n", + "memory = InMemorySaver()\n", "part_3_graph = builder.compile(\n", " checkpointer=memory,\n", " # NEW: The graph will always halt before executing the \"tools\" node.\n", @@ -3477,7 +3477,7 @@ "source": [ "from typing import Literal\n", "\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from langgraph.graph import StateGraph\n", "from langgraph.prebuilt import tools_condition\n", "\n", @@ -3841,7 +3841,7 @@ "builder.add_conditional_edges(\"fetch_user_info\", route_to_workflow)\n", "\n", "# Compile graph\n", - "memory = MemorySaver()\n", + "memory = InMemorySaver()\n", "part_4_graph = builder.compile(\n", " checkpointer=memory,\n", " # Let the user approve or deny the use of sensitive tools\n", diff --git a/docs/docs/tutorials/get-started/3-add-memory.md b/docs/docs/tutorials/get-started/3-add-memory.md index 9087fb86c..728ffba51 100644 --- a/docs/docs/tutorials/get-started/3-add-memory.md +++ b/docs/docs/tutorials/get-started/3-add-memory.md @@ -10,14 +10,14 @@ We will see later that **checkpointing** is _much_ more powerful than simple cha This tutorial builds on [Add tools](./2-add-tools.md). -## 1. Create a `MemorySaver` checkpointer +## 1. Create a `InMemorySaver` checkpointer -Create a `MemorySaver` checkpointer: +Create a `InMemorySaver` checkpointer: ``` python -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver -memory = MemorySaver() +memory = InMemorySaver() ``` This is in-memory checkpointer, which is convenient for the tutorial. However, in a production application, you would likely change this to use `SqliteSaver` or `PostgresSaver` and connect a database. @@ -172,7 +172,7 @@ from langchain_tavily import TavilySearch from langchain_core.messages import BaseMessage from typing_extensions import TypedDict -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import StateGraph from langgraph.graph.message import add_messages from langgraph.prebuilt import ToolNode, tools_condition @@ -200,7 +200,7 @@ graph_builder.add_conditional_edges( ) graph_builder.add_edge("tools", "chatbot") graph_builder.set_entry_point("chatbot") -memory = MemorySaver() +memory = InMemorySaver() graph = graph_builder.compile(checkpointer=memory) ``` diff --git a/docs/docs/tutorials/get-started/4-human-in-the-loop.md b/docs/docs/tutorials/get-started/4-human-in-the-loop.md index c37f3a3f8..cf1c5ba4a 100644 --- a/docs/docs/tutorials/get-started/4-human-in-the-loop.md +++ b/docs/docs/tutorials/get-started/4-human-in-the-loop.md @@ -33,7 +33,7 @@ from langchain_tavily import TavilySearch from langchain_core.tools import tool from typing_extensions import TypedDict -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import StateGraph, START, END from langgraph.graph.message import add_messages from langgraph.prebuilt import ToolNode, tools_condition @@ -85,7 +85,7 @@ graph_builder.add_edge(START, "chatbot") We compile the graph with a checkpointer, as before: ```python -memory = MemorySaver() +memory = InMemorySaver() graph = graph_builder.compile(checkpointer=memory) ``` @@ -230,7 +230,7 @@ from langchain_tavily import TavilySearch from langchain_core.tools import tool from typing_extensions import TypedDict -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import StateGraph, START, END from langgraph.graph.message import add_messages from langgraph.prebuilt import ToolNode, tools_condition @@ -268,7 +268,7 @@ graph_builder.add_conditional_edges( graph_builder.add_edge("tools", "chatbot") graph_builder.add_edge(START, "chatbot") -memory = MemorySaver() +memory = InMemorySaver() graph = graph_builder.compile(checkpointer=memory) ``` diff --git a/docs/docs/tutorials/get-started/5-customize-state.md b/docs/docs/tutorials/get-started/5-customize-state.md index 84d3cda7d..8be1a9246 100644 --- a/docs/docs/tutorials/get-started/5-customize-state.md +++ b/docs/docs/tutorials/get-started/5-customize-state.md @@ -239,7 +239,7 @@ from langchain_core.messages import ToolMessage from langchain_core.tools import InjectedToolCallId, tool from typing_extensions import TypedDict -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import StateGraph, START, END from langgraph.graph.message import add_messages from langgraph.prebuilt import ToolNode, tools_condition @@ -301,7 +301,7 @@ graph_builder.add_conditional_edges( graph_builder.add_edge("tools", "chatbot") graph_builder.add_edge(START, "chatbot") -memory = MemorySaver() +memory = InMemorySaver() graph = graph_builder.compile(checkpointer=memory) ``` diff --git a/docs/docs/tutorials/get-started/6-time-travel.md b/docs/docs/tutorials/get-started/6-time-travel.md index 16d515091..eabb46e4f 100644 --- a/docs/docs/tutorials/get-started/6-time-travel.md +++ b/docs/docs/tutorials/get-started/6-time-travel.md @@ -31,7 +31,7 @@ from langchain_tavily import TavilySearch from langchain_core.messages import BaseMessage from typing_extensions import TypedDict -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import StateGraph, START, END from langgraph.graph.message import add_messages from langgraph.prebuilt import ToolNode, tools_condition @@ -60,7 +60,7 @@ graph_builder.add_conditional_edges( graph_builder.add_edge("tools", "chatbot") graph_builder.add_edge(START, "chatbot") -memory = MemorySaver() +memory = InMemorySaver() graph = graph_builder.compile(checkpointer=memory) ``` diff --git a/docs/docs/tutorials/langgraph-platform/local-server.md b/docs/docs/tutorials/langgraph-platform/local-server.md index 1ff5e082b..70c9478c6 100644 --- a/docs/docs/tutorials/langgraph-platform/local-server.md +++ b/docs/docs/tutorials/langgraph-platform/local-server.md @@ -12,9 +12,9 @@ Before you begin, ensure you have the following: === "Python server" - ```shell - # Python >= 3.11 is required. + Python >= 3.11 is required. + ```shell pip install --upgrade "langgraph-cli[inmem]" ``` diff --git a/docs/docs/tutorials/reflection/reflection.ipynb b/docs/docs/tutorials/reflection/reflection.ipynb index bd9b018af..26d6fe60d 100644 --- a/docs/docs/tutorials/reflection/reflection.ipynb +++ b/docs/docs/tutorials/reflection/reflection.ipynb @@ -322,7 +322,7 @@ "from typing import Annotated, List, Sequence\n", "from langgraph.graph import END, StateGraph, START\n", "from langgraph.graph.message import add_messages\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from typing_extensions import TypedDict\n", "\n", "\n", @@ -361,7 +361,7 @@ "\n", "builder.add_conditional_edges(\"generate\", should_continue)\n", "builder.add_edge(\"reflect\", \"generate\")\n", - "memory = MemorySaver()\n", + "memory = InMemorySaver()\n", "graph = builder.compile(checkpointer=memory)" ] }, diff --git a/docs/docs/tutorials/tot/tot.ipynb b/docs/docs/tutorials/tot/tot.ipynb index 29fe435bc..40f5216c5 100644 --- a/docs/docs/tutorials/tot/tot.ipynb +++ b/docs/docs/tutorials/tot/tot.ipynb @@ -283,7 +283,7 @@ "\n", "from langchain_core.runnables import RunnableConfig\n", "from langgraph.constants import Send\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "\n", "\n", "def update_candidates(\n", @@ -412,7 +412,7 @@ "builder.add_edge(\"__start__\", \"expand\")\n", "\n", "# Compile the graph\n", - "graph = builder.compile(checkpointer=MemorySaver())" + "graph = builder.compile(checkpointer=InMemorySaver())" ] }, { diff --git a/docs/docs/tutorials/usaco/usaco.ipynb b/docs/docs/tutorials/usaco/usaco.ipynb index 407f564ee..078e6eaae 100644 --- a/docs/docs/tutorials/usaco/usaco.ipynb +++ b/docs/docs/tutorials/usaco/usaco.ipynb @@ -1029,7 +1029,7 @@ "metadata": {}, "outputs": [], "source": [ - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from langgraph.graph import END, StateGraph, START\n", "\n", "builder = StateGraph(State)\n", @@ -1053,7 +1053,7 @@ "builder.add_conditional_edges(\"evaluate\", control_edge, {END: END, \"solve\": \"solve\"})\n", "\n", "\n", - "checkpointer = MemorySaver()\n", + "checkpointer = InMemorySaver()\n", "graph = builder.compile(checkpointer=checkpointer)" ] }, @@ -1327,7 +1327,7 @@ "outputs": [], "source": [ "# This is all the same as before\n", - "from langgraph.checkpoint.memory import MemorySaver\n", + "from langgraph.checkpoint.memory import InMemorySaver\n", "from langgraph.graph import END, StateGraph, START\n", "\n", "builder = StateGraph(State)\n", @@ -1353,7 +1353,7 @@ "\n", "\n", "builder.add_conditional_edges(\"evaluate\", control_edge, {END: END, \"solve\": \"solve\"})\n", - "checkpointer = MemorySaver()" + "checkpointer = InMemorySaver()" ] }, { diff --git a/examples/code_assistant/langgraph_code_assistant_mistral.ipynb b/examples/code_assistant/langgraph_code_assistant_mistral.ipynb index 8d873d68c..1c666241f 100644 --- a/examples/code_assistant/langgraph_code_assistant_mistral.ipynb +++ b/examples/code_assistant/langgraph_code_assistant_mistral.ipynb @@ -154,7 +154,7 @@ "id": "2dff2209-44c7-4e2c-b607-ba6675f9e45f", "metadata": {}, "outputs": [], - "source": ["from langgraph.checkpoint.memory import MemorySaver\nfrom langgraph.graph import END, StateGraph, START\n\nbuilder = StateGraph(GraphState)\n\n# Define the nodes\nbuilder.add_node(\"generate\", generate) # generation solution\nbuilder.add_node(\"check_code\", code_check) # check code\n\n# Build graph\nbuilder.add_edge(START, \"generate\")\nbuilder.add_edge(\"generate\", \"check_code\")\nbuilder.add_conditional_edges(\n \"check_code\",\n decide_to_finish,\n {\n \"end\": END,\n \"generate\": \"generate\",\n },\n)\n\nmemory = MemorySaver()\ngraph = builder.compile(checkpointer=memory)"] + "source": ["from langgraph.checkpoint.memory import InMemorySaver\nfrom langgraph.graph import END, StateGraph, START\n\nbuilder = StateGraph(GraphState)\n\n# Define the nodes\nbuilder.add_node(\"generate\", generate) # generation solution\nbuilder.add_node(\"check_code\", code_check) # check code\n\n# Build graph\nbuilder.add_edge(START, \"generate\")\nbuilder.add_edge(\"generate\", \"check_code\")\nbuilder.add_conditional_edges(\n \"check_code\",\n decide_to_finish,\n {\n \"end\": END,\n \"generate\": \"generate\",\n },\n)\n\nmemory = InMemorySaver()\ngraph = builder.compile(checkpointer=memory)"] }, { "cell_type": "code", diff --git a/libs/checkpoint/README.md b/libs/checkpoint/README.md index 4877a17b9..f3fd43836 100644 --- a/libs/checkpoint/README.md +++ b/libs/checkpoint/README.md @@ -44,12 +44,12 @@ If the checkpointer will be used with asynchronous graph execution (i.e. executi ## Usage ```python -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver write_config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}} read_config = {"configurable": {"thread_id": "1"}} -checkpointer = MemorySaver() +checkpointer = InMemorySaver() checkpoint = { "v": 4, "ts": "2024-07-31T20:14:19.804150+00:00", diff --git a/libs/checkpoint/tests/test_memory.py b/libs/checkpoint/tests/test_memory.py index 4893a3d59..a39ddad5e 100644 --- a/libs/checkpoint/tests/test_memory.py +++ b/libs/checkpoint/tests/test_memory.py @@ -190,6 +190,6 @@ class TestMemorySaver: def test_memory_saver() -> None: - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver - assert isinstance(MemorySaver(), InMemorySaver) + assert isinstance(InMemorySaver(), InMemorySaver) diff --git a/libs/langgraph/bench/__main__.py b/libs/langgraph/bench/__main__.py index f75f2122b..f860ede57 100644 --- a/libs/langgraph/bench/__main__.py +++ b/libs/langgraph/bench/__main__.py @@ -11,7 +11,7 @@ from bench.react_agent import react_agent from bench.sequential import create_sequential from bench.wide_dict import wide_dict from bench.wide_state import wide_state -from langgraph.checkpoint.memory import MemorySaver +from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import StateGraph from langgraph.pregel import Pregel @@ -108,8 +108,8 @@ benchmarks = ( ), ( "fanout_to_subgraph_10x_checkpoint", - fanout_to_subgraph().compile(checkpointer=MemorySaver()), - fanout_to_subgraph_sync().compile(checkpointer=MemorySaver()), + fanout_to_subgraph().compile(checkpointer=InMemorySaver()), + fanout_to_subgraph_sync().compile(checkpointer=InMemorySaver()), { "subjects": [ random.choices("abcdefghijklmnopqrstuvwxyz", k=1000) for _ in range(10) @@ -128,8 +128,8 @@ benchmarks = ( ), ( "fanout_to_subgraph_100x_checkpoint", - fanout_to_subgraph().compile(checkpointer=MemorySaver()), - fanout_to_subgraph_sync().compile(checkpointer=MemorySaver()), + fanout_to_subgraph().compile(checkpointer=InMemorySaver()), + fanout_to_subgraph_sync().compile(checkpointer=InMemorySaver()), { "subjects": [ random.choices("abcdefghijklmnopqrstuvwxyz", k=1000) for _ in range(100) @@ -144,8 +144,8 @@ benchmarks = ( ), ( "react_agent_10x_checkpoint", - react_agent(10, checkpointer=MemorySaver()), - react_agent(10, checkpointer=MemorySaver()), + react_agent(10, checkpointer=InMemorySaver()), + react_agent(10, checkpointer=InMemorySaver()), {"messages": [HumanMessage("hi?")]}, ), ( @@ -156,8 +156,8 @@ benchmarks = ( ), ( "react_agent_100x_checkpoint", - react_agent(100, checkpointer=MemorySaver()), - react_agent(100, checkpointer=MemorySaver()), + react_agent(100, checkpointer=InMemorySaver()), + react_agent(100, checkpointer=InMemorySaver()), {"messages": [HumanMessage("hi?")]}, ), ( @@ -178,8 +178,8 @@ benchmarks = ( ), ( "wide_state_25x300_checkpoint", - wide_state(300).compile(checkpointer=MemorySaver()), - wide_state(300).compile(checkpointer=MemorySaver()), + wide_state(300).compile(checkpointer=InMemorySaver()), + wide_state(300).compile(checkpointer=InMemorySaver()), { "messages": [ { @@ -210,8 +210,8 @@ benchmarks = ( ), ( "wide_state_15x600_checkpoint", - wide_state(600).compile(checkpointer=MemorySaver()), - wide_state(600).compile(checkpointer=MemorySaver()), + wide_state(600).compile(checkpointer=InMemorySaver()), + wide_state(600).compile(checkpointer=InMemorySaver()), { "messages": [ { @@ -242,8 +242,8 @@ benchmarks = ( ), ( "wide_state_9x1200_checkpoint", - wide_state(1200).compile(checkpointer=MemorySaver()), - wide_state(1200).compile(checkpointer=MemorySaver()), + wide_state(1200).compile(checkpointer=InMemorySaver()), + wide_state(1200).compile(checkpointer=InMemorySaver()), { "messages": [ { @@ -274,8 +274,8 @@ benchmarks = ( ), ( "wide_dict_25x300_checkpoint", - wide_dict(300).compile(checkpointer=MemorySaver()), - wide_dict(300).compile(checkpointer=MemorySaver()), + wide_dict(300).compile(checkpointer=InMemorySaver()), + wide_dict(300).compile(checkpointer=InMemorySaver()), { "messages": [ { @@ -306,8 +306,8 @@ benchmarks = ( ), ( "wide_dict_15x600_checkpoint", - wide_dict(600).compile(checkpointer=MemorySaver()), - wide_dict(600).compile(checkpointer=MemorySaver()), + wide_dict(600).compile(checkpointer=InMemorySaver()), + wide_dict(600).compile(checkpointer=InMemorySaver()), { "messages": [ { @@ -338,8 +338,8 @@ benchmarks = ( ), ( "wide_dict_9x1200_checkpoint", - wide_dict(1200).compile(checkpointer=MemorySaver()), - wide_dict(1200).compile(checkpointer=MemorySaver()), + wide_dict(1200).compile(checkpointer=InMemorySaver()), + wide_dict(1200).compile(checkpointer=InMemorySaver()), { "messages": [ { @@ -382,8 +382,8 @@ benchmarks = ( ), ( "pydantic_state_25x300_checkpoint", - pydantic_state(300).compile(checkpointer=MemorySaver()), - pydantic_state(300).compile(checkpointer=MemorySaver()), + pydantic_state(300).compile(checkpointer=InMemorySaver()), + pydantic_state(300).compile(checkpointer=InMemorySaver()), { "messages": [ { @@ -414,8 +414,8 @@ benchmarks = ( ), ( "pydantic_state_15x600_checkpoint", - pydantic_state(600).compile(checkpointer=MemorySaver()), - pydantic_state(600).compile(checkpointer=MemorySaver()), + pydantic_state(600).compile(checkpointer=InMemorySaver()), + pydantic_state(600).compile(checkpointer=InMemorySaver()), { "messages": [ { @@ -446,8 +446,8 @@ benchmarks = ( ), ( "pydantic_state_9x1200_checkpoint", - pydantic_state(1200).compile(checkpointer=MemorySaver()), - pydantic_state(1200).compile(checkpointer=MemorySaver()), + pydantic_state(1200).compile(checkpointer=InMemorySaver()), + pydantic_state(1200).compile(checkpointer=InMemorySaver()), { "messages": [ { diff --git a/libs/langgraph/bench/fanout_to_subgraph.py b/libs/langgraph/bench/fanout_to_subgraph.py index ade894acc..e6ebc001a 100644 --- a/libs/langgraph/bench/fanout_to_subgraph.py +++ b/libs/langgraph/bench/fanout_to_subgraph.py @@ -114,9 +114,9 @@ if __name__ == "__main__": import uvloop - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver - graph = fanout_to_subgraph().compile(checkpointer=MemorySaver()) + graph = fanout_to_subgraph().compile(checkpointer=InMemorySaver()) input = { "subjects": [ random.choices("abcdefghijklmnopqrstuvwxyz", k=1000) for _ in range(1000) diff --git a/libs/langgraph/bench/pydantic_state.py b/libs/langgraph/bench/pydantic_state.py index 7c5fd0e0e..acbc428ea 100644 --- a/libs/langgraph/bench/pydantic_state.py +++ b/libs/langgraph/bench/pydantic_state.py @@ -304,9 +304,9 @@ if __name__ == "__main__": import uvloop - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver - graph = pydantic_state(1000).compile(checkpointer=MemorySaver()) + graph = pydantic_state(1000).compile(checkpointer=InMemorySaver()) input = { "messages": [ { diff --git a/libs/langgraph/bench/react_agent.py b/libs/langgraph/bench/react_agent.py index 59e60fb95..b4a8dcc60 100644 --- a/libs/langgraph/bench/react_agent.py +++ b/libs/langgraph/bench/react_agent.py @@ -68,9 +68,9 @@ if __name__ == "__main__": import uvloop - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver - graph = react_agent(100, checkpointer=MemorySaver()) + graph = react_agent(100, checkpointer=InMemorySaver()) input = {"messages": [HumanMessage("hi?")]} config = {"configurable": {"thread_id": "1"}, "recursion_limit": 20000000000} diff --git a/libs/langgraph/bench/wide_dict.py b/libs/langgraph/bench/wide_dict.py index 79549346c..7ff22e519 100644 --- a/libs/langgraph/bench/wide_dict.py +++ b/libs/langgraph/bench/wide_dict.py @@ -130,9 +130,9 @@ if __name__ == "__main__": import uvloop - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver - graph = wide_dict(1000).compile(checkpointer=MemorySaver()) + graph = wide_dict(1000).compile(checkpointer=InMemorySaver()) input = { "messages": [ { diff --git a/libs/langgraph/bench/wide_state.py b/libs/langgraph/bench/wide_state.py index 04c50632a..eb2b036ff 100644 --- a/libs/langgraph/bench/wide_state.py +++ b/libs/langgraph/bench/wide_state.py @@ -140,9 +140,9 @@ if __name__ == "__main__": import uvloop - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver - graph = wide_state(1000).compile(checkpointer=MemorySaver()) + graph = wide_state(1000).compile(checkpointer=InMemorySaver()) input = { "messages": [ { diff --git a/libs/langgraph/langgraph/func/__init__.py b/libs/langgraph/langgraph/func/__init__.py index fa2e09ad7..71879d571 100644 --- a/libs/langgraph/langgraph/func/__init__.py +++ b/libs/langgraph/langgraph/func/__init__.py @@ -264,14 +264,14 @@ class entrypoint: from langgraph.func import entrypoint, task from langgraph.types import interrupt, Command - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver @task def compose_essay(topic: str) -> str: time.sleep(1.0) # Simulate slow operation return f"An essay about {topic}" - @entrypoint(checkpointer=MemorySaver()) + @entrypoint(checkpointer=InMemorySaver()) def review_workflow(topic: str) -> dict: \"\"\"Manages the workflow for generating and reviewing an essay. @@ -326,10 +326,10 @@ class entrypoint: of the previous invocation on the same thread id. ```python - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver from langgraph.func import entrypoint - @entrypoint(checkpointer=MemorySaver()) + @entrypoint(checkpointer=InMemorySaver()) def my_workflow(input_data: str, previous: Optional[str] = None) -> str: return "world" @@ -348,10 +348,10 @@ class entrypoint: long as the same thread id is used. ```python - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver from langgraph.func import entrypoint - @entrypoint(checkpointer=MemorySaver()) + @entrypoint(checkpointer=InMemorySaver()) def my_workflow(number: int, *, previous: Any = None) -> entrypoint.final[int, int]: previous = previous or 0 # This will return the previous value to the caller, saving @@ -406,10 +406,10 @@ class entrypoint: Example: Decoupling the return value and the save value ```python - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver from langgraph.func import entrypoint - @entrypoint(checkpointer=MemorySaver()) + @entrypoint(checkpointer=InMemorySaver()) def my_workflow(number: int, *, previous: Any = None) -> entrypoint.final[int, int]: previous = previous or 0 # This will return the previous value to the caller, saving diff --git a/libs/langgraph/langgraph/graph/state.py b/libs/langgraph/langgraph/graph/state.py index 697637686..6e5b77b73 100644 --- a/libs/langgraph/langgraph/graph/state.py +++ b/libs/langgraph/langgraph/graph/state.py @@ -202,7 +202,7 @@ class StateGraph(Generic[StateT, InputT, OutputT]): ```python from langchain_core.runnables import RunnableConfig from typing_extensions import Annotated, TypedDict - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import StateGraph def reducer(a: list, b: int | None) -> list: diff --git a/libs/langgraph/langgraph/types.py b/libs/langgraph/langgraph/types.py index 8a653c0b9..d71271f29 100644 --- a/libs/langgraph/langgraph/types.py +++ b/libs/langgraph/langgraph/types.py @@ -425,7 +425,7 @@ def interrupt(value: Any) -> Any: from typing import Optional from typing_extensions import TypedDict - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver from langgraph.constants import START from langgraph.graph import StateGraph from langgraph.types import interrupt, Command @@ -454,7 +454,7 @@ def interrupt(value: Any) -> Any: builder.add_edge(START, \"node\") # A checkpointer must be enabled for interrupts to work! - checkpointer = MemorySaver() + checkpointer = InMemorySaver() graph = builder.compile(checkpointer=checkpointer) config = { diff --git a/libs/langgraph/tests/test_remote_graph.py b/libs/langgraph/tests/test_remote_graph.py index 5fa61db3f..16f3dc503 100644 --- a/libs/langgraph/tests/test_remote_graph.py +++ b/libs/langgraph/tests/test_remote_graph.py @@ -877,7 +877,7 @@ async def test_ainvoke(): async def test_langgraph_cloud_integration(): from langgraph_sdk.client import get_client, get_sync_client - from langgraph.checkpoint.memory import MemorySaver + from langgraph.checkpoint.memory import InMemorySaver from langgraph.graph import END, START, MessagesState, StateGraph # create RemotePregel instance @@ -894,7 +894,7 @@ async def test_langgraph_cloud_integration(): workflow.add_node("agent", remote_pregel) workflow.add_edge(START, "agent") workflow.add_edge("agent", END) - app = workflow.compile(checkpointer=MemorySaver()) + app = workflow.compile(checkpointer=InMemorySaver()) # test invocation input = {