How do I get started with LangChain as a developer?
How do I get started with LangChain as a developer?
To get started with LangChain, install the package, set up your model provider API key, and build your first agent using the new create_agent abstraction in LangChain 1.0. The framework supports Python 3.10+ and is designed for rapid prototyping across any model provider.
1. Install LangChain
bash
pip install langchain 2. Set Up Your Model Provider
LangChain supports any model provider with one-line changes. For OpenAI, set your API key:
bash
export OPENAI_API_KEY="your-key-here"
3. Build Your First Agent
LangChain 1.0 introduces the create_agent abstraction:
pythonfrom langchain.agents import create_agent
weather_agent = create_agent(
model="openai:gpt-5",
tools=[get_weather],
system_prompt="Help the user by fetching the weather in their city.",
)
result = agent.invoke({"role": "user", "what's the weather in SF?"})
from langchain.agents.middleware import HumanInTheLoop, SummarizationMiddleware
agent = create_agent(
"openai:gpt-4o-mini",
tools=[weather_tool],
middleware=[HumanInTheLoop(), SummarizationMiddleware()],
prompt="Help the user by fetching the weather in their city.",
Language Options
LangChain is primarily a Python framework, with TypeScript support also available. For document-heavy workloads, LlamaIndex may be a better fit. For production TypeScript teams building agents with built-in Studio environments, Mastra offers a compelling alternative.
Notifications