You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
I am sure that this is a bug in LangChain rather than my code.
The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
fromlangchain_core.messagesimportRemoveMessagefromlangchain_core.toolsimporttoolfromlangchain_openaiimportChatOpenAIfrompydanticimportBaseModel, Fieldfromlanggraph.prebuiltimporttools_conditionmodel=ChatOpenAI(model="ep-20241223171230-8tv46",
api_key='32589e42-775a-4c85-ab34-ecf34deda5f1',
base_url='https://ark.cn-beijing.volces.com/api/v3',
streaming=True, temperature=0,
)
retrieve_model=ChatOpenAI(model="ep-20241223171230-8tv46",
api_key='32589e42-775a-4c85-ab34-ecf34deda5f1',
base_url='https://ark.cn-beijing.volces.com/api/v3',
streaming=True, temperature=0.1,
)
file_path1='../data/080901.pdf'file_path2='../data/非学历证书可免考课程列表.pdf'@tool(response_format="content_and_artifact")defcomputer_science_major_plan(query: str):
"""查询知识库,该知识库包含计算机科学与技术(专升本)专业考试计划,包含开设课程、课程学分级及毕业条件。"""return'', ''@tool(response_format="content_and_artifact")defcourse_exemption_info(query: str):
"""查询知识库,该知识库包含福建省高等教育自学考试课程免考实施细则。"""return'', ''defcitation_rag_agent(state):
"""查询知识库,该知识库包含福建省高等教育自学考试课程免考实施细则。"""system_msg= (
"You are an expert Q&A system!""Please provide an answer based solely on the provided sources. ""When referencing information from a source, ""cite the appropriate source(s) using their corresponding numbers. ""Every answer should include at least one source citation. ""You should use format '[source number]' to cite the source!""Only cite a source when you are explicitly referencing it. ""If none of the sources are helpful, you should indicate that. ""For example:\n""Source 1:\n""The sky is red in the evening and blue in the morning.\n""Source 2:\n""Water is wet when the sky is red.\n""User query: When is water wet?\n""Your answer: Water will be wet when the sky is red [2], ""which occurs in the evening [1].\n""Now it's your turn. Below are several numbered sources of information:""\n------\n""{context}""\n------\n"
)
prompt_template=ChatPromptTemplate.from_messages(
[
(
"system",
system_msg,
),
MessagesPlaceholder(variable_name="messages"),
]
)
messages=state["messages"]
conversation_messages= [
messageformessageinstate["messages"]
ifmessage.typein ("human", "system")
or (message.type=="ai"andnotmessage.tool_calls)
]
# question = messages[-2].tool_calls[0]['args']['query']docs=messages[-1].content# Chainrag_chain=prompt_template|retrieve_model# Runresponse=rag_chain.invoke({"context": docs, "messages":conversation_messages})
return {"messages": [response]}
tools= [computer_science_major_plan,course_exemption_info]
fromtypingimportAnnotated, Sequencefromtyping_extensionsimportTypedDictfromlangchain_core.messagesimportBaseMessagefromlanggraph.graph.messageimportadd_messagesclassAgentState(TypedDict):
# The add_messages function defines how an update should be processed# Default is to replace. add_messages says "append"messages: Annotated[Sequence[BaseMessage], add_messages]
question: str### Nodesfromlangchain_core.promptsimportChatPromptTemplate, MessagesPlaceholderSYSTEM_PROMPT=(
"you are helpful assistant! your name is '小安'.\n""You should answer user questions base on tool response, rather than relying on your previous knowledge.\n""When the user's statement is unclear or you feel confused, you can ask the user for confirmation.\n""# User Information\n""1. User's personal information can help you to have a personalized response.\n""Below is user information:\n""```\n""{user_info}\n""```\n"
)
USER_INFO= {
"name": 'Arvin',
"age": '18',
"user hobby": ['basketball', 'listening music'],
}
prompt_template=ChatPromptTemplate.from_messages(
[
(
"system",
SYSTEM_PROMPT,
),
MessagesPlaceholder(variable_name="messages"),
]
)
prompt_template_with_user=prompt_template.partial(user_info=str(USER_INFO))
defagent(state):
""" Invokes the agent model to generate a response based on the current state. Given the question, it will decide to retrieve using the retriever tool, or simply end. Args: state (messages): The current state Returns: dict: The updated state with the agent response appended to messages """print("---CALL AGENT---")
model_with_tool=model.bind_tools(tools)
prompt=prompt_template_with_user.invoke(state)
response=model_with_tool.invoke(prompt)
# We return a list, because this will get added to the existing listreturn {"messages": [response]}
fromlanggraph.graphimportEND, StateGraph, STARTfromlanggraph.prebuiltimportToolNode# Define a new graphworkflow=StateGraph(AgentState)
# Define the nodes we will cycle betweenworkflow.add_node("agent", agent) # agentworkflow.add_node("citation", citation_rag_agent)
tool_node=ToolNode(tools)
workflow.add_node('tools', tool_node)
workflow.add_edge(START, "agent")
# Decide whether to retrieveworkflow.add_conditional_edges(
"agent",
# Assess agent decisiontools_condition,
{
# Translate the condition outputs to nodes in our graph"tools": "tools",
END: END,
},
)
workflow.add_edge('tools', "citation")
workflow.add_edge("citation", END)
# Compilefromlanggraph.checkpoint.memoryimportMemorySavermemory=MemorySaver()
graph=workflow.compile(checkpointer=memory)
CONFIG= {"configurable": {"thread_id": "abc123"}}
inputs= {
"messages": [
("user", 'hi'),
]
}
response=graph.invoke(inputs, config=CONFIG)
print(response["messages"][-1].content)
messages=graph.get_state(CONFIG).values["messages"]
graph.update_state(CONFIG,{"messages": [RemoveMessage(id=m.id) forminmessages]})
Error Message and Stack Trace (if applicable)
Traceback (most recent call last):
File "/home/chenjq/miniconda3/envs/RAG/lib/python3.10/contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "/home/chenjq/miniconda3/envs/RAG/lib/python3.10/site-packages/langgraph/pregel/manager.py", line 37, in ChannelsManager
yield (
File "/home/chenjq/miniconda3/envs/RAG/lib/python3.10/site-packages/langgraph/pregel/__init__.py", line 1079, in update_state
run.invoke(
File "/home/chenjq/miniconda3/envs/RAG/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 3024, in invoke
input = context.run(step.invoke, input, config)
File "/home/chenjq/miniconda3/envs/RAG/lib/python3.10/site-packages/langgraph/utils/runnable.py", line 184, in invoke
ret = context.run(self.func, input, **kwargs)
File "/home/chenjq/miniconda3/envs/RAG/lib/python3.10/site-packages/langgraph/graph/graph.py", line 95, in _route
result = self.path.invoke(value, config)
File "/home/chenjq/miniconda3/envs/RAG/lib/python3.10/site-packages/langgraph/utils/runnable.py", line 176, in invoke
ret = context.run(self.func, input, **kwargs)
File "/home/chenjq/miniconda3/envs/RAG/lib/python3.10/site-packages/langgraph/prebuilt/tool_node.py", line 636, in tools_condition
raise ValueError(f"No messages found in input state to tool_edge: {state}")
ValueError: No messages found in input state to tool_edge: {'messages': []}
Description
I try to delete messages and this error occur.
System Info
System Information
OS: Linux
OS Version: #1 SMP Mon Oct 19 16:18:59 UTC 2020
Python Version: 3.10.12 (main, Jul 5 2023, 18:54:27) [GCC 11.2.0]
Package Information
langchain_core: 0.3.29
langchain: 0.3.14
langchain_community: 0.3.13
langsmith: 0.2.4
langchain_app: Installed. No version info available.
langchain_chroma: 0.1.4
langchain_huggingface: 0.1.2
langchain_openai: 0.2.14
langchain_text_splitters: 0.3.4
langgraph_sdk: 0.1.48
@minmie I don't understand why you are trying to do this since you are using MemorySaver the messages are kept in memory as long as the main process is running,.,
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
Description
I try to delete messages and this error occur.
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: