A collection of runnable examples showcasing key LangChain features using TypeScript.
- 
Prerequisites 
- 
Setup 
- 
Examples 
- 
Configuration 
- 
Node.js v16 or later 
- 
npm (comes with Node.js) 
- 
A code editor (e.g., VS Code) 
- Clone the repository
git clone <repo-url> langchain-ts-examples
cd langchain-ts-examples
- Install dependencies
npm install
- Environment variables
- 
Copy .env.exampleto.env
- 
Fill in your API keys: 
OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_ENVIRONMENT=your_pinecone_environment
PINECONE_INDEX=your_pinecone_index
ANTHROPIC_API_KEY=your_anthropic_api_key
TAVILY_API_KEY=your_tavily_api_key
Each example can be run with:
npx ts-node <path-to-example>/index.ts
Location: examples/simple/index.ts
- Demonstrates a basic chat call with OpenAI's ChatOpenAI.
Location: examples/structured-output/index.ts
- Uses zodschemas andStructuredOutputParserto enforce and parse structured JSON output from an LLM.
Location: examples/rag/index.ts
- Shows how to retrieve context from a Pinecone vector store and feed it to a ChatOpenAI model via a StateGraph.
Location: examples/tool-example/index.ts
- Defines a simple uppercase conversion tool and uses LangChain's agent executor for zero-shot tool execution.
Location: examples/langgraph-agent/agent.ts
- Builds an autonomous multi-step agent using LangGraph, integrating a third-party search tool via ToolNode.
- 
**package.json**: sets up scripts and dependencies
- 
**tsconfig.json**: TypeScript compiler options
- 
**.env.example**: template for environment variables