Skip to content

Commit 93e54ec

Browse files
committed
split rag agent
1 parent f5b9f3d commit 93e54ec

File tree

11 files changed

+174
-21
lines changed

11 files changed

+174
-21
lines changed

.ci/ignore_treon_docker.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ notebooks/explainable-ai-1-basic/explainable-ai-1-basic.ipynb
6464
notebooks/explainable-ai-2-deep-dive/explainable-ai-2-deep-dive.ipynb
6565
notebooks/explainable-ai-3-map-interpretation/explainable-ai-3-map-interpretation.ipynb
6666
notebooks/phi-3-vision/phi-3-vision.ipynb
67-
notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb
67+
notebooks/llm-agent-rag-llamaindex/llm-agent-rag-llamaindex.ipynb
6868
notebooks/stable-audio/stable-audio.ipynb
6969
notebooks/internvl2/internvl2.ipynb
7070
notebooks/qwen2-vl/qwen2-vl.ipynb
@@ -73,9 +73,9 @@ notebooks/stable-fast-3d/stable-fast-3d.ipynb
7373
notebooks/mllama-3.2/mllama-3.2.ipynb
7474
notebooks/sam2-image-segmentation/segment-anything-2-image.ipynb
7575
notebooks/pixtral/pixtral.ipynb
76-
notebooks/llm-agent-react/llm-agent-react.ipynb
76+
notebooks/llm-native-agent-react/llm-native-agent-react.ipynb
7777
notebooks/multilora-image-generation/multilora-image-generation.ipynb
78-
notebooks/llm-agent-react/llm-agent-react-langchain.ipynb
78+
notebooks/llm-agent-react-langchain/llm-agent-react-langchain.ipynb
7979
notebooks/multimodal-rag/multimodal-rag-llamaindex.ipynb
8080
notebooks/llm-rag-langchain/llm-rag-langchain-genai.ipynb
8181
notebooks/ltx-video/ltx-video.ipynb

.ci/skipped_notebooks.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@
375375
- macos-13
376376
- ubuntu-22.04
377377
- windows-2019
378-
- notebook: notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb
378+
- notebook: notebooks/llm-agent-rag-llamaindex/llm-agent-rag-llamaindex.ipynb
379379
skips:
380380
- os:
381381
- macos-13
@@ -425,7 +425,7 @@
425425
- macos-13
426426
- ubuntu-22.04
427427
- windows-2019
428-
- notebook: notebooks/llm-agent-react/llm-agent-react.ipynb
428+
- notebook: notebooks/llm-native-agent-react/llm-native-agent-react.ipynb
429429
skips:
430430
- os:
431431
- macos-13
@@ -445,7 +445,7 @@
445445
skips:
446446
- os:
447447
- macos-13
448-
- notebook: notebooks/llm-agent-react/llm-agent-react-langchain.ipynb
448+
- notebook: notebooks/llm-agent-react-langchain/llm-agent-react-langchain.ipynb
449449
skips:
450450
- os:
451451
- macos-13

