Introduction
Agents are systems that use language models to reason about which actions to take and then execute those actions. They can use tools, make decisions, and work toward goals autonomously. In LangChain.js, agents combine:- Chat models for reasoning and decision-making
- Tools for taking actions (API calls, database queries, etc.)
- Memory for maintaining conversation context
- Execution loops for iterative problem-solving
Quick Start
The simplest way to create an agent is using thecreateAgent function:
Agent Components
AgentAction
Represents an action the agent decides to take:AgentFinish
Represents the agent’s final response:AgentStep
Tracks an action and its result:Building Custom Agents
Multi-Tool Agent
Create an agent that can use multiple tools:Agent with Memory
Add persistent memory to your agent:Streaming Agent Responses
Stream agent execution to show progress in real-time:Agent Execution Control
Setting Iteration Limits
Prevent infinite loops by limiting agent iterations:Handling Errors
Implement error handling in your agent:Advanced Agent Patterns
Multi-Agent Systems
Create specialized agents that work together:Agent with Structured Output
Get structured responses from your agent:Best Practices
Design Clear Tool Descriptions
Design Clear Tool Descriptions
Tool descriptions guide the agent’s decision-making:
Add System Prompts
Add System Prompts
Guide agent behavior with system prompts:
Implement Guardrails
Implement Guardrails
Add safety checks to prevent unwanted behavior:
Monitor and Log
Monitor and Log
Track agent behavior for debugging and improvement:
Next Steps
Creating Tools
Learn how to build custom tools for your agents
Memory and History
Add conversation memory to your agents
Streaming
Stream agent responses in real-time
Callbacks and Tracing
Monitor and debug agent execution
