LangChain is a powerful framework designed to ease the development of applications using language models. One of its standout features is the ability to create agents that can make decisions based on user input and context. Agents utilize tools and chains to perform tasks effectively, making them a perfect fit for complex workflows.
Here's a quick code snippet to demonstrate how to set up a simple agent that uses a language model for question answering:
from langchain import OpenAI, LLMPredictor, AgentExecutor, Tool
# Define a tool
tool = Tool(
name="QuestionAnsweringTool",
func=llm_predictor.answer_question,
description="Answer questions based on provided context."
)
# Initialize the LLM
llm = OpenAI(model="gpt-3.5-turbo")
# Create the agent executor
agent_executor = AgentExecutor(
llm_predictor=LLMPredictor(llm),
tools=[tool]
)
# Run the agent on a question
response = agent_executor.run("What is LangChain?")
print(response)
This code showcases how simple it is to create an agent that can interactively respond to questions. By utilizing the predefined tools and leveraging the power of language models, developers can build intelligent applications effortlessly. Dive into LangChain and explore the limitless possibilities!