|
1 | 1 | # LangChain <> Llama3 Cookbooks
|
2 | 2 |
|
3 |
| -LLM agents use [planning, memory, and tools](https://lilianweng.github.io/posts/2023-06-23-agent/) to accomplish tasks. |
| 3 | +LLM agents use [planning, memory, and tools](https://lilianweng.github.io/posts/2023-06-23-agent/) to accomplish tasks. Agents can empower Llama 3 with important new capabilities. Here, we will show how to give Llama 3 the ability to perform web search, as well as multi-modality: image generation (text-to-image), image analysis (image-to-text), and voice (text-to-speech) tools! |
4 | 4 |
|
5 |
| -LangChain offers several different ways to implement agents. |
| 5 | +LangChain offers several different ways to implement agents with Llama 3: |
6 | 6 |
|
7 |
| -(1) Use [AgentExecutor](https://python.langchain.com/docs/modules/agents/quick_start/) with [tool-calling](https://python.langchain.com/docs/integrations/chat/) versions of Llama 3. |
| 7 | +(1) `ReAct agent` - Uses [AgentExecutor](https://python.langchain.com/docs/modules/agents/quick_start/) with [tool-calling](https://python.langchain.com/docs/integrations/chat/) versions of Llama 3. |
8 | 8 |
|
9 |
| -(2) Use [LangGraph](https://python.langchain.com/docs/langgraph), a library from LangChain that can be used to build reliable agents with Llama 3. |
| 9 | +(2) `LangGraph tool calling agent` - Uses [LangGraph](https://python.langchain.com/docs/langgraph) with [tool-calling](https://python.langchain.com/docs/integrations/chat/) versions of Llama 3. |
| 10 | + |
| 11 | +(3) `LangGraph custom agent` - Uses [LangGraph](https://python.langchain.com/docs/langgraph) with **any** version of Llama 3 (so long as it supports structured output). |
| 12 | + |
| 13 | +As we move from option (1) to (3) the degree of customization and flexibility increases: |
| 14 | + |
| 15 | +(1) `ReAct agent` using AgentExecutor is a great for getting started quickly with minimal code, but requires a version of Llama 3 with reliable tool-calling, is the least customizable, and uses higher-level AgentExecutor abstraction. |
| 16 | + |
| 17 | +(2) `LangGraph tool calling agent` is more customizable than (1) because the LLM assistant (planning) and tool call (action) nodes are defined by the user, but it still requires a version of Llama 3 with reliable tool-calling. |
| 18 | + |
| 19 | +(3) `LangGraph custom agent` does not require a version of Llama 3 with reliable tool-calling and is the most customizable, but requires the most work to implement. |
| 20 | + |
| 21 | + |
10 | 22 |
|
11 | 23 | ---
|
12 | 24 |
|
13 |
| -### AgentExecutor Agent |
| 25 | +### `ReAct agent` |
14 | 26 |
|
15 |
| -AgentExecutor is the runtime for an agent. AgentExecutor calls the agent, executes the actions it chooses, passes the action outputs back to the agent, and repeats. |
| 27 | +The AgentExecutor manages the loop of planning, executing tool calls, and processing outputs until an AgentFinish signal is generated, indicating task completion. |
16 | 28 |
|
17 | 29 | Our first notebook, `tool-calling-agent`, shows how to build a [tool calling agent](https://python.langchain.com/docs/modules/agents/agent_types/tool_calling/) with AgentExecutor and Llama 3.
|
18 | 30 |
|
19 |
| -This shows how to build an agent that uses web search, text2image, image2text, and text2speech tools. |
20 |
| - |
21 | 31 | ---
|
22 | 32 |
|
23 |
| -### LangGraph Agent |
| 33 | +### `LangGraph tool calling agent` |
24 | 34 |
|
25 | 35 | [LangGraph](https://python.langchain.com/docs/langgraph) is a library from LangChain that can be used to build reliable agents.
|
26 | 36 |
|
27 |
| -LangGraph can be used to build agents with a few pieces: |
28 |
| -- **Planning:** Define a control flow of steps that you want the agent to take (a graph) |
29 |
| -- **Memory:** Persist information (graph state) across these steps |
30 |
| -- **Tool use:** Modify state at any step |
| 37 | +Our second notebook, `langgraph-tool-calling-agent`, shows an alternative to AgentExecutor for building a Llama 3 powered agent. |
| 38 | + |
| 39 | +--- |
31 | 40 |
|
32 |
| -Our second notebook, `langgraph-agent`, shows an alternative way to AgentExecutor to build a Llama 3 powered agent in LangGraph. |
| 41 | +### `LangGraph custom agent` |
33 | 42 |
|
34 |
| -It discusses some of the trade-offs between AgentExecutor and LangGraph. |
| 43 | +Our third notebook, `langgraph-custom-agent`, shows how to build a Llama 3 powered agent without reliance on tool-calling. |
35 | 44 |
|
36 | 45 | ---
|
37 | 46 |
|
38 |
| -### LangGraph RAG Agent |
| 47 | +### `LangGraph RAG Agent` |
39 | 48 |
|
40 |
| -Our third notebook, `langgraph-rag-agent`, shows how to apply LangGraph to build advanced Llama 3 powered RAG agents that use ideas from 3 papers: |
| 49 | +Our fourth notebook, `langgraph-rag-agent`, shows how to apply LangGraph to build a custom Llama 3 powered RAG agent that use ideas from 3 papers: |
41 | 50 |
|
42 | 51 | * Corrective-RAG (CRAG) [paper](https://arxiv.org/pdf/2401.15884.pdf) uses self-grading on retrieved documents and web-search fallback if documents are not relevant.
|
43 | 52 | * Self-RAG [paper](https://arxiv.org/abs/2310.11511) adds self-grading on generations for hallucinations and for ability to answer the question.
|
44 | 53 | * Adaptive RAG [paper](https://arxiv.org/abs/2403.14403) routes queries between different RAG approaches based on their complexity.
|
45 | 54 |
|
46 | 55 | We implement each approach as a control flow in LangGraph:
|
47 |
| -- **Planning:** The sequence of RAG steps (e.g., retrieval, grading, and generation) that we want the agent to take |
48 |
| -- **Memory:** All the RAG-related information (input question, retrieved documents, etc) that we want to pass between steps |
49 |
| -- **Tool use:** All the tools needed for RAG (e.g., decide web search or vectorstore retrieval based on the question) |
| 56 | +- **Planning:** The sequence of RAG steps (e.g., retrieval, grading, and generation) that we want the agent to take. |
| 57 | +- **Memory:** All the RAG-related information (input question, retrieved documents, etc) that we want to pass between steps. |
| 58 | +- **Tool use:** All the tools needed for RAG (e.g., decide web search or vectorstore retrieval based on the question). |
50 | 59 |
|
51 | 60 | We will build from CRAG (blue, below) to Self-RAG (green) and finally to Adaptive RAG (red):
|
52 | 61 |
|
53 |
| - |
| 62 | + |
54 | 63 |
|
55 | 64 | ---
|
| 65 | + |
| 66 | +### `Local LangGraph RAG Agent` |
56 | 67 |
|
57 |
| -### Local LangGraph RAG Agent |
58 |
| - |
59 |
| -Our fourth notebook, `langgraph-rag-agent-local`, shows how to apply LangGraph to build advanced RAG agents using Llama 3 that run locally and reliably. |
| 68 | +Our fifth notebook, `langgraph-rag-agent-local`, shows how to apply LangGraph to build advanced RAG agents using Llama 3 that run locally and reliably. |
60 | 69 |
|
61 |
| -See this [video overview](https://www.youtube.com/watch?v=sgnrL7yo1TE) for more detail. |
| 70 | +See this [video overview](https://www.youtube.com/watch?v=sgnrL7yo1TE) for more detail on the design of this agent. |
0 commit comments