LangChain CLI Cheatsheet
The LangChain CLI ecosystem provides two tools: `langchain` for application scaffolding and LangServe deployment, and `langgraph` for agent workflow development. Both support template-based quick-start, REST API deployment, and Docker packaging for production.
Quick Start
``bash
# Install CLI
pip install langchain-cli
# Create a new app langchain app new my-app
# Add a RAG template langchain app add rag-chroma
# Create environment file with API keys echo 'OPENAI_API_KEY=sk-xxx' > .env
# Start LangServe langchain serve --port 8000
# Visit the docs
open http://localhost:8000/docs
`
LangGraph
For agent workflows, install and use LangGraph separately:
`bash
pip install langgraph
# Start dev server langgraph dev
# Build for production langgraph build -t my-agent:v1
# Deploy with Docker Compose
langgraph up
`
Templates
Templates provide pre-built architectures: RAG, conversational retrieval, SQL agents, document analysis, and more. Browse and add them via the CLI.
LangServe
LangServe wraps LangChain chains as REST APIs automatically. Each template has its own endpoint at /chain-name, plus a Playground UI at /chain-name/playground` for interactive testing.
LangSmith
Observability and debugging platform. Enable tracing via environment variables to log all LLM calls, chains, and agent steps for inspection and evaluation.
Startup & Modes(16)
| Command | Level | ||
|---|---|---|---|
langchain --helpShow LangChain CLI help | Basic | langchain --help | |
langchain app newCreate a new LangChain application | Basic | langchain app new my-app | |
langchain app new --packageCreate app from a template package | Intermediate | langchain app new my-app --package rag-chroma | |
langchain app addAdd a package (template) to existing app | Intermediate | langchain app add rag-chroma | |
pip install langchain-cliInstall LangChain CLI | Basic | pip install langchain-cli | |
pip install langchainInstall LangChain core library | Basic | pip install langchain | |
pip install langchain-communityInstall LangChain community integrations | Basic | pip install langchain-community | |
pip install langgraphInstall LangGraph framework | Intermediate | pip install langgraph | |
langgraph buildBuild LangGraph app for deployment | Intermediate | langgraph build -t my-agent:latest | |
langgraph build -tSpecify Docker image tag | Intermediate | langgraph build -t my-agent:v1 | |
langgraph testRun LangGraph tests | Intermediate | langgraph test | |
langchain template listList all available template packages | Basic | langchain template list | |
pip install langchain-postgresInstall LangChain PostgreSQL integration | Intermediate | pip install langchain-postgres | |
pip install langchain-chromaInstall LangChain Chroma integration | Intermediate | pip install langchain-chroma | |
export LANGCHAIN_API_KEYSet LangSmith API key | Basic | export LANGCHAIN_API_KEY=ls-xxx | |
export LANGCHAIN_TRACING_V2=trueEnable LangSmith tracing | Intermediate | export LANGCHAIN_TRACING_V2=true |
ai-server(8)
| Command | Level | ||
|---|---|---|---|
langchain serveStart LangServe REST API server | Intermediate | langchain serve | |
langchain serve --portSpecify server port | Basic | langchain serve --port 8080 | |
langchain serve --hostSpecify bind host address | Basic | langchain serve --host 0.0.0.0 | |
langgraph devStart LangGraph development server | Intermediate | langgraph dev | |
langgraph upStart LangGraph app with Docker Compose | Intermediate | langgraph up | |
npx @langchain/langgraph-cli devStart LangGraph dev server via npx | Intermediate | npx @langchain/langgraph-cli dev | |
curl http://localhost:8000/docsAccess LangServe API documentation | Basic | curl -s http://localhost:8000/docs | |
curl http://localhost:8000/rag/playgroundAccess LangServe Playground UI | Basic | curl -s http://localhost:8000/rag/playground |