Introduction
Imagine you want a smart helper that can decide what to do next based on what you ask. LangChain agents solve this by acting like decision-makers that choose the right tools or actions to answer your questions or complete tasks.
Jump into concepts and practice - no test required
Imagine a personal assistant who listens to your request, decides which expert to ask, and then combines their answers to help you. The assistant knows when to ask a weather expert, a calendar manager, or a search specialist.
┌───────────────┐
│ User Input │
└──────┬────────┘
│
▼
┌───────────────┐
│ Agent │
│ (Decision) │
└──────┬────────┘
│
▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ Tool 1 │ │ Tool 2 │ │ Tool 3 │
│ (Search) │ │ (Calculator) │ │ (API Call) │
└───────────────┘ └───────────────┘ └───────────────┘
│ │ │
└──────────┬───────┴───────────┬───────┘
▼ ▼
┌───────────────┐
│ Agent Combines│
│ Results │
└──────┬────────┘
│
▼
┌───────────────┐
│ User Response │
└───────────────┘llm and tools list tools?initialize_agent with parameters: tools, llm, and agent_type.from langchain.agents import initialize_agent, Tool
from langchain.llms import OpenAI
tools = [Tool(name='Search', func=lambda x: 'Found info about ' + x)]
llm = OpenAI(temperature=0)
agent = initialize_agent(tools, llm, agent_type='zero-shot')
response = agent.run('Python programming')response most likely contain?tools = [Tool(name='Calc', func=lambda x: eval(x))]
llm = OpenAI(temperature=0)
agent = initialize_agent(llm, tools, agent_type='zero-shot')
result = agent.run('2 + 2')