Module#3_L17_Information Retrieval Using Agents & Tools
Module#3_L17_Information Retrieval Using Agents & Tools
Module #3 - LangChain 1
Module 3: Introduction to Langchain. [L-8 P-10 Total:
16 sessions] [Apply]
Introduction to Lang chain: Types, Components, Information retrieval using agents and tools in Lang
chain, Retrieval Augmented Language Models (RALM): Understanding Retrieval and vectors:
Embeddings, Vector storage, Vector indexing, Vector Libraries, Vector Databases, Chatbot using
memory and conversation buffer
17. Introduction to Information retrieval using agents Co3 PPT/
Langchain and tools in Langchain Chalk and
L01: Generalize the concept of Talk
information retrieval L1
methodologies.
L02: Estimate the impact of
agents that influence the L2
information retrieval and tools that
demonstrate the impact.
Module #3 - LangChain 2
An Agent…
In LangChain,
An “Agent” is an AI entity that is able to perceive its environment, act on its
environment, and make intelligent decisions about how to reach a goal, as
well as the ability to learn as it goes”.
Module #3 - LangChain 3
• LLMs have capabilities beyond simply predicting the next word.
• They break the task into steps or sub-tasks, execute each step,
monitor the outcomes, reason through successes or failures, and
adapt the plan accordingly.
4
• They use reasoning, which we can reinforce with prompts and
instructions.
• Agents also require an executor, which is the runtime for the agent
and helps execute it.
5
The brains of a LangChain agent are an
LLM.
So, at a basic level, an agent needs
• an LLM to act as its brain, and to give
it its reasoning abilities
• as tools can interact with the
environment around it and achieve its
goals
6
What are Tools?
Module #3 - LangChain 7
• Tools act as a interface that an
agent, a chain, or a chat model /
LLM can use to interact with the
world. For e.g., Tools can be Search
tool like SerpAPI, Google search etc.,.
• Given a list of tools and prompt, an
LLM can request that one or more
tools be invoked with appropriate
arguments.
8
9
AI Agents with LangChain
10
AI Agent(bot) An example…
11
Create Agent’s in Langchain…
• The basic code to create an agent in LangChain involves defining
tools, loading a prompt template, and initializing a language model.
12
Steps involved to Create Agent’s in Langchain…
• Import the necessary library and modules for Agent
• Define Tool function
• Define Tools
• Prompt Template
• Initialize OpenAI Model
• Initialize the Agent (ReAct Agent)
• Create Agent Executor
• Run the Agent
• Print the response
13
Import Statements: This block imports necessary libraries and modules:
14
Agent’s in Langchain…
15
Define a Tool function…
• This function get_current_time returns the current time formatted as H:MM
AM/PM.
• The function imports the datetime module, gets the current time, and then
formats it.
16
Define a Tools…
The Tools class requires three parameters:
2. Func: Assign the function that you want to associate with this
tool.
17
Define a Tools…
This creates a list of tools available to the agent.
18
• combine all the tools you can simple create a array
19
Pull Prompt Template…
This pulls a prompt template named “react” from the LangChain hub, which is
designed to help the agent reason and take actions.
20
Initialize OpenAI Model…
• For instance, you can employ the OpenAI LLM, which provides powerful
language processing capabilities.
21
Initializing the ReAct Agent…
• Once the tools are created, you can initialize the agent to in executing the
defined tools.
• This creates a ReAct agent using the specified model (llm), tools (tools), and
prompt template (prompt).
22
Create Agent Executor…
• This creates an AgentExecutor that manages the interaction between the agent
and the tools.
• The verbose =True parameter allows detailed logging of the agent’s actions..
23
Run the Agent …
• This runs the agent with a test query: “What time is it?”.
• The agent will use the Time tool to get the current time and respond.
24
Print the Response …
Finally, this prints the response from the agent, which should contain the
25
Benefits of Langchain Agents
1.Flexibility in Integration: Easily integrate with popular LLMs like OpenAI’s
GPT-3, ensuring your applications are powered by the latest in AI.
Module #3 - LangChain 26
Various other Latest Agent Frameworks…
CrewAI – A Platform for Multi Agent Purpose
https://www.crewai.com/?source=post_page-----90d09a9343db
• Crew AI is a framework which helps us build the agents, where the multiple
agents can work on a different task individually and communicate with each
other.
27
CrewAI – an example…
For example, if we ask the Agent to book a movie ticket, it will start by retrieving the user’s
location and searching for nearby theaters.
• It will then check the available movies in those theaters and sort them based on their
preferences.
• Next, it will present options for the selected movies according to their availability, which it can
also determine by accessing the user’s calendar. Finally, it will book the ticket based on their
seat and location preferences.
• For instance, if you mention that you are on a diet, the agent will avoid booking seats at a fast
food restaurant.
28
Various Latest Agent Frameworks…
Autogen– Multi Agent Conversational Framework
https://microsoft.github.io/autogen/?source=post_page-----90d09a9343db
29
References:
1.https://python.langchain.com/v0.1/docs/modules/agents/
2. https://brandonhancock.io/langchain-master-class
3. https://python.langchain.com/v0.1/docs/modules/tools/
30
Complete Code
31
Complete Code
32
Complete Code
33