The find_meeting_time node is treated as a tool node and appends a tool call to the state, which is why you suggest to:
messages = messages[:-1]
(remove the last message) so we can call:
result = await agent.ainvoke(
input={"messages": [{"role": "user", "content": input_message}] + messages},
config=config,
)
to then later return the ToolMessage answer:
return {
"messages": [
ToolMessage(
content=result["messages"][-1].content, tool_call_id=tool_call["id"]
)
]
}
This works fine for Langgraph DEV, but when the graph is called with e.g. astream and a Redis Checkpointer, the _validate_chat_history will validate the state.messages and throw:
Found AIMessages with tool_calls that do not have a corresponding ToolMessage. Here are the first few of those tool calls: [{'name': 'MeetingAssistant', 'args': {'call': True}, 'id': 'call_lBHYB24fddwYsy1mvPTEdGKJ', 'type': 'tool_call'}].