One of the standout features of LangChain is its support for creating Agents that can make decisions based on user queries and available tools. Agents can dynamically determine which action to take based on input, making them incredibly versatile for various applications, from chatbots to automated workflows.
Using LangChain, you can easily create an agent that utilizes different tools depending on the user's request. Below is a simple example that demonstrates how to create an agent that can respond to queries using a predefined set of tools:
from langchain.agents import initialize_agent, Tool
from langchain.chat_models import ChatOpenAI
# Initialize the language model
llm = ChatOpenAI(temperature=0)
# Define some tools the agent can use
tools = [
Tool(name="Time Tool", func=lambda: "The current time is: " + str(datetime.now())),
Tool(name="Math Tool", func=lambda x: eval(x)),
]
# Initialize the agent with the tools and the language model
agent = initialize_agent(tools, llm, agent_type="zero-shot-react-description")
# Example query
response = agent("What's 5 plus 10?")
print(response)
This code snippet shows how to initialize a simple agent capable of performing basic math operations and telling the time. By adding more tools, your agents can become even more powerful and capable of handling a wider array of tasks.
Explore LangChain today to unlock the potential of creating intelligent agents that can interact and react to real-time user needs!