Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
|
|
|
Agents
|
|
|
|
==========================
|
|
|
|
|
2023-03-27 02:49:46 +00:00
|
|
|
.. note::
|
|
|
|
`Conceptual Guide <https://docs.langchain.com/docs/components/agents>`_
|
|
|
|
|
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
Some applications require not just a predetermined chain of calls to LLMs/other tools,
|
2023-02-27 22:40:43 +00:00
|
|
|
but potentially an unknown chain that depends on the user's input.
|
2023-06-03 21:44:32 +00:00
|
|
|
In these types of chains, there is an **agent** which has access to a suite of **tools**.
|
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
|
|
|
Depending on the user input, the agent can then decide which, if any, of these tools to call.
|
|
|
|
|
2023-05-10 04:07:56 +00:00
|
|
|
At the moment, there are two main types of agents:
|
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
1. **Action Agents**: these agents decide the actions to take and execute that actions one action at a time.
|
|
|
|
2. **Plan-and-Execute Agents**: these agents first decide a plan of actions to take, and then execute those actions one at a time.
|
2023-05-10 04:07:56 +00:00
|
|
|
|
|
|
|
When should you use each one? Action Agents are more conventional, and good for small tasks.
|
2023-06-03 21:44:32 +00:00
|
|
|
For more complex or long running tasks, the initial planning step helps to maintain long term objectives and focus.
|
|
|
|
However, that comes at the expense of generally more calls and higher latency.
|
|
|
|
These two agents are also not mutually exclusive - in fact, it is often best to have an Action Agent be in charge
|
|
|
|
of the execution for the Plan and Execute agent.
|
2023-05-10 04:07:56 +00:00
|
|
|
|
|
|
|
Action Agents
|
|
|
|
-------------
|
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
High level pseudocode of the Action Agents:
|
2023-05-04 05:44:01 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
- The **user input** is received
|
|
|
|
- The **agent** decides which **tool** - if any - to use, and what the **tool input** should be
|
|
|
|
- That **tool** is then called with the **tool input**, and an **observation** is recorded (the output of this calling)
|
|
|
|
- That history of **tool**, **tool input**, and **observation** is passed back into the **agent**, and it decides the next step
|
|
|
|
- This is repeated until the **agent** decides it no longer needs to use a **tool**, and then it responds directly to the user.
|
2023-05-04 05:44:01 +00:00
|
|
|
|
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
The different abstractions involved in agents are:
|
2023-05-04 05:44:01 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
- **Agent**: this is where the logic of the application lives. Agents expose an interface that takes in user input
|
|
|
|
along with a list of previous steps the agent has taken, and returns either an **AgentAction** or **AgentFinish**
|
2023-05-04 05:44:01 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
- **AgentAction** corresponds to the tool to use and the input to that tool
|
|
|
|
- **AgentFinish** means the agent is done, and has information around what to return to the user
|
|
|
|
- **Tools**: these are the actions an agent can take. What tools you give an agent highly depend on what you want the agent to do
|
|
|
|
- **Toolkits**: these are groups of tools designed for a specific use case. For example, in order for an agent to
|
|
|
|
interact with a SQL database in the best way it may need access to one tool to execute queries and another tool to inspect tables.
|
|
|
|
- **Agent Executor**: this wraps an agent and a list of tools. This is responsible for the loop of running the agent
|
|
|
|
iteratively until the stopping criteria is met.
|
2023-05-04 05:44:01 +00:00
|
|
|
|
2023-03-27 02:49:46 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
|
|
|
|
|
- `Getting Started <./agents/getting_started.html>`_: An overview of agents. It covers how to use all things related to agents in an end-to-end manner.
|
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
|
|
|
|
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
|
|
|
|
|
**Agent Construction:**
|
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
Although an agent can be constructed in many way, the typical way to construct an agent is with:
|
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
- **PromptTemplate**: this is responsible for taking the user input and previous steps and constructing a prompt
|
|
|
|
to send to the language model
|
|
|
|
- **Language Model**: this takes the prompt constructed by the PromptTemplate and returns some output
|
|
|
|
- **Output Parser**: this takes the output of the Language Model and parses it into an **AgentAction** or **AgentFinish** object.
|
Docs refactor (#480)
Big docs refactor! Motivation is to make it easier for people to find
resources they are looking for. To accomplish this, there are now three
main sections:
- Getting Started: steps for getting started, walking through most core
functionality
- Modules: these are different modules of functionality that langchain
provides. Each part here has a "getting started", "how to", "key
concepts" and "reference" section (except in a few select cases where it
didnt easily fit).
- Use Cases: this is to separate use cases (like summarization, question
answering, evaluation, etc) from the modules, and provide a different
entry point to the code base.
There is also a full reference section, as well as extra resources
(glossary, gallery, etc)
Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
2023-01-02 16:24:09 +00:00
|
|
|
|
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
|
|
|
|
|
**Additional Documentation:**
|
2023-03-27 02:49:46 +00:00
|
|
|
|
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
- `Tools <./agents/tools.html>`_: Different types of **tools** LangChain supports natively. We also cover how to add your own tools.
|
2023-03-27 02:49:46 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
- `Agents <./agents/agents.html>`_: Different types of **agents** LangChain supports natively. We also cover how to
|
|
|
|
modify and create your own agents.
|
2023-03-27 02:49:46 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
- `Toolkits <./agents/toolkits.html>`_: Various **toolkits** that LangChain supports out of the box, and how to
|
|
|
|
create an agent from them.
|
2023-03-27 02:49:46 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
- `Agent Executor <./agents/agent_executors.html>`_: The **Agent Executor** class, which is responsible for calling
|
|
|
|
the agent and tools in a loop. We go over different ways to customize this, and options you can use for more control.
|
2023-03-27 02:49:46 +00:00
|
|
|
|
2023-05-10 04:07:56 +00:00
|
|
|
|
|
|
|
Plan-and-Execute Agents
|
|
|
|
-----------------------
|
2023-06-03 21:44:32 +00:00
|
|
|
High level pseudocode of the **Plan-and-Execute Agents**:
|
2023-05-10 04:07:56 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
- The **user input** is received
|
|
|
|
- The **planner** lists out the steps to take
|
|
|
|
- The **executor** goes through the list of steps, executing them
|
2023-05-10 04:07:56 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
The most typical implementation is to have the planner be a language model, and the executor be an action agent.
|
2023-05-10 04:07:56 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
|
|
|
|
|
- `Plan-and-Execute Agents <./agents/plan_and_execute.html>`_
|
2023-05-10 04:07:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 1
|
2023-06-03 21:44:32 +00:00
|
|
|
:hidden:
|
2023-05-10 04:07:56 +00:00
|
|
|
|
2023-06-03 21:44:32 +00:00
|
|
|
./agents/getting_started.ipynb
|
|
|
|
./agents/tools.rst
|
|
|
|
./agents/agents.rst
|
|
|
|
./agents/toolkits.rst
|
|
|
|
./agents/agent_executors.rst
|
2023-05-10 04:07:56 +00:00
|
|
|
./agents/plan_and_execute.ipynb
|
|
|
|
|