CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-langchain-cli

CLI for interacting with LangChain templates and applications

Pending
Overview
Eval results
Files

template-development.mddocs/

Template Development

Create and develop installable LangChain template packages with scaffolding, development server, and template discovery capabilities. This namespace provides tools for building reusable LangChain components.

Capabilities

Create New Template

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 configuration
  • Python module with chain implementation
  • README.md with usage instructions and route code
  • Standard package structure for LangChain templates

Serve Template

Start 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 localhost

Server Modes:

  • Default: Basic template serving with standard LangServe endpoints
  • Configurable: Includes configuration endpoints for dynamic template parameters
  • Chat Playground: Adds interactive chat interface for testing conversational templates

List Templates

Discover available templates from the LangChain template repository.

langchain template list [contains]

Arguments:
  contains              Optional search term to filter templates

Usage Examples:

# List all available templates
langchain template list

# Search for specific templates
langchain template list rag

# Search for OpenAI templates
langchain template list openai

Programmatic API

Template Namespace Functions

def 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."""

Template Structure

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)

LangServe Export Configuration

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:

  • Automatic discovery by the CLI
  • Proper import resolution when adding to applications
  • Route generation for LangServe applications

Template Development Best Practices

Chain Implementation

Templates should export a well-defined chain:

from langchain_core.runnables import Runnable

# Your chain implementation
chain: Runnable = ...

Module Structure

Use consistent module organization:

# __init__.py
from template_name.chain import chain

__all__ = ["chain"]

Documentation

Include comprehensive README with:

  • Purpose and use cases
  • Installation instructions
  • Usage examples
  • Route integration code
  • Configuration options

Testing

Templates can include tests for validation:

def test_chain():
    """Test the template chain."""
    # Test implementation
    pass

Development Workflow

Local Development

  1. Create template: langchain template new my-template
  2. Implement chain logic in the generated module
  3. Test locally: langchain template serve --chat-playground
  4. Validate with demo server and playground interface

Template Publishing

Templates can be published to:

  • Git repositories for distribution
  • LangChain template registry
  • Private template repositories

Integration Testing

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 serve

Error Handling

Common development issues and solutions:

  • Invalid pyproject.toml: Missing LangServe export configuration
  • Import Errors: Incorrect module structure or missing dependencies
  • Chain Validation: Runtime errors in chain implementation
  • Server Issues: Port conflicts or host binding problems
  • Template Discovery: Network issues accessing template registry

Install with Tessl CLI

npx tessl i tessl/pypi-langchain-cli

docs

app-management.md

code-migration.md

index.md

integration-development.md

template-development.md

utilities.md

tile.json