Components, Tools, and Relationships
Relationship Explanation:
LLM serves as the core foundation, powering all agent capabilities.
Agent Types define how the agent makes decisions, while Tools provide specific capabilities that agents can use. The Memory & Execution layer manages conversation context and handles the execution flow of agent actions.
from langchain.agents import AgentType, initialize_agent, load_tools
from langchain.llms import OpenAI
# Initialize the language model
llm = OpenAI(temperature=0)
# Load tools the agent can use
tools = load_tools(["serpapi", "llm-math"], llm=llm)
# Create an agent with the tools and LLM
agent = initialize_agent(
tools,
llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True
)
# Run the agent on a specific task
result = agent.run(
"What was the high temperature in SF yesterday? "
"What is that number raised to the .023 power?"
)