Skip to main content

Utilities for Langchain and langgraph

Project description

LangChain Tools JSON Converter

This module provides utility functions to convert LangChain tool objects into JSON format and vice versa. It helps serialize and deserialize structured tool definitions for easier storage and transport.

Features

  • create_tools_json: Converts a list of LangChain tool objects into a JSON string.
  • json_to_structured_tools: Converts a JSON representation of LangChain tools back into StructuredTool objects.

Installation

Ensure you have langchain_core installed before using this module:

pip install langchain-core

Usage

Converting Tools to JSON

from langchain_core.tools import StructuredTool

# Example tool
example_tool = StructuredTool(
    name="example_tool",
    description="An example tool",
    func=None,
    args_schema={}
)

# Convert to JSON
json_output = create_tools_json([example_tool])
print(json_output)

Converting JSON to Structured Tools

json_tools = [
    {
        "name": "example_tool",
        "description": "An example tool",
        "args_schema": {}
    }
]

structured_tools = json_to_structured_tools(json_tools)
print(structured_tools)

Function Details

create_tools_json(tools)

Description: Converts a list of LangChain tool objects into a JSON string.

Parameters:

  • tools (List of StructuredTool objects): List of tool objects to be serialized.

Returns:

  • str: JSON string representation of the tools.

json_to_structured_tools(json_tools)

Description: Converts JSON-formatted LangChain tools into StructuredTool objects.

Parameters:

  • json_tools (list or dict): A list or single JSON object representing tools.

Returns:

  • StructuredTool or List of StructuredTool objects.

Notes

  • The func attribute is set to None when reconstructing StructuredTool objects from JSON.
  • Ensure that the args_schema matches the expected schema format for LangChain.

License

This module is open-source and can be modified as needed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langgraph_utils-0.0.7.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langgraph_utils-0.0.7-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file langgraph_utils-0.0.7.tar.gz.

File metadata

  • Download URL: langgraph_utils-0.0.7.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for langgraph_utils-0.0.7.tar.gz
Algorithm Hash digest
SHA256 aabd2ae308b504cac1cf3fd7cc29a8301e06f76da6fc6f54d80cc17efed69ec6
MD5 a1b875968e4cd330c5d0231137ec893a
BLAKE2b-256 9ecd45ca1413a14b1fab6a3f14e5cdf95969179e5bef86fcca0b1439c5a4dd92

See more details on using hashes here.

File details

Details for the file langgraph_utils-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for langgraph_utils-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 20678ce5853e9fe5e4f8117958050e12c8a1dffc84ddc30a1ad4cd7385797b6f
MD5 d4221ac9e77e1e3dd70d08fb76a12e72
BLAKE2b-256 bb3e4d8a010806a0ad44cdf3dde3d19b26c951c72420d4fa4f78e8d7a0e5804b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page