- langgraph_agent_toolkit.helper.utils.langchain_to_chat_message(message)[source][source]
Create a ChatMessage from a LangChain message.
- Parameters:
- Return type:
- langgraph_agent_toolkit.helper.utils.remove_tool_calls(content)[source][source]
Remove tool calls from content.
- langgraph_agent_toolkit.helper.utils.sanitize_chat_history(messages)[source][source]
Sanitize chat history so tool calls and tool results are consistently paired.
Fixes both directions of broken pairing, which providers reject: - AIMessages whose
tool_callshave no corresponding ToolMessage (the call was neveranswered) — the dangling tool calls are stripped.
ToolMessages whose
tool_call_idhas no requesting AIMessage tool call (the result is orphaned) — the ToolMessage is dropped.
This is useful when: - A previous execution was interrupted before tool responses were added - Trimming or summarization removed an AIMessage but kept its ToolMessage (or vice versa) - Chat history was corrupted or a connection was lost during tool execution
- langgraph_agent_toolkit.helper.utils.create_ai_message(parts)[source][source]
- Parameters:
parts (dict)
- Return type:
AIMessage