langgraph_agent_toolkit.helper.utils.convert_message_content_to_string(content)[source][source]
Parameters:

content (str | list[str | dict])

Return type:

str

langgraph_agent_toolkit.helper.utils.langchain_to_chat_message(message)[source][source]

Create a ChatMessage from a LangChain message.

Parameters:

message (BaseMessage | dict | BaseModel | list)

Return type:

ChatMessage

langgraph_agent_toolkit.helper.utils.remove_tool_calls(content)[source][source]

Remove tool calls from content.

Parameters:

content (str | list[str | dict])

Return type:

str | list[str | dict]

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_calls have no corresponding ToolMessage (the call was never

answered) — the dangling tool calls are stripped.

  • ToolMessages whose tool_call_id has 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

Parameters:

messages (list[BaseMessage]) – List of messages to sanitize

Returns:

Sanitized list of messages where every remaining AIMessage tool call has a ToolMessage and every remaining ToolMessage has a requesting AIMessage tool call

Return type:

list[BaseMessage]

langgraph_agent_toolkit.helper.utils.create_ai_message(parts)[source][source]
Parameters:

parts (dict)

Return type:

AIMessage

langgraph_agent_toolkit.helper.utils.read_file(file_path, mode='r', encoding='utf-8', **kwargs)[source][source]

Read the content of a file and return it as a string.

Parameters:
  • file_path (Path | str) – The path to the file to read.

  • mode (str) – The mode in which to open the file. Default is “r”.

  • encoding (str) – The encoding to use for reading the file. Default is “utf-8”.

  • **kwargs – Additional arguments to pass to the open function.

Returns:

The content of the file as a string.

Return type:

Any