LangGraph Utilities

0.0.7.4 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart demonstrates how to use `create_tools_json` to serialize a list of mock LangChain `StructuredTool` objects into a JSON string. While the `langgraph-utils` PyPI description mentions conversion 'and vice versa', the `create_tools_json` function is explicitly detailed. For deserialization, you would typically use standard JSON parsing and potentially recreate `StructuredTool` instances based on the JSON structure.

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']}")

view raw JSON →