Who this is for and what you will build
This article is for readers who know some Python or JavaScript and want a first AI agent that can call a tool. By the end you will have LangChain installed, a model API key configured, a working agent that calls a weather function, and optional tracing that shows every model call.
What LangChain offers
LangChain gives you one interface to hundreds of large language models and thousands of other integrations[1]. Those integrations live in independent provider packages, so OpenAI support comes from langchain-openai and Anthropic support from langchain-anthropic[1]. Switching to another model usually means changing the model name and setting the matching API key[2]. That is the most direct benefit when you build your first agent, because the agent code itself barely changes.
Prerequisites
- Python 3.10 or later for the core package. The Python example pins Python 3.11[1][2]. JavaScript needs Node.js 22 or later, and Bun needs version 1.0.0 or later[1].
- An API key from a supported provider, such as OpenAI, Google Gemini, Anthropic, OpenRouter, Fireworks, Baseten, Ollama, Azure OpenAI, AWS Bedrock or HuggingFace[2].
- Usage is billed by the provider you choose. This article does not cover pricing.
Step 1: Install the packages
With uv, the following commands pin Python 3.11, create the project and add LangChain[2]:
uv python pin 3.11
uv init
uv add langchain
uv syncIf you prefer venv and pip, the sequence below works. The activation path on Windows differs, and the comment in the block shows it[2]:
python3.11 -m venv .venv
source .venv/bin/activate
# Windows: .venv\Scripts\activate
pip install -U langchainFor OpenAI or Anthropic models, install the provider package as well with pip install -U langchain-openai or pip install -U langchain-anthropic[1]. In a JavaScript project, the core package is installed with npm install langchain @langchain/core[1].
Step 2: Configure API keys
Keep keys in environment variables rather than in source code or in a repository. In a shell you can run export OPENAI_API_KEY="your-api-key", or put OPENAI_API_KEY=your-api-key in a .env file[2]. Python loads .env with load_dotenv() from python-dotenv, while JavaScript uses import "dotenv/config"[2].
Variable names depend on the provider. Google Gemini uses GOOGLE_API_KEY, Claude uses ANTHROPIC_API_KEY, OpenRouter uses OPENROUTER_API_KEY, Fireworks uses FIREWORKS_API_KEY and Baseten uses BASETEN_API_KEY[2]. Local Ollama requires the Ollama server to be running, and Ollama cloud requires OLLAMA_API_KEY[2]. Azure needs AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME. AWS Bedrock needs AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION. HuggingFace uses HUGGINGFACEHUB_API_TOKEN[2]. If requests go through the LangSmith LLM Gateway, the gateway key is used as the API key[2].
Step 3: Write the first agent
In Python, create_agent is imported from langchain.agents. The example below uses Claude. get_weather is an ordinary function, and placing it in the tools list makes it available to the agent[2]:
from langchain.agents import create_agent
def get_weather(city: str) -> str:
"""Get weather for a given city."""
return f"It's always sunny in {city}!"
agent = create_agent(
model="claude-sonnet-4-6",
tools=[get_weather],
system_prompt="You are a helpful assistant",
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]}
)
print(result["messages"][-1].content_blocks)The agent reads the city from the question and calls get_weather with it. The last line prints the content blocks of the final message, which confirms that the run finished[2].
Model strings usually take the form provider:model, such as google_genai:gemini-2.5-flash-lite, while the Claude example uses claude-sonnet-4-6[2]. The JavaScript version imports createAgent and tool from langchain and describes the tool's input with zod[2].
Step 4: Turn on tracing (optional)
Agents often call a model several times, and the intermediate steps are hard to see without tracing. LangChain recommends LangSmith[2]. Set these variables and run the script again:
export LANGSMITH_AGENT_ID="<your-agent-id>"
export LANGSMITH_AGENT_ENVIRONMENT="local"
export LANGSMITH_TRACING="true"
export LANGSMITH_API_KEY="..."Afterwards, LangSmith shows each agent call the script made[2].
A second, longer example
The second example is a research agent that answers questions about text files. It covers detailed system prompts, a tool that loads document text from a URL, model configuration, conversational memory, Deep Agents and testing[2].
Common problems
- An error about a missing key: check that the variable name matches the provider. OpenRouter, for example, reads
OPENROUTER_API_KEY, notOPENAI_API_KEY[2]. - An unexpected model: the model string must follow the format that the provider expects, as in the examples above[2].
- Scope: this example covers a single question-and-answer agent. Memory and production deployment are covered in the LangGraph and Deep Agents material[2].
Next steps
Replace get_weather with a real weather data source, then move on to the tools article in this series. Further reading on memory and deployment is available in LangChain's documentation[2].
Adapted from the Install and Quickstart pages of LangChain's open-source documentation[1][2], released under the MIT License.
Sources
- 1Install LangChainLangChain docs (MIT)
- 2QuickstartLangChain docs (MIT)
Cite this page: LangChain quickstart: install and build a first agent. TellWorld, https://www.tellworld.net/practice/practice-langchain-quickstart. Updated 2026-11-14