langgraph/how-tos/persistence_postgres/ #894
Replies: 22 comments 39 replies
-
How do I pass config and recursion limit together while streaming the graph? Currently, I'm getting this error - TypeError: Pregel.stream() takes from 2 to 3 positional arguments but 4 were given |
Beta Was this translation helpful? Give feedback.
-
Can you also update this guide but for JS version, and maybe a seperate general guide to explain in detail how to create a custom checkpointer and each component a checkpointer should have? I feel like this is a really important feature to bring LangGraph to production and there should be more guidance for it. |
Beta Was this translation helpful? Give feedback.
-
Please add a specific section on accessing and modifying the state variables of nodes from outside the node functions. |
Beta Was this translation helpful? Give feedback.
-
William
Thanks for the reply, this is not exactly what I am looking for. Consider a simple scenario that an attribute in the state object has to be modified.
I have a state object and want to modify a string parameter and set it to a value , for e.g. plan attribute . A simple document to modify state attributes with examples will be useful.
class AgentState(TypedDict):
task: str
plan: str
draft: str
critique: str
content: List[str]
revision_number: int
max_revisions: int
workflow = StateGraph(AgentState)
rampi
…________________________________
From: William FH ***@***.***>
Sent: 09 July 2024 03:47
To: langchain-ai/langgraph ***@***.***>
Cc: Ramprasad ***@***.***>; Comment ***@***.***>
Subject: Re: [langchain-ai/langgraph] langgraph/how-tos/persistence_postgres/ (Discussion #894)
You mean like this? https://langchain-ai.github.io/langgraph/how-tos/human_in_the_loop/edit-graph-state/<https://eu-central-1.protection.sophos.com/?d=langchain-ai.github.io&u=aHR0cHM6Ly9sYW5nY2hhaW4tYWkuZ2l0aHViLmlvL2xhbmdncmFwaC9ob3ctdG9zL2h1bWFuX2luX3RoZV9sb29wL2VkaXQtZ3JhcGgtc3RhdGUv&i=NWY1NzY4MDNhOGI2OTAwZWFlOGRmNDI2&t=QkNXVHhueXB5K0FEKzQ2eFNNSEpXelZJTCtEbCs5VGdscllybnBqZThGdz0=&h=afb31f07d9264eedb4c62fc9d0a21266&s=AVNPUEhUT0NFTkNSWVBUSVY6K0T94M0wPyDMzKN9BocAHrXlbSFJ3THbbw-AzQ3TEw>
—
Reply to this email directly, view it on GitHub<https://eu-central-1.protection.sophos.com/?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL2xhbmdjaGFpbi1haS9sYW5nZ3JhcGgvZGlzY3Vzc2lvbnMvODk0I2Rpc2N1c3Npb25jb21tZW50LTk5OTIwOTM=&i=NWY1NzY4MDNhOGI2OTAwZWFlOGRmNDI2&t=V0pKTnpNS3A2clF5NG54MUJYeStraGNLOHoxcVZBRklqU3dQV0xMbGF5RT0=&h=afb31f07d9264eedb4c62fc9d0a21266&s=AVNPUEhUT0NFTkNSWVBUSVY6K0T94M0wPyDMzKN9BocAHrXlbSFJ3THbbw-AzQ3TEw>, or unsubscribe<https://eu-central-1.protection.sophos.com/?d=github.com&u=aHR0cHM6Ly9naXRodWIuY29tL25vdGlmaWNhdGlvbnMvdW5zdWJzY3JpYmUtYXV0aC9CRjVDSlQyVkNRUFJLTFFMWTZDVkdLVFpMTUZZSEFWQ05GU002QUFBQUFCS0U0N1RENlZISTJEU01WUVdJWDNMTVY0M1NSREpPTlJYSzQzVE5GWFc0UTNQTlZXV0szVFVITTRUU09KU0dBNFRH&i=NWY1NzY4MDNhOGI2OTAwZWFlOGRmNDI2&t=SDdWRUxYR1o5RmROWXNnNWhrdktVWGVvZW9rOXY0eDBlbWdsWXdjcVZUST0=&h=afb31f07d9264eedb4c62fc9d0a21266&s=AVNPUEhUT0NFTkNSWVBUSVY6K0T94M0wPyDMzKN9BocAHrXlbSFJ3THbbw-AzQ3TEw>.
You are receiving this because you commented.Message ID: ***@***.***>
This E-MAIL message is a property of Premjiinvest and is intended for use only by the individual or entity to which it is addressed. The information contained may be confidential and privileged. If this is a forwarded message, the content of this E-MAIL may not have been sent with the authority of the company. If you have received this message by mistake, kindly notify the sender by return E-MAIL and delete this message. Premjiinvest will not be responsible for any viruses or defects or any forwarded attachments emanating either from within or outside. Premjiinvest reserves the right to monitor and review the content of all messages sent to or from Premjiinvest E-MAIL addresses. Messages sent to or from this e-mail address may be stored on the Premjiinvest E-MAIL system or elsewhere.
|
Beta Was this translation helpful? Give feedback.
-
Hello, How can I limit the memory, avoiding the graph to continuously have more history on its prompt? E.g., by limiting to the last 10 messages |
Beta Was this translation helpful? Give feedback.
-
I am currently implementing a customer support bot and have been exploring the use of persistent memory to manage user interactions. My initial approach was to load the memory for a specific user from persistent storage, ensuring that all interactions from different users remain isolated. This seemed straightforward for maintaining user-specific contexts across sessions. However, I am a bit confused about the specific utility of threads in this context. I understand that threads can provide additional granularity by keeping separate interactions within the same user session, but I am struggling to come up with concrete use cases where this granularity would be beneficial. One example I am considering is within a single chat interaction. Even with persistent memory loaded through a checkpointer, it seems possible to add more granularity by using threads to manage multiple sub-interactions within a single user session. For instance, in a customer support bot scenario, a user might request multiple tasks, and these could be managed as separate threads within the same interaction. My question is about the practical management of this granularity. How does the agent determine which thread to use at any given time within an ongoing interaction? Are there specific strategies or examples where combining both checkpointers and threads has proven particularly effective? I would greatly appreciate insights from those with more experience in this area. |
Beta Was this translation helpful? Give feedback.
-
Any plans to add to the documentation an explanation of the "state' structure once its persisted? e.g: To understand what each of those values here represent :) |
Beta Was this translation helpful? Give feedback.
-
Why we need the |
Beta Was this translation helpful? Give feedback.
-
It should have docs about the way checkpointer work. |
Beta Was this translation helpful? Give feedback.
-
I get this error from get_tuple: CheckpointTuple.new() got an unexpected keyword argument 'pending_writes' and sure enough it doesn't: class CheckpointTuple(NamedTuple): Anybody any ideas? |
Beta Was this translation helpful? Give feedback.
-
Hi folks! We just released a new Postgres checkpointer library -- you can install it with Please let me know if you run into any issues with the library! |
Beta Was this translation helpful? Give feedback.
-
from psycopg_pool import AsyncConnectionPool
async with AsyncConnectionPool(
# Example configuration
conninfo=DB_URI,
max_size=20,
kwargs=connection_kwargs
) as pool, pool.connection() as conn:
checkpointer = AsyncPostgresSaver(conn)
# NOTE: you need to call .setup() the first time you're using your checkpointer
# await checkpointer.setup()
graph = create_react_agent(model, tools=tools, checkpointer=checkpointer)
config = {"configurable": {"thread_id": "4"}}
res = await graph.ainvoke(
{"messages": [("human", "what's the weather in nyc")]}, config
)
checkpoint = await checkpointer.aget(config) Regarding this piece of pool code, the pool has 20 connections available, but the code only takes one connection from the pool and assigns it to Does this mean that an AsyncPostgresSaver will always have only one connection? Additionally, I have a similar question to @GaryFail: how exactly should I compile the graph and the checkpointer in the API? |
Beta Was this translation helpful? Give feedback.
-
Any idea on which implementation works the best for the production environment ..?
|
Beta Was this translation helpful? Give feedback.
-
Hey when I run my agent outside of LangGraph studio it's accessing the DB fine. I've even used ngrok to expose to TCP port. But from the langgraph studio docker container it won't connect. Any ideas? |
Beta Was this translation helpful? Give feedback.
-
i am getting error on imports error:
|
Beta Was this translation helpful? Give feedback.
-
i am getting error like: DuplicatePreparedStatement prepared statement "_pg3_0" already exists my graph: start ]):::firstsupervisor(supervisor) human_feedback(human_feedback __interrupt = before) SeedKeywords(SeedKeywords) OptimizedKeywords(OptimizedKeywords) RelatedKeywords(RelatedKeywords) end([ end ]):::lastOptimizedKeywords --> human_feedback; RelatedKeywords --> human_feedback; SeedKeywords --> human_feedback; start --> supervisor; human_feedback --> supervisor; supervisor -.-> SeedKeywords; supervisor -.-> OptimizedKeywords; supervisor -.-> RelatedKeywords; supervisor -. FINISH .-> end; classDef default fill:#f2f0ff,line-height:1.2 classDef first fill-opacity:0 classDef last fill:#bfb6fc and every agent that connected to supervisor in subgraph. |
Beta Was this translation helpful? Give feedback.
-
Having through with I'm using this example pretty much verbatim. When I trace through with the debugger it seems to be with the Any idea's?
Part of the trace
|
Beta Was this translation helpful? Give feedback.
-
I ran into this issue so I thought I share the solution. For the async-connection string scneario, make sure run async with AsyncPostgresSaver.from_conn_string(DB_URI) as checkpointer:
await checkpointer.setup()
graph = create_react_agent(model, tools=tools, checkpointer=checkpointer)
config = {"configurable": {"thread_id": "6"}}
res = await graph.ainvoke(
{"messages": [("human", "what's the weather in nyc")]}, config
)
checkpoint_tuples = [c async for c in checkpointer.alist(config)] |
Beta Was this translation helpful? Give feedback.
-
Do I need to run any migration to use this? Can I use this with an existing PG db? I have one already to use for document retrieval. Many points are not covered by this docs. Do I need anything extra or some steps to run before using this PostgresSaver thing? Any toughts? |
Beta Was this translation helpful? Give feedback.
-
I am getting this error does anyone faced the same problem? psycopg.Not SupportedError: the feature 'Connection.pipeline()" is not available: the client libpq version (imported from system libraries) is 13.11; the feature requires libpq version 14.0 or newer |
Beta Was this translation helpful? Give feedback.
-
I am using postgres checkpointer to save STATE and creating THREADS for follow-up questions. I want to understand if there is a way to filter certain state variables before checkpointers saves them? I want to avoid saving RAG searches in my DB? |
Beta Was this translation helpful? Give feedback.
-
Whats the actual implementation for thread checkpoint rollback ? i mean, if a specific thread gets an exception during execution which leads to a "broken" state i.e. ai_messages with tool calls without tool_messages. Whats the best way to have the last valid checkpoint being the last again ? |
Beta Was this translation helpful? Give feedback.
-
langgraph/how-tos/persistence_postgres/
Build language agents as graphs
https://langchain-ai.github.io/langgraph/how-tos/persistence_postgres/
Beta Was this translation helpful? Give feedback.
All reactions