notebooks/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
- [LLM Instruction-following pipeline with OpenVINO](./llm-question-answering/llm-question-answering.ipynb)
7272
- [Create an LLM-powered Chatbot using OpenVINO](./llm-chatbot/llm-chatbot.ipynb)
7373
- [Create an LLM-powered Chatbot using OpenVINO Generate API](./llm-chatbot/llm-chatbot-generate-api.ipynb)
74-
- [Create a native Agent with OpenVINO](./llm-agent-react/llm-agent-react.ipynb)
75-
- [Create ReAct Agent using OpenVINO and LangChain](./llm-agent-react/llm-agent-react-langchain.ipynb)
76-
- [Create an Agentic RAG using OpenVINO and LlamaIndex](./llm-agent-react/llm-agent-rag-llamaindex.ipynb)
74+
- [Create a native Agent with OpenVINO](./llm-native-agent-react/llm-native-agent-react.ipynb)
75+
- [Create ReAct Agent using OpenVINO and LangChain](./llm-agent-react-langchain/llm-agent-react-langchain.ipynb)
76+
- [Create an Agentic RAG using OpenVINO and LlamaIndex](./llm-agent-rag-llamaindex/llm-agent-rag-llamaindex.ipynb)
7777
- [Create Function-calling Agent using OpenVINO and Qwen-Agent](./llm-agent-functioncall/llm-agent-functioncall-qwen.ipynb)
7878
- [Visual-language assistant with LLaVA Next and OpenVINO](./llava-next-multimodal-chatbot/llava-next-multimodal-chatbot.ipynb)
7979
- [Visual-language assistant with LLaVA and Optimum Intel OpenVINO integration](./llava-multimodal-chatbot/llava-multimodal-chatbot-optimum.ipynb)
@@ -277,9 +277,9 @@
277277
- [LLM Instruction-following pipeline with OpenVINO](./llm-question-answering/llm-question-answering.ipynb)
278278
- [Create an LLM-powered Chatbot using OpenVINO](./llm-chatbot/llm-chatbot.ipynb)
279279
- [Create an LLM-powered Chatbot using OpenVINO Generate API](./llm-chatbot/llm-chatbot-generate-api.ipynb)
280-
- [Create a native Agent with OpenVINO](./llm-agent-react/llm-agent-react.ipynb)
281-
- [Create ReAct Agent using OpenVINO and LangChain](./llm-agent-react/llm-agent-react-langchain.ipynb)
282-
- [Create an Agentic RAG using OpenVINO and LlamaIndex](./llm-agent-react/llm-agent-rag-llamaindex.ipynb)
280+
- [Create a native Agent with OpenVINO](./llm-native-agent-react/llm-native-agent-react.ipynb)
281+
- [Create ReAct Agent using OpenVINO and LangChain](./llm-agent-react-langchain/llm-agent-react-langchain.ipynb)
282+
- [Create an Agentic RAG using OpenVINO and LlamaIndex](./llm-agent-rag-llamaindex/llm-agent-rag-llamaindex.ipynb)
283283
- [Create Function-calling Agent using OpenVINO and Qwen-Agent](./llm-agent-functioncall/llm-agent-functioncall-qwen.ipynb)
284284
- [Visual-language assistant with LLaVA Next and OpenVINO](./llava-next-multimodal-chatbot/llava-next-multimodal-chatbot.ipynb)
285285
- [Visual-language assistant with LLaVA and Optimum Intel OpenVINO integration](./llava-multimodal-chatbot/llava-multimodal-chatbot-optimum.ipynb)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Create an Agentic RAG using OpenVINO and LlamaIndex
2+
3+
4+
An **agent** is an automated reasoning and decision engine. It takes in a user input/query and can make internal decisions for executing that query in order to return the correct result. The key agent components can include, but are not limited to:
5+
6+
- Breaking down a complex question into smaller ones
7+
- Choosing an external Tool to use + coming up with parameters for calling the Tool
8+
- Planning out a set of tasks
9+
- Storing previously completed tasks in a memory module
10+
11+
[LlamaIndex](https://docs.llamaindex.ai/en/stable/) is a framework for building context-augmented generative AI applications with LLMs.LlamaIndex imposes no restriction on how you use LLMs. You can use LLMs as auto-complete, chatbots, semi-autonomous agents, and more. It just makes using them easier. You can build agents on top of your existing LlamaIndex RAG pipeline to empower it with automated decision capabilities. A lot of modules (routing, query transformations, and more) are already agentic in nature in that they use LLMs for decision making.
12+
13+
![agentic-rag](https://github.com/openvinotoolkit/openvino_notebooks/assets/91237924/871cb90d-27fd-4a87-aa3c-f4cdb199a148)
14+
15+
16+
This example will demonstrate using RAG engines as a tool in an agent with OpenVINO and LlamaIndex.
17+
18+
19+
### Notebook Contents
20+
21+
The tutorial consists of the following steps:
22+
23+
- Prerequisites
24+
- Create tools
25+
- Create prompt template
26+
- Create LLM
27+
- Download model
28+
- Select inference device for LLM
29+
- Create agent
30+
- Run the agent
31+
- Interactive Demo
32+
- Use built-in tool
33+
- Create customized tools
34+
- Create AI agent demo with Gradio UI
35+
36+
## Installation Instructions
37+
38+
This is a self-contained example that relies solely on its own code.</br>
39+
We recommend running the notebook in a virtual environment. You only need a Jupyter server to start.
40+
For details, please refer to [Installation Guide](../../README.md).
41+
42+
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-agent-rag-llamaindex/README.md" />

notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb renamed to notebooks/llm-agent-rag-llamaindex/llm-agent-rag-llamaindex.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"We recommend running the notebook in a virtual environment. You only need a Jupyter server to start.\n",
4545
"For details, please refer to [Installation Guide](https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/README.md#-installation-guide).\n",
4646
"\n",
47-
"<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb\" />\n"
47+
"<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-agent-rag-llamaindex/llm-agent-rag-llamaindex.ipynb\" />\n"
4848
]
4949
},
5050
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Create ReAct Agent using OpenVINO and LangChain
2+
3+
LLM are limited to the knowledge on which they have been trained and the additional knowledge provided as context, as a result, if a useful piece of information is missing the provided knowledge, the model cannot “go around” and try to find it in other sources. This is the reason why we need to introduce the concept of Agents.
4+
5+
The core idea of agents is to use a language model to choose a sequence of actions to take. In agents, a language model is used as a reasoning engine to determine which actions to take and in which order. Agents can be seen as applications powered by LLMs and integrated with a set of tools like search engines, databases, websites, and so on. Within an agent, the LLM is the reasoning engine that, based on the user input, is able to plan and execute a set of actions that are needed to fulfill the request.
6+
7+
![image](https://github.com/user-attachments/assets/b656adab-a448-4784-a6df-a068e0cb45bb)
8+
9+
This notebook explores how to create an ReAct Agent step by step using OpenVINO and LangChain. [ReAct](https://arxiv.org/abs/2210.03629) is an approach to combine reasoning (e.g. chain-of-thought prompting) and acting. ReAct overcomes issues of hallucination and error propagation prevalent in chain-of-thought reasoning by interacting with a simple Wikipedia API, and generates human-like task-solving trajectories that are more interpretable than baselines without reasoning traces.
10+
11+
12+
[LangChain](https://python.langchain.com/docs/get_started/introduction) is a framework for developing applications powered by language models. LangChain comes with a number of built-in agents that are optimized for different use cases.
13+
14+
15+
### Notebook Contents
16+
17+
The tutorial consists of the following steps:
18+
19+
- Prerequisites
20+
- Create tools
21+
- Create prompt template
22+
- Create LLM
23+
- Download model
24+
- Select inference device for LLM
25+
- Create agent
26+
- Run the agent
27+
- Interactive Demo
28+
- Use built-in tool
29+
- Create customized tools
30+
- Create AI agent demo with Gradio UI
31+
32+
## Installation Instructions
33+
34+
This is a self-contained example that relies solely on its own code.</br>
35+
We recommend running the notebook in a virtual environment. You only need a Jupyter server to start.
36+
For details, please refer to [Installation Guide](../../README.md).
37+
38+
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-agent-react-langchain/README.md" />

notebooks/llm-agent-react/llm-agent-react-langchain.ipynb renamed to notebooks/llm-agent-react-langchain/llm-agent-react-langchain.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"We recommend running the notebook in a virtual environment. You only need a Jupyter server to start.\n",
4141
"For details, please refer to [Installation Guide](https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/README.md#-installation-guide).\n",
4242
"\n",
43-
"<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-agent-react/llm-agent-react-langchain.ipynb\" />\n"
43+
"<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-agent-react-langchain/llm-agent-react-langchain.ipynb\" />\n"
4444
]
4545
},
4646
{
@@ -985,7 +985,7 @@
985985
"outputs": [],
986986
"source": [
987987
"if not Path(\"gradio_helper.py\").exists():\n",
988-
" r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/llm-agent-react/gradio_helper.py\")\n",
988+
" r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/llm-agent-react-langchain/gradio_helper.py\")\n",
989989
" open(\"gradio_helper.py\", \"w\").write(r.text)\n",
990990
"\n",
991991
"from gradio_helper import make_demo\n",

notebooks/llm-agent-react/README.md renamed to notebooks/llm-native-agent-react/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Create a ReAct Agent using OpenVINO
1+
# Create a native Agent with OpenVINO
22

33
LLM are limited to the knowledge on which they have been trained and the additional knowledge provided as context, as a result, if a useful piece of information is missing the provided knowledge, the model cannot “go around” and try to find it in other sources. This is the reason why we need to introduce the concept of Agents.
44

@@ -32,4 +32,4 @@ This is a self-contained example that relies solely on its own code.</br>
3232
We recommend running the notebook in a virtual environment. You only need a Jupyter server to start.
3333
For details, please refer to [Installation Guide](../../README.md).
3434

35-
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-agent-react/README.md" />
35+
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-native-agent-react/README.md" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from typing import Callable, List
2+
import gradio as gr
3+
4+
5+
def handle_user_message(message, history):
6+
"""
7+
callback function for updating user messages in interface on submit button click
8+
9+
Params:
10+
message: current message
11+
history: conversation history
12+
Returns:
13+
None
14+
"""
15+
# Append the user's message to the conversation history
16+
return "", history + [[message, ""]]
17+
18+
19+
def make_demo(run_fn: Callable, stop_fn: Callable, examples: List):
20+
with gr.Blocks(
21+
theme=gr.themes.Soft(),
22+
css=".disclaimer {font-variant-caps: all-small-caps;}",
23+
) as demo:
24+
gr.Markdown(f"""<h1><center>AI Agent with OpenVINO</center></h1>""")
25+
chatbot = gr.Chatbot(height=800)
26+
with gr.Row():
27+
with gr.Column():
28+
msg = gr.Textbox(
29+
label="Chat Message Box",
30+
placeholder="Chat Message Box",
31+
show_label=False,
32+
container=False,
33+
)
34+
with gr.Column():
35+
with gr.Row():
36+
submit = gr.Button("Submit")
37+
stop = gr.Button("Stop")
38+
clear = gr.Button("Clear")
39+
gr.Examples(examples, inputs=msg, label="Click on any example and press the 'Submit' button")
40+
41+
submit_event = msg.submit(
42+
fn=handle_user_message,
43+
inputs=[msg, chatbot],
44+
outputs=[msg, chatbot],
45+
queue=False,
46+
).then(
47+
fn=run_fn,
48+
inputs=[
49+
chatbot,
50+
],
51+
outputs=chatbot,
52+
queue=True,
53+
)
54+
submit_click_event = submit.click(
55+
fn=handle_user_message,
56+
inputs=[msg, chatbot],
57+
outputs=[msg, chatbot],
58+
queue=False,
59+
).then(
60+
fn=run_fn,
61+
inputs=[
62+
chatbot,
63+
],
64+
outputs=chatbot,
65+
queue=True,
66+
)
67+
stop.click(
68+
fn=stop_fn,
69+
inputs=None,
70+
outputs=None,
71+
cancels=[submit_event, submit_click_event],
72+
queue=False,
73+
)
74+
clear.click(lambda: None, None, chatbot, queue=False)
75+
return demo

notebooks/llm-agent-react/llm-agent-react.ipynb renamed to notebooks/llm-native-agent-react/llm-agent-react.ipynb

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737
"We recommend running the notebook in a virtual environment. You only need a Jupyter server to start.\n",
3838
"For details, please refer to [Installation Guide](https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/README.md#-installation-guide).\n",
3939
"\n",
40-
"<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-agent-react/llm-agent-rag-llamaindex.ipynb\" />\n",
41-
"\n",
42-
"<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-agent-react/llm-agent-react.ipynb\" />\n"
40+
"<img referrerpolicy=\"no-referrer-when-downgrade\" src=\"https://static.scarf.sh/a.png?x-pxid=5b5a4db0-7875-4bfb-bdbd-01698b5b1a77&file=notebooks/llm-native-agent-react/llm-agent-react.ipynb\" />\n"
4341
]
4442
},
4543
{
@@ -764,7 +762,7 @@
764762
"outputs": [],
765763
"source": [
766764
"if not Path(\"gradio_helper.py\").exists():\n",
767-
" r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/llm-agent-react/gradio_helper.py\")\n",
765+
" r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/llm-native-agent-react/gradio_helper.py\")\n",
768766
" open(\"gradio_helper.py\", \"w\").write(r.text)\n",
769767
"\n",
770768
"from gradio_helper import make_demo\n",

0 commit comments

Comments
 (0)