Skip to main content

A practical utility library for LangChain and LangGraph development

Project description

langchain-dev-utils

PyPI License Python

langchain-dev-utils is a utility library focused on enhancing the development experience with LangChain and LangGraph. It provides a collection of ready-to-use utility functions that reduce repetitive code while improving code consistency and readability. By streamlining development workflows, this library helps you build prototypes faster, iterate more smoothly, and create clearer, more reliable AI applications powered by large language models.

📚 Documentation

🚀 Installation

pip install -U langchain-dev-utils

# For all features:
pip install -U langchain-dev-utils[standard]

📦 Core Features

1. Model Management

  • Register any chat model or embeddings provider
  • Unified interface with load_chat_model() / load_embeddings()
# Chat model management
from langchain_dev_utils.chat_models import (
    register_model_provider,
    load_chat_model,
)

# Register model provider
register_model_provider(
    provider_name="vllm",
    chat_model="openai-compatible",
    base_url="http://localhost:8000/v1",
)

# Load model
model = load_chat_model("vllm:qwen3-4b")
print(model.invoke("Hello"))

# Embeddings management
from langchain_dev_utils.embeddings import register_embeddings_provider, load_embeddings

register_embeddings_provider(
    provider_name="vllm",
    embeddings_model="openai-compatible",
    base_url="http://localhost:8000/v1",
)
embeddings = load_embeddings("vllm:qwen3-embedding-4b")
emb = embeddings.embed_query("Hello")
print(emb)

2. Message Processing

  • Merge reasoning content into final response
  • Stream-aware chunk merging
  • Content formatting utilities
from langchain_dev_utils.message_convert import (
    convert_reasoning_content_for_ai_message,
    convert_reasoning_content_for_chunk_iterator,
    merge_ai_message_chunk,
    format_sequence
)

response = model.invoke("Hello")
# Merge reasoning content to final response
cleaned = convert_reasoning_content_for_ai_message(
    response, think_tag=("<think>", "</think>")
)

# Stream merge reasoning content
for chunk in convert_reasoning_content_for_chunk_iterator(
    model.stream("Hello")
):
    print(chunk.content, end="", flush=True)

# Merge streaming chunks
chunks = list(model.stream("Hello"))
merged = merge_ai_message_chunk(chunks)

# Format sequence
text = format_sequence([
    "str1",
    "str2",
    "str3"
], separator="\n", with_num=True)

3. Tool Calling

  • Check and parse tool calls
  • Human-in-the-loop functionality for tool execution
import datetime
from langchain_core.tools import tool
from langchain_dev_utils.tool_calling import has_tool_calling, parse_tool_calling, human_in_the_loop
from langchain_core.messages import AIMessage
from typing import cast

@human_in_the_loop
def get_current_time() -> str:
    """Get current timestamp"""
    return str(datetime.datetime.now().timestamp())

response = model.bind_tools([get_current_time]).invoke("What time is it?")

if has_tool_calling(cast(AIMessage, response)):
    name, args = parse_tool_calling(
        cast(AIMessage, response), first_tool_call_only=True
    )
    print(name, args)

4. Agent Development

  • Pre-built agent factory functions
  • Context management utilities
  • Common middleware components
# Basic agent
from langchain_dev_utils.agents import create_agent
from langchain.agents import AgentState

agent = create_agent("vllm:qwen3-4b", tools=[get_current_time], name="time-agent")
response = agent.invoke({"messages": [{"role": "user", "content": "What time is it?"}]})
print(response)

# Plan tools
from langchain_dev_utils.agents.plan import (
    create_write_plan_tool,
    create_update_plan_tool,
    PlanStateMixin,
)

class PlanAgentState(AgentState, PlanStateMixin):
    pass

agent = create_agent(
    "vllm:qwen3-4b",
    tools=[
        create_write_plan_tool(),
        create_update_plan_tool(),
    ],
    name="plan-agent",
    state_schema=PlanAgentState,
)

# File system tools
from langchain_dev_utils.agents.file_system import (
    create_write_file_tool,
    create_update_file_tool,
    create_ls_file_tool,
    create_query_file_tool,
    FileStateMixin,
)

class FileAgentState(AgentState, FileStateMixin):
    pass

agent = create_agent(
    "vllm:qwen3-4b",
    tools=[
        create_write_file_tool(),
        create_update_file_tool(),
        create_ls_file_tool(),
        create_query_file_tool(),
    ],
    name="file-agent",
    state_schema=FileAgentState,
)

# Middleware
from langchain_dev_utils.agents.middleware import (
    SummarizationMiddleware,
    LLMToolSelectorMiddleware,
)

response = agent.invoke({"messages": [{"role": "user", "content": "What time is it?"}]})
print(response)

5. State Graph Orchestration

  • Sequential graph pipelines
  • Parallel graph pipelines
from langchain_dev_utils.pipelines import sequential_pipeline, parallel_pipeline

# Build sequential pipeline
graph = sequential_pipeline(
    sub_graphs=[
        make_graph("graph1"),
        make_graph("graph2"),
        make_graph("graph3"),
    ],
    state_schema=State,
)

# Build parallel pipeline
graph = parallel_pipeline(
    sub_graphs=[
        make_graph("graph1"),
        make_graph("graph2"),
        make_graph("graph3"),
    ],
    state_schema=State,
)

💬 Join the Community

  • 🐙 GitHub Repository — Browse source code, submit pull requests
  • 🐞 Issue Tracker — Report bugs or suggest improvements
  • 💡 We welcome all forms of contribution — whether it's code, documentation, or usage examples. Let's build a more powerful and practical LangChain development ecosystem together!

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

langchain_dev_utils-1.0.0.tar.gz (160.9 kB view details)

Uploaded Source

Built Distribution

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

langchain_dev_utils-1.0.0-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file langchain_dev_utils-1.0.0.tar.gz.

File metadata

  • Download URL: langchain_dev_utils-1.0.0.tar.gz
  • Upload date:
  • Size: 160.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for langchain_dev_utils-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9c6d7dcc479b393734d2b69aca26af19956e0355d5eed3c535d7989ff9803069
MD5 d677168753cd501e0e0c0071f246bfae
BLAKE2b-256 c6905c1fcbf20054bf171800fd5858846c5b1317920f5c4b0c3bc42a4ea0e060

See more details on using hashes here.

File details

Details for the file langchain_dev_utils-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_dev_utils-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c690da88a5c6578eb17ca14a397cd7fb65c887fdba93127a531150061dea9dd
MD5 a3bc1882b08379fb686ab07afb9dc4f8
BLAKE2b-256 11cb79c0698011981b8e2065d40ffb3e02ba0f0d88b57b3e523a4903b38b7eeb

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