LangGraph Utilities
This library (version 0.0.7.4) provides utility functions specifically designed to convert LangChain tool objects into JSON format and vice versa. Its primary purpose is to help serialize and deserialize structured tool definitions, facilitating easier storage and transport within applications built with LangChain and LangGraph. The release cadence appears to be infrequent, with the latest version uploaded in May 2025.
Warnings
- gotcha The official PyPI description for `langgraph-utils` (version 0.0.7.4) specifies its role as a 'LangChain Tools JSON Converter', focusing on `create_tools_json`. This is more specific than the broader 'Utilities for Langchain and langgraph' summary provided in some contexts. Ensure this specific JSON conversion functionality aligns with your needs.
- breaking LangChain and LangGraph APIs, including tool definitions (`StructuredTool`), undergo updates. Breaking changes, especially in major LangChain/LangGraph versions (e.g., LangGraph v1.0), could affect how tools are defined or interpreted, potentially impacting the serialization/deserialization process.
- gotcha If `langgraph-utils` is used within a larger LangGraph application, pay close attention to state management. Incorrectly serialized or deserialized tool definitions, or state changes during parallel execution, can lead to unexpected tool calls or graph behavior.
Install
-
pip install langgraph-utils==0.0.7.4 -
pip install langgraph-utils
Imports
- create_tools_json
from langgraph_utils import create_tools_json
Quickstart
import os
from typing import List, Dict, Any
from langchain_core.tools import StructuredTool
from langgraph_utils import create_tools_json
# Mock a LangChain StructuredTool
# In a real application, you would import and define actual tools.
class MockTool(StructuredTool):
name: str = "mock_tool"
description: str = "A mock tool for demonstration."
args_schema: Dict[str, Any] = {"param": {"type": "string", "description": "A parameter"}}
def _run(self, param: str) -> str:
return f"MockTool executed with: {param}"
async def _arun(self, param: str) -> str:
return f"MockTool async executed with: {param}"
mock_tools = [
MockTool(name='search_internet', description='Searches the internet for information'),
MockTool(name='get_weather', description='Fetches current weather for a location')
]
tools_json_string = create_tools_json(mock_tools)
print(f"Serialized Tools: {tools_json_string}")
# Example of deserialization (assuming a hypothetical deserialize_tools_json function exists or custom logic)
# This library's PyPI description focuses on 'create_tools_json', but also mentions 'and vice versa'.
# For full deserialization, you might need to implement custom logic or use other LangChain utilities.
# For illustrative purposes, we'll just show the structure.
import json
deserialized_data = json.loads(tools_json_string)
print(f"Deserialized data structure: {deserialized_data[0]['name']}")