Memory object passed to prompttemplate as dict in langgraph #30176
Replies: 1 comment 10 replies
-
Hello @pydisandeep! I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this together! To pass conversation history as a dictionary or list to the LLM through
Here's a code snippet to illustrate this setup: from langchain_core.messages import HumanMessage
from langgraph.checkpoint.memory import MemorySaver
from langgraph.graph import START, MessagesState, StateGraph
# Define a new graph
workflow = StateGraph(state_schema=MessagesState)
# Define the function that calls the model
def call_model(state: MessagesState):
response = llm.invoke(state["messages"])
# Update message history with response:
return {"messages": response}
# Define the (single) node in the graph
workflow.add_edge(START, "model")
workflow.add_node("model", call_model)
# Add memory
memory = MemorySaver()
app = workflow.compile(checkpointer=memory)
# Example invocation
query = "Hi! I'm Bob."
input_messages = [HumanMessage(query)]
config = {"configurable": {"thread_id": "abc123"}}
output = app.invoke({"messages": input_messages}, config)
output["messages"][-1].pretty_print() This setup allows you to manage the conversation history effectively and pass it to the LLM for rewriting follow-up questions [1][2]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello , I'm building a Bot using Langgraph. My requirement is if the question is follow up question i had to reformat / rewrite the question for which i have to pass conversation history as dictionary / list to the LLM through promptTemplate so that it rewrites question. im using memory checkpointer but still ,i want to store conversation history only.
Beta Was this translation helpful? Give feedback.
All reactions