Skip to main content

LangGraph utilities for Streamlit - StreamlitLanggraphHandler and more

Project description

youngjin-langchain-tools

youngjin-langchain-tools is a collection of LangGraph utilities designed to simplify AI application development with Streamlit and other frameworks.

Features

  • StreamlitLanggraphHandler: A drop-in replacement for the deprecated StreamlitCallbackHandler, designed for LangGraph agents
  • Real-time Streaming: Stream agent responses with live token updates
  • Tool Visualization: Display tool calls and results with expandable UI components
  • Configurable: Customize display options, labels, and behavior

Installation

pip install youngjin-langchain-tools

Or using uv:

uv add youngjin-langchain-tools

With Streamlit support:

pip install youngjin-langchain-tools[streamlit]

Quick Start

Basic Usage with LangGraph Agent

import streamlit as st
from langgraph.checkpoint.memory import InMemorySaver
from langchain.agents import create_agent
from youngjin_langchain_tools import StreamlitLanggraphHandler

# Create your LangGraph agent
agent = create_agent(
    model=llm,
    tools=tools,
    checkpointer=InMemorySaver(),
)

# In your Streamlit app
with st.chat_message("assistant"):
    handler = StreamlitLanggraphHandler(
        container=st.container(),
        expand_new_thoughts=True
    )

    response = handler.invoke(
        agent=agent,
        input={"messages": [{"role": "user", "content": prompt}]},
        config={"configurable": {"thread_id": thread_id}}
    )

    # response contains the final text

Before & After Comparison

Before (LangChain < 1.0 with AgentExecutor):

from langchain.callbacks import StreamlitCallbackHandler

with st.chat_message("assistant"):
    st_cb = StreamlitCallbackHandler(st.container(), expand_new_thoughts=True)
    response = agent_executor.invoke(
        {"input": prompt},
        config=RunnableConfig({"callbacks": [st_cb]})
    )
    st.write(response["output"])

After (LangGraph with StreamlitLanggraphHandler):

from youngjin_langchain_tools import StreamlitLanggraphHandler

with st.chat_message("assistant"):
    handler = StreamlitLanggraphHandler(st.container(), expand_new_thoughts=True)
    response = handler.invoke(
        agent=langgraph_agent,
        input={"messages": [{"role": "user", "content": prompt}]},
        config={"configurable": {"thread_id": thread_id}}
    )
    # response is the final text directly

Advanced Usage with Custom Configuration

from youngjin_langchain_tools import (
    StreamlitLanggraphHandler,
    StreamlitLanggraphHandlerConfig
)

# Create custom configuration
config = StreamlitLanggraphHandlerConfig(
    expand_new_thoughts=True,
    max_tool_content_length=3000,
    show_tool_calls=True,
    show_tool_results=True,
    thinking_label="🧠 Processing...",
    complete_label="✨ Done!",
    tool_call_emoji="⚡",
    tool_complete_emoji="✓",
    cursor="█",
)

handler = StreamlitLanggraphHandler(
    container=st.container(),
    config=config
)

# Use stream() for more control
for event in handler.stream(agent, input, config):
    if event["type"] == "tool_call":
        print(f"Tool called: {event['data']['name']}")
    elif event["type"] == "token":
        # Custom token handling
        pass

final_response = handler.get_response()

API Reference

StreamlitLanggraphHandler

Main handler class for streaming LangGraph agents in Streamlit.

Constructor Parameters

Parameter Type Default Description
container Any required Streamlit container to render in
expand_new_thoughts bool True Expand status container for tool calls
max_tool_content_length int 2000 Max chars of tool output to display
show_tool_calls bool True Show tool call information
show_tool_results bool True Show tool execution results
thinking_label str "🤔 Thinking..." Label while processing
complete_label str "✅ Complete!" Label when complete
config Config None Optional config object

Methods

Method Description
invoke(agent, input, config) Execute agent and return final response
stream(agent, input, config) Generator yielding streaming events
get_response() Get accumulated response text

StreamlitLanggraphHandlerConfig

Configuration dataclass for handler customization.

Architecture

youngjin_langchain_tools/
├── __init__.py              # Package exports
├── handlers/                # UI framework handlers
│   ├── __init__.py
│   └── streamlit_langgraph_handler.py
└── utils/                   # Utility functions
    ├── __init__.py
    └── config.py

Requirements

  • Python 3.12+
  • LangGraph 0.2+
  • Streamlit 1.30+ (optional, for StreamlitLanggraphHandler)

License

Apache License 2.0 - see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

youngjin_langchain_tools-0.2.3.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

youngjin_langchain_tools-0.2.3-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file youngjin_langchain_tools-0.2.3.tar.gz.

File metadata

  • Download URL: youngjin_langchain_tools-0.2.3.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for youngjin_langchain_tools-0.2.3.tar.gz
Algorithm Hash digest
SHA256 06d75a454cf683dfedbb527719f0c532ee8fe44fb698e43e5ebcb6061e93c44d
MD5 d81306161f4165e174c6f77b3c5fd59c
BLAKE2b-256 3d38fd1211a4fb94080c3617421c64a242165448192959707eace39c81a0cbf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for youngjin_langchain_tools-0.2.3.tar.gz:

Publisher: publish.yml on CocoRoF/youngjin-langchain-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file youngjin_langchain_tools-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for youngjin_langchain_tools-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 44852340749b4f1e45d6013cf25419e6da93152a81969c712c2bb75ed425966c
MD5 a6fd279df2a604c6fcdf3b8734a85807
BLAKE2b-256 3a48ece8e5776d704065a25ecbd2f72ada15387835327652b560c58f97b67a2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for youngjin_langchain_tools-0.2.3-py3-none-any.whl:

Publisher: publish.yml on CocoRoF/youngjin-langchain-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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