CLI for interacting with LangChain templates and applications
—
Create and develop installable LangChain template packages with scaffolding, development server, and template discovery capabilities. This namespace provides tools for building reusable LangChain components.
Creates a new template package with standardized structure and configuration.
langchain template new [name] [options]
Arguments:
name The name of the folder to create (required)
Options:
--with-poetry Run poetry install after creation
--no-poetry Don't run poetry install (default)Usage Examples:
# Create new template
langchain template new my-template
# Create template with poetry install
langchain template new my-template --with-poetry
# Create template in current directory
langchain template new .Generated Structure:
The new command creates a complete template package with:
pyproject.toml with LangServe export configurationREADME.md with usage instructions and route codeStart a development server for testing templates with configurable options and playground interfaces.
langchain template serve [options]
Options:
--port INTEGER The port to run the server on (default: 8000)
--host TEXT The host to run the server on (default: 127.0.0.1)
--configurable/--no-configurable Whether to include a configurable route
--chat-playground Whether to include a chat playground route
--no-chat-playground Don't include chat playground (default)Usage Examples:
# Serve template on default settings
langchain template serve
# Serve with chat playground
langchain template serve --chat-playground --port 8080
# Serve with configurable route
langchain template serve --configurable --host 0.0.0.0
# Serve on custom port and host
langchain template serve --port 9000 --host localhostServer Modes:
Discover available templates from the LangChain template repository.
langchain template list [contains]
Arguments:
contains Optional search term to filter templatesUsage Examples:
# List all available templates
langchain template list
# Search for specific templates
langchain template list rag
# Search for OpenAI templates
langchain template list openaidef new(
name: str,
with_poetry: bool = False,
) -> None:
"""Create a new template package."""
def serve(
*,
port: Optional[int] = None,
host: Optional[str] = None,
configurable: Optional[bool] = None,
chat_playground: bool = False,
) -> None:
"""Start a demo app for this template."""
def list(contains: Optional[str] = None) -> None:
"""List all or search for available templates."""Templates follow a standardized structure:
template-name/
├── pyproject.toml # Package configuration with LangServe export
├── README.md # Usage documentation and route code
├── template_name/ # Python package
│ ├── __init__.py # Module exports
│ └── chain.py # Chain implementation
└── tests/ # Test files (optional)Templates must include LangServe export configuration in pyproject.toml:
[tool.langserve]
export_module = "template_name.chain"
export_attr = "chain"
[tool.poetry]
name = "template-name"This configuration enables:
Templates should export a well-defined chain:
from langchain_core.runnables import Runnable
# Your chain implementation
chain: Runnable = ...Use consistent module organization:
# __init__.py
from template_name.chain import chain
__all__ = ["chain"]Include comprehensive README with:
Templates can include tests for validation:
def test_chain():
"""Test the template chain."""
# Test implementation
passlangchain template new my-templatelangchain template serve --chat-playgroundTemplates can be published to:
Test template integration with applications:
# Create test app
langchain app new test-app
# Add your template
langchain app add /path/to/template --pip
# Test in application context
langchain app serveCommon development issues and solutions:
Install with Tessl CLI
npx tessl i tessl/pypi-langchain-cli