Alpha Notice: These docs cover the v1-alpha release. Content is incomplete and subject to change.For the latest stable version, see the v0 LangChain Python or LangChain JavaScript docs.
Install
Build a basic agent
Start by creating a simple agent that can answer questions and call tools. The agent will have the following components:- A language model (Claude Sonnet 4.5)
- A simple tool (weather function)
- A basic prompt
- The ability to invoke it with messages
For this example, you will need to set up a Claude (Anthropic) account and get an API key. Then, set the
ANTHROPIC_API_KEY
environment variable in your terminal.Build a real-world agent
Next, build a practical weather forecasting agent that demonstrates key production concepts:- Detailed system prompts for better agent behavior
- Create tools that integrate with external data
- Model configuration for consistent responses
- Structured output for predictable results
- Conversational memory for chat-like interactions
- Create and run the agent create a fully functional agent
1
Define the system prompt
The system prompt defines your agent’s role and behavior. Keep it specific and actionable:
2
Create tools
Tools are functions your agent can call. They should be well-documented. Oftentimes tools will want to connect to external systems, and will rely on runtime configuration to do so. Notice here how the
getUserLocation
tool does exactly that:Zod is a library for validating and parsing pre-defined schemas. You can use it to define the input schema for your tools to make sure the agent only calls the tool with the correct arguments.Alternatively, you can define the
schema
property as a JSON schema object. Keep in mind that JSON schemas won’t be validated at runtime.Example: Using JSON schema for tool input
Example: Using JSON schema for tool input
3
Configure your model
Set up your language model with the right parameters for your use case:
4
Define response format
Optionally, define a structured response format if you need the agent responses to match
a specific schema.
5
Add memory
Add memory to your agent to maintain state across interactions. This allows
the agent to remember previous conversations and context.
In production, use a persistent checkpointer that saves to a database.
See Add and manage memory for more details.
6
Create and run the agent
Now assemble your agent with all the components and run it!
- Understand context and remember conversations
- Use multiple tools intelligently
- Provide structured responses in a consistent format
- Handle user-specific information through context
- Maintain conversation state across interactions