vectara-agentic 0.1.24__tar.gz → 0.1.26__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of vectara-agentic might be problematic. Click here for more details.
- {vectara_agentic-0.1.24/vectara_agentic.egg-info → vectara_agentic-0.1.26}/PKG-INFO +146 -41
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/README.md +133 -28
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/requirements.txt +12 -12
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/__init__.py +7 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/_prompts.py +3 -2
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/_version.py +1 -1
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/agent.py +109 -30
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/agent_config.py +2 -2
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/tools.py +277 -117
- vectara_agentic-0.1.26/vectara_agentic/tools_catalog.py +155 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/types.py +10 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/utils.py +4 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26/vectara_agentic.egg-info}/PKG-INFO +146 -41
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic.egg-info/requires.txt +12 -12
- vectara_agentic-0.1.24/vectara_agentic/tools_catalog.py +0 -129
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/LICENSE +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/MANIFEST.in +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/setup.cfg +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/setup.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/tests/__init__.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/tests/test_agent.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/tests/test_tools.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/_callback.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/_observability.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/agent_endpoint.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic/db_tools.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic.egg-info/SOURCES.txt +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic.egg-info/dependency_links.txt +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.26}/vectara_agentic.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: vectara_agentic
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.26
|
|
4
4
|
Summary: A Python package for creating AI Assistants and AI Agents with Vectara
|
|
5
5
|
Home-page: https://github.com/vectara/py-vectara-agentic
|
|
6
6
|
Author: Ofer Mendelevitch
|
|
@@ -16,39 +16,39 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
16
16
|
Requires-Python: >=3.10
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: llama-index==0.12.
|
|
19
|
+
Requires-Dist: llama-index==0.12.11
|
|
20
20
|
Requires-Dist: llama-index-indices-managed-vectara==0.3.1
|
|
21
21
|
Requires-Dist: llama-index-agent-llm-compiler==0.3.0
|
|
22
22
|
Requires-Dist: llama-index-agent-lats==0.3.0
|
|
23
|
-
Requires-Dist: llama-index-agent-openai==0.4.
|
|
24
|
-
Requires-Dist: llama-index-llms-openai==0.3.
|
|
25
|
-
Requires-Dist: llama-index-llms-anthropic==0.6.
|
|
23
|
+
Requires-Dist: llama-index-agent-openai==0.4.3
|
|
24
|
+
Requires-Dist: llama-index-llms-openai==0.3.18
|
|
25
|
+
Requires-Dist: llama-index-llms-anthropic==0.6.4
|
|
26
26
|
Requires-Dist: llama-index-llms-together==0.3.1
|
|
27
27
|
Requires-Dist: llama-index-llms-groq==0.3.1
|
|
28
|
-
Requires-Dist: llama-index-llms-fireworks==0.3.
|
|
28
|
+
Requires-Dist: llama-index-llms-fireworks==0.3.1
|
|
29
29
|
Requires-Dist: llama-index-llms-cohere==0.4.0
|
|
30
|
-
Requires-Dist: llama-index-llms-gemini==0.4.
|
|
30
|
+
Requires-Dist: llama-index-llms-gemini==0.4.4
|
|
31
|
+
Requires-Dist: llama-index-llms-bedrock==0.3.3
|
|
31
32
|
Requires-Dist: llama-index-tools-yahoo-finance==0.3.0
|
|
32
33
|
Requires-Dist: llama-index-tools-arxiv==0.3.0
|
|
33
34
|
Requires-Dist: llama-index-tools-database==0.3.0
|
|
34
35
|
Requires-Dist: llama-index-tools-google==0.3.0
|
|
35
36
|
Requires-Dist: llama-index-tools-tavily_research==0.3.0
|
|
36
37
|
Requires-Dist: llama-index-tools-neo4j==0.3.0
|
|
37
|
-
Requires-Dist: llama-index-graph-stores-kuzu==0.
|
|
38
|
+
Requires-Dist: llama-index-graph-stores-kuzu==0.6.0
|
|
38
39
|
Requires-Dist: llama-index-tools-slack==0.3.0
|
|
39
40
|
Requires-Dist: llama-index-tools-exa==0.3.0
|
|
40
41
|
Requires-Dist: tavily-python==0.5.0
|
|
41
|
-
Requires-Dist: exa-py==1.
|
|
42
|
+
Requires-Dist: exa-py==1.8.5
|
|
42
43
|
Requires-Dist: yahoo-finance==1.4.0
|
|
43
|
-
Requires-Dist: openinference-instrumentation-llama-index==3.
|
|
44
|
+
Requires-Dist: openinference-instrumentation-llama-index==3.1.4
|
|
44
45
|
Requires-Dist: opentelemetry-proto==1.26.0
|
|
45
|
-
Requires-Dist: arize-phoenix==
|
|
46
|
+
Requires-Dist: arize-phoenix==7.11.0
|
|
46
47
|
Requires-Dist: arize-phoenix-otel==0.6.1
|
|
47
48
|
Requires-Dist: protobuf==4.25.5
|
|
48
49
|
Requires-Dist: tokenizers>=0.20
|
|
49
|
-
Requires-Dist: pydantic==2.
|
|
50
|
+
Requires-Dist: pydantic==2.10.3
|
|
50
51
|
Requires-Dist: retrying==1.3.4
|
|
51
|
-
Requires-Dist: pymongo==4.10.1
|
|
52
52
|
Requires-Dist: python-dotenv==1.0.1
|
|
53
53
|
Requires-Dist: tiktoken==0.8.0
|
|
54
54
|
Requires-Dist: dill>=0.3.7
|
|
@@ -87,7 +87,7 @@ Dynamic: summary
|
|
|
87
87
|
|
|
88
88
|
## ✨ Overview
|
|
89
89
|
|
|
90
|
-
`vectara-agentic` is a Python library for developing powerful AI assistants and agents using Vectara and Agentic-RAG. It leverages the LlamaIndex Agent framework
|
|
90
|
+
`vectara-agentic` is a Python library for developing powerful AI assistants and agents using Vectara and Agentic-RAG. It leverages the LlamaIndex Agent framework and provides helper functions to quickly create tools that connect to Vectara corpora.
|
|
91
91
|
|
|
92
92
|
<p align="center">
|
|
93
93
|
<img src="https://raw.githubusercontent.com/vectara/py-vectara-agentic/main/.github/assets/diagram1.png" alt="Agentic RAG diagram" width="100%" style="vertical-align: middle;">
|
|
@@ -96,10 +96,10 @@ Dynamic: summary
|
|
|
96
96
|
### Features
|
|
97
97
|
|
|
98
98
|
- Enables easy creation of custom AI assistants and agents.
|
|
99
|
-
- Create a Vectara RAG tool with a single line of code.
|
|
100
|
-
- Supports `ReAct`, `OpenAIAgent`, `LATS
|
|
99
|
+
- Create a Vectara RAG tool or search tool with a single line of code.
|
|
100
|
+
- Supports `ReAct`, `OpenAIAgent`, `LATS` and `LLMCompiler` agent types.
|
|
101
101
|
- Includes pre-built tools for various domains (e.g., finance, legal).
|
|
102
|
-
- Integrates with various LLM inference services like OpenAI, Anthropic, Gemini, GROQ, Together.AI, Cohere and Fireworks
|
|
102
|
+
- Integrates with various LLM inference services like OpenAI, Anthropic, Gemini, GROQ, Together.AI, Cohere, Bedrock and Fireworks
|
|
103
103
|
- Built-in support for observability with Arize Phoenix
|
|
104
104
|
|
|
105
105
|
### 📚 Example AI Assistants
|
|
@@ -109,14 +109,14 @@ Check out our example AI assistants:
|
|
|
109
109
|
- [Financial Assistant](https://huggingface.co/spaces/vectara/finance-chat)
|
|
110
110
|
- [Justice Harvard Teaching Assistant](https://huggingface.co/spaces/vectara/Justice-Harvard)
|
|
111
111
|
- [Legal Assistant](https://huggingface.co/spaces/vectara/legal-agent)
|
|
112
|
-
|
|
112
|
+
- [EV Assistant](https://huggingface.co/spaces/vectara/ev-assistant)
|
|
113
113
|
|
|
114
114
|
### Prerequisites
|
|
115
115
|
|
|
116
116
|
- [Vectara account](https://console.vectara.com/signup/?utm_source=github&utm_medium=code&utm_term=DevRel&utm_content=vectara-agentic&utm_campaign=github-code-DevRel-vectara-agentic)
|
|
117
117
|
- A Vectara corpus with an [API key](https://docs.vectara.com/docs/api-keys)
|
|
118
118
|
- [Python 3.10 or higher](https://www.python.org/downloads/)
|
|
119
|
-
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Cohere, GEMINI or GROQ, if you choose to use them)
|
|
119
|
+
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Bedrock, Cohere, GEMINI or GROQ, if you choose to use them)
|
|
120
120
|
|
|
121
121
|
### Installation
|
|
122
122
|
|
|
@@ -126,18 +126,25 @@ pip install vectara-agentic
|
|
|
126
126
|
|
|
127
127
|
## 🚀 Quick Start
|
|
128
128
|
|
|
129
|
-
### 1.
|
|
129
|
+
### 1. Initialize the Vectara tool factory
|
|
130
130
|
|
|
131
131
|
```python
|
|
132
132
|
import os
|
|
133
133
|
from vectara_agentic.tools import VectaraToolFactory
|
|
134
|
-
from pydantic import BaseModel, Field
|
|
135
134
|
|
|
136
135
|
vec_factory = VectaraToolFactory(
|
|
137
136
|
vectara_api_key=os.environ['VECTARA_API_KEY'],
|
|
138
137
|
vectara_customer_id=os.environ['VECTARA_CUSTOMER_ID'],
|
|
139
138
|
vectara_corpus_id=os.environ['VECTARA_CORPUS_ID']
|
|
140
139
|
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 2. Create a Vectara RAG Tool
|
|
143
|
+
|
|
144
|
+
A RAG tool calls the full Vectara RAG pipeline to provide summarized responses to queries grounded in data.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from pydantic import BaseModel, Field
|
|
141
148
|
|
|
142
149
|
years = list(range(2020, 2024))
|
|
143
150
|
tickers = {
|
|
@@ -156,17 +163,22 @@ query_financial_reports_tool = vec_factory.create_rag_tool(
|
|
|
156
163
|
tool_name="query_financial_reports",
|
|
157
164
|
tool_description="Query financial reports for a company and year",
|
|
158
165
|
tool_args_schema=QueryFinancialReportsArgs,
|
|
166
|
+
lambda_val=0.005,
|
|
167
|
+
summary_num_results=7,
|
|
168
|
+
# Additional arguments
|
|
159
169
|
)
|
|
160
170
|
```
|
|
161
171
|
|
|
162
|
-
|
|
172
|
+
See the [docs](https://vectara.github.io/vectara-agentic-docs/) for additional arguments to customize your Vectara RAG tool.
|
|
173
|
+
|
|
174
|
+
### 3. Create other tools (optional)
|
|
163
175
|
|
|
164
176
|
In addition to RAG tools, you can generate a lot of other types of tools the agent can use. These could be mathematical tools, tools
|
|
165
177
|
that call other APIs to get more information, or any other type of tool.
|
|
166
178
|
|
|
167
179
|
See [Agent Tools](#agent-tools) for more information.
|
|
168
180
|
|
|
169
|
-
###
|
|
181
|
+
### 4. Create your agent
|
|
170
182
|
|
|
171
183
|
```python
|
|
172
184
|
from vectara_agentic import Agent
|
|
@@ -186,20 +198,89 @@ agent = Agent(
|
|
|
186
198
|
)
|
|
187
199
|
```
|
|
188
200
|
|
|
189
|
-
|
|
201
|
+
See the [docs](https://vectara.github.io/vectara-agentic-docs/) for additional arguments, including `agent_progress_callback` and `query_logging_callback`.
|
|
202
|
+
|
|
203
|
+
### 5. Run your agent
|
|
190
204
|
|
|
191
205
|
```python
|
|
192
|
-
|
|
193
|
-
print(response)
|
|
206
|
+
res = agent.chat("What was the revenue for Apple in 2021?")
|
|
207
|
+
print(res.response)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Note that:
|
|
211
|
+
1. `vectara-agentic` also supports `achat()` and two streaming variants `stream_chat()` and `astream_chat()`.
|
|
212
|
+
2. The response types from `chat()` and `achat()` are of type `AgentResponse`. If you just need the actual string
|
|
213
|
+
response it's available as the `response` variable, or just use `str()`. For advanced use-cases you can look
|
|
214
|
+
at other `AgentResponse` variables [such as `sources`](https://github.com/run-llama/llama_index/blob/659f9faaafbecebb6e6c65f42143c0bf19274a37/llama-index-core/llama_index/core/chat_engine/types.py#L53).
|
|
215
|
+
|
|
216
|
+
## 🧰 Vectara tools
|
|
217
|
+
|
|
218
|
+
`vectara-agentic` provides two helper functions to connect with Vectara RAG
|
|
219
|
+
* `create_rag_tool()` to create an agent tool that connects with a Vectara corpus for querying.
|
|
220
|
+
* `create_search_tool()` to create a tool to search a Vectara corpus and return a list of matching documents.
|
|
221
|
+
|
|
222
|
+
See the documentation for the full list of arguments for `create_rag_tool()` and `create_search_tool()`,
|
|
223
|
+
to understand how to configure Vectara query performed by those tools.
|
|
224
|
+
|
|
225
|
+
### Creating a Vectara RAG tool
|
|
226
|
+
|
|
227
|
+
A Vectara RAG tool is often the main workhorse for any Agentic RAG application, and enables the agent to query
|
|
228
|
+
one or more Vectara RAG corpora.
|
|
229
|
+
|
|
230
|
+
The tool generated always includes the `query` argument, followed by 1 or more optional arguments used for
|
|
231
|
+
metadata filtering, defined by `tool_args_schema`.
|
|
232
|
+
|
|
233
|
+
For example, in the quickstart example the schema is:
|
|
234
|
+
|
|
194
235
|
```
|
|
236
|
+
class QueryFinancialReportsArgs(BaseModel):
|
|
237
|
+
query: str = Field(..., description="The user query.")
|
|
238
|
+
year: int | str = Field(..., description=f"The year this query relates to. An integer between {min(years)} and {max(years)} or a string specifying a condition on the year (example: '>2020').")
|
|
239
|
+
ticker: str = Field(..., description=f"The company ticker. Must be a valid ticket symbol from the list {tickers.keys()}.")
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
The `query` is required and is always the query string.
|
|
243
|
+
The other arguments are optional and will be interpreted as Vectara metadata filters.
|
|
195
244
|
|
|
196
|
-
|
|
245
|
+
For example, in the example above, the agent may call the `query_financial_reports_tool` tool with
|
|
246
|
+
query='what is the revenue?', year=2022 and ticker='AAPL'. Subsequently the RAG tool will issue
|
|
247
|
+
a Vectara RAG query with the same query, but with metadata filtering (doc.year=2022 and doc.ticker='AAPL').
|
|
248
|
+
|
|
249
|
+
There are also additional cool features supported here:
|
|
250
|
+
* An argument can be a condition, for example year='>2022' translates to the correct metadata
|
|
251
|
+
filtering condition doc.year>2022
|
|
252
|
+
* if `fixed_filter` is defined in the RAG tool, it provides a constant metadata filtering that is always applied.
|
|
253
|
+
For example, if fixed_filter=`doc.filing_type='10K'` then a query with query='what is the reveue', year=2022
|
|
254
|
+
and ticker='AAPL' would translate into query='what is the revenue' with metadata filtering condition of
|
|
255
|
+
"doc.year=2022 AND doc.ticker='AAPL' and doc.filing_type='10K'"
|
|
256
|
+
|
|
257
|
+
Note that `tool_args_type` is an optional dictionary that indicates the level at which metadata filtering
|
|
258
|
+
is applied for each argument (`doc` or `part`)
|
|
259
|
+
|
|
260
|
+
### Creating a Vectara search tool
|
|
261
|
+
|
|
262
|
+
The Vectara search tool allows the agent to list documents that match a query.
|
|
263
|
+
This can be helpful to the agent to answer queries like "how many documents discuss the iPhone?" or other
|
|
264
|
+
similar queries that require a response in terms of a list of matching documents.
|
|
265
|
+
|
|
266
|
+
## 🛠️ Agent Tools at a Glance
|
|
267
|
+
|
|
268
|
+
`vectara-agentic` provides a few tools out of the box (see ToolsCatalog for details):
|
|
197
269
|
|
|
198
|
-
`vectara-agentic` provides a few tools out of the box:
|
|
199
270
|
1. **Standard tools**:
|
|
200
271
|
- `summarize_text`: a tool to summarize a long text into a shorter summary (uses LLM)
|
|
201
272
|
- `rephrase_text`: a tool to rephrase a given text, given a set of rephrase instructions (uses LLM)
|
|
202
|
-
|
|
273
|
+
These tools use an LLM and so would use the `Tools` LLM specified in your `AgentConfig`.
|
|
274
|
+
To instantiate them:
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
from vectara_agentic.tools_catalog import ToolsCatalog
|
|
278
|
+
summarize_text = ToolsCatalog(agent_config).summarize_text
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
This ensures the summarize_text tool is configured with the proper LLM provider and model as
|
|
282
|
+
specified in the Agent configuration.
|
|
283
|
+
|
|
203
284
|
2. **Legal tools**: a set of tools for the legal vertical, such as:
|
|
204
285
|
- `summarize_legal_text`: summarize legal text with a certain point of view
|
|
205
286
|
- `critique_as_judge`: critique a legal text as a judge, providing their perspective
|
|
@@ -217,10 +298,9 @@ print(response)
|
|
|
217
298
|
- `load_unique_values`: returns the top unique values for a given column
|
|
218
299
|
|
|
219
300
|
In addition, we include various other tools from LlamaIndex ToolSpecs:
|
|
220
|
-
* Tavily search
|
|
221
|
-
* EXA.AI
|
|
301
|
+
* Tavily search and EXA.AI
|
|
222
302
|
* arxiv
|
|
223
|
-
* neo4j & Kuzu for Graph integration
|
|
303
|
+
* neo4j & Kuzu for Graph DB integration
|
|
224
304
|
* Google tools (including gmail, calendar, and search)
|
|
225
305
|
* Slack
|
|
226
306
|
|
|
@@ -237,19 +317,44 @@ mult_tool = ToolsFactory().create_tool(mult_func)
|
|
|
237
317
|
|
|
238
318
|
## 🛠️ Configuration
|
|
239
319
|
|
|
320
|
+
## Configuring Vectara-agentic
|
|
321
|
+
|
|
240
322
|
The main way to control the behavior of `vectara-agentic` is by passing an `AgentConfig` object to your `Agent` when creating it.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
323
|
+
For example:
|
|
324
|
+
|
|
325
|
+
```python
|
|
326
|
+
agent_config = AgentConfig(
|
|
327
|
+
agent_type = AgentType.REACT,
|
|
328
|
+
main_llm_provider = ModelProvider.ANTHROPIC,
|
|
329
|
+
main_llm_model_name = 'claude-3-5-sonnet-20241022',
|
|
330
|
+
tool_llm_provider = ModelProvider.TOGETHER,
|
|
331
|
+
tool_llm_model_name = 'meta-llama/Llama-3.3-70B-Instruct-Turbo'
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
agent = Agent(
|
|
335
|
+
tools=[query_financial_reports_tool],
|
|
336
|
+
topic="10-K financial reports",
|
|
337
|
+
custom_instructions="You are a helpful financial assistant in conversation with a user.",
|
|
338
|
+
agent_config=agent_config
|
|
339
|
+
)
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
The `AgentConfig` object may include the following items:
|
|
343
|
+
- `agent_type`: the agent type. Valid values are `REACT`, `LLMCOMPILER`, `LATS` or `OPENAI` (default: `OPENAI`).
|
|
344
|
+
- `main_llm_provider` and `tool_llm_provider`: the LLM provider for main agent and for the tools. Valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `BEDROCK`, `GEMINI` or `FIREWORKS` (default: `OPENAI`).
|
|
345
|
+
- `main_llm_model_name` and `tool_llm_model_name`: agent model name for agent and tools (default depends on provider).
|
|
346
|
+
- `observer`: the observer type; should be `ARIZE_PHOENIX` or if undefined no observation framework will be used.
|
|
347
|
+
- `endpoint_api_key`: a secret key if using the API endpoint option (defaults to `dev-api-key`)
|
|
249
348
|
|
|
250
349
|
If any of these are not provided, `AgentConfig` first tries to read the values from the OS environment.
|
|
251
350
|
|
|
252
|
-
|
|
351
|
+
## Configuring Vectara RAG or search tools
|
|
352
|
+
|
|
353
|
+
When creating a `VectaraToolFactory`, you can pass in a `vectara_api_key`, `vectara_customer_id`, and `vectara_corpus_id` to the factory.
|
|
354
|
+
|
|
355
|
+
If not passed in, it will be taken from the environment variables (`VECTARA_API_KEY`, `VECTARA_CUSTOMER_ID` and `VECTARA_CORPUS_ID`). Note that `VECTARA_CORPUS_ID` can be a single ID or a comma-separated list of IDs (if you want to query multiple corpora).
|
|
356
|
+
|
|
357
|
+
These values will be used as credentials when creating Vectara tools - in `create_rag_tool()` and `create_search_tool()`.
|
|
253
358
|
|
|
254
359
|
## ℹ️ Additional Information
|
|
255
360
|
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
## ✨ Overview
|
|
22
22
|
|
|
23
|
-
`vectara-agentic` is a Python library for developing powerful AI assistants and agents using Vectara and Agentic-RAG. It leverages the LlamaIndex Agent framework
|
|
23
|
+
`vectara-agentic` is a Python library for developing powerful AI assistants and agents using Vectara and Agentic-RAG. It leverages the LlamaIndex Agent framework and provides helper functions to quickly create tools that connect to Vectara corpora.
|
|
24
24
|
|
|
25
25
|
<p align="center">
|
|
26
26
|
<img src="https://raw.githubusercontent.com/vectara/py-vectara-agentic/main/.github/assets/diagram1.png" alt="Agentic RAG diagram" width="100%" style="vertical-align: middle;">
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
### Features
|
|
30
30
|
|
|
31
31
|
- Enables easy creation of custom AI assistants and agents.
|
|
32
|
-
- Create a Vectara RAG tool with a single line of code.
|
|
33
|
-
- Supports `ReAct`, `OpenAIAgent`, `LATS
|
|
32
|
+
- Create a Vectara RAG tool or search tool with a single line of code.
|
|
33
|
+
- Supports `ReAct`, `OpenAIAgent`, `LATS` and `LLMCompiler` agent types.
|
|
34
34
|
- Includes pre-built tools for various domains (e.g., finance, legal).
|
|
35
|
-
- Integrates with various LLM inference services like OpenAI, Anthropic, Gemini, GROQ, Together.AI, Cohere and Fireworks
|
|
35
|
+
- Integrates with various LLM inference services like OpenAI, Anthropic, Gemini, GROQ, Together.AI, Cohere, Bedrock and Fireworks
|
|
36
36
|
- Built-in support for observability with Arize Phoenix
|
|
37
37
|
|
|
38
38
|
### 📚 Example AI Assistants
|
|
@@ -42,14 +42,14 @@ Check out our example AI assistants:
|
|
|
42
42
|
- [Financial Assistant](https://huggingface.co/spaces/vectara/finance-chat)
|
|
43
43
|
- [Justice Harvard Teaching Assistant](https://huggingface.co/spaces/vectara/Justice-Harvard)
|
|
44
44
|
- [Legal Assistant](https://huggingface.co/spaces/vectara/legal-agent)
|
|
45
|
-
|
|
45
|
+
- [EV Assistant](https://huggingface.co/spaces/vectara/ev-assistant)
|
|
46
46
|
|
|
47
47
|
### Prerequisites
|
|
48
48
|
|
|
49
49
|
- [Vectara account](https://console.vectara.com/signup/?utm_source=github&utm_medium=code&utm_term=DevRel&utm_content=vectara-agentic&utm_campaign=github-code-DevRel-vectara-agentic)
|
|
50
50
|
- A Vectara corpus with an [API key](https://docs.vectara.com/docs/api-keys)
|
|
51
51
|
- [Python 3.10 or higher](https://www.python.org/downloads/)
|
|
52
|
-
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Cohere, GEMINI or GROQ, if you choose to use them)
|
|
52
|
+
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Bedrock, Cohere, GEMINI or GROQ, if you choose to use them)
|
|
53
53
|
|
|
54
54
|
### Installation
|
|
55
55
|
|
|
@@ -59,18 +59,25 @@ pip install vectara-agentic
|
|
|
59
59
|
|
|
60
60
|
## 🚀 Quick Start
|
|
61
61
|
|
|
62
|
-
### 1.
|
|
62
|
+
### 1. Initialize the Vectara tool factory
|
|
63
63
|
|
|
64
64
|
```python
|
|
65
65
|
import os
|
|
66
66
|
from vectara_agentic.tools import VectaraToolFactory
|
|
67
|
-
from pydantic import BaseModel, Field
|
|
68
67
|
|
|
69
68
|
vec_factory = VectaraToolFactory(
|
|
70
69
|
vectara_api_key=os.environ['VECTARA_API_KEY'],
|
|
71
70
|
vectara_customer_id=os.environ['VECTARA_CUSTOMER_ID'],
|
|
72
71
|
vectara_corpus_id=os.environ['VECTARA_CORPUS_ID']
|
|
73
72
|
)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 2. Create a Vectara RAG Tool
|
|
76
|
+
|
|
77
|
+
A RAG tool calls the full Vectara RAG pipeline to provide summarized responses to queries grounded in data.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from pydantic import BaseModel, Field
|
|
74
81
|
|
|
75
82
|
years = list(range(2020, 2024))
|
|
76
83
|
tickers = {
|
|
@@ -89,17 +96,22 @@ query_financial_reports_tool = vec_factory.create_rag_tool(
|
|
|
89
96
|
tool_name="query_financial_reports",
|
|
90
97
|
tool_description="Query financial reports for a company and year",
|
|
91
98
|
tool_args_schema=QueryFinancialReportsArgs,
|
|
99
|
+
lambda_val=0.005,
|
|
100
|
+
summary_num_results=7,
|
|
101
|
+
# Additional arguments
|
|
92
102
|
)
|
|
93
103
|
```
|
|
94
104
|
|
|
95
|
-
|
|
105
|
+
See the [docs](https://vectara.github.io/vectara-agentic-docs/) for additional arguments to customize your Vectara RAG tool.
|
|
106
|
+
|
|
107
|
+
### 3. Create other tools (optional)
|
|
96
108
|
|
|
97
109
|
In addition to RAG tools, you can generate a lot of other types of tools the agent can use. These could be mathematical tools, tools
|
|
98
110
|
that call other APIs to get more information, or any other type of tool.
|
|
99
111
|
|
|
100
112
|
See [Agent Tools](#agent-tools) for more information.
|
|
101
113
|
|
|
102
|
-
###
|
|
114
|
+
### 4. Create your agent
|
|
103
115
|
|
|
104
116
|
```python
|
|
105
117
|
from vectara_agentic import Agent
|
|
@@ -119,20 +131,89 @@ agent = Agent(
|
|
|
119
131
|
)
|
|
120
132
|
```
|
|
121
133
|
|
|
122
|
-
|
|
134
|
+
See the [docs](https://vectara.github.io/vectara-agentic-docs/) for additional arguments, including `agent_progress_callback` and `query_logging_callback`.
|
|
135
|
+
|
|
136
|
+
### 5. Run your agent
|
|
123
137
|
|
|
124
138
|
```python
|
|
125
|
-
|
|
126
|
-
print(response)
|
|
139
|
+
res = agent.chat("What was the revenue for Apple in 2021?")
|
|
140
|
+
print(res.response)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Note that:
|
|
144
|
+
1. `vectara-agentic` also supports `achat()` and two streaming variants `stream_chat()` and `astream_chat()`.
|
|
145
|
+
2. The response types from `chat()` and `achat()` are of type `AgentResponse`. If you just need the actual string
|
|
146
|
+
response it's available as the `response` variable, or just use `str()`. For advanced use-cases you can look
|
|
147
|
+
at other `AgentResponse` variables [such as `sources`](https://github.com/run-llama/llama_index/blob/659f9faaafbecebb6e6c65f42143c0bf19274a37/llama-index-core/llama_index/core/chat_engine/types.py#L53).
|
|
148
|
+
|
|
149
|
+
## 🧰 Vectara tools
|
|
150
|
+
|
|
151
|
+
`vectara-agentic` provides two helper functions to connect with Vectara RAG
|
|
152
|
+
* `create_rag_tool()` to create an agent tool that connects with a Vectara corpus for querying.
|
|
153
|
+
* `create_search_tool()` to create a tool to search a Vectara corpus and return a list of matching documents.
|
|
154
|
+
|
|
155
|
+
See the documentation for the full list of arguments for `create_rag_tool()` and `create_search_tool()`,
|
|
156
|
+
to understand how to configure Vectara query performed by those tools.
|
|
157
|
+
|
|
158
|
+
### Creating a Vectara RAG tool
|
|
159
|
+
|
|
160
|
+
A Vectara RAG tool is often the main workhorse for any Agentic RAG application, and enables the agent to query
|
|
161
|
+
one or more Vectara RAG corpora.
|
|
162
|
+
|
|
163
|
+
The tool generated always includes the `query` argument, followed by 1 or more optional arguments used for
|
|
164
|
+
metadata filtering, defined by `tool_args_schema`.
|
|
165
|
+
|
|
166
|
+
For example, in the quickstart example the schema is:
|
|
167
|
+
|
|
127
168
|
```
|
|
169
|
+
class QueryFinancialReportsArgs(BaseModel):
|
|
170
|
+
query: str = Field(..., description="The user query.")
|
|
171
|
+
year: int | str = Field(..., description=f"The year this query relates to. An integer between {min(years)} and {max(years)} or a string specifying a condition on the year (example: '>2020').")
|
|
172
|
+
ticker: str = Field(..., description=f"The company ticker. Must be a valid ticket symbol from the list {tickers.keys()}.")
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The `query` is required and is always the query string.
|
|
176
|
+
The other arguments are optional and will be interpreted as Vectara metadata filters.
|
|
128
177
|
|
|
129
|
-
|
|
178
|
+
For example, in the example above, the agent may call the `query_financial_reports_tool` tool with
|
|
179
|
+
query='what is the revenue?', year=2022 and ticker='AAPL'. Subsequently the RAG tool will issue
|
|
180
|
+
a Vectara RAG query with the same query, but with metadata filtering (doc.year=2022 and doc.ticker='AAPL').
|
|
181
|
+
|
|
182
|
+
There are also additional cool features supported here:
|
|
183
|
+
* An argument can be a condition, for example year='>2022' translates to the correct metadata
|
|
184
|
+
filtering condition doc.year>2022
|
|
185
|
+
* if `fixed_filter` is defined in the RAG tool, it provides a constant metadata filtering that is always applied.
|
|
186
|
+
For example, if fixed_filter=`doc.filing_type='10K'` then a query with query='what is the reveue', year=2022
|
|
187
|
+
and ticker='AAPL' would translate into query='what is the revenue' with metadata filtering condition of
|
|
188
|
+
"doc.year=2022 AND doc.ticker='AAPL' and doc.filing_type='10K'"
|
|
189
|
+
|
|
190
|
+
Note that `tool_args_type` is an optional dictionary that indicates the level at which metadata filtering
|
|
191
|
+
is applied for each argument (`doc` or `part`)
|
|
192
|
+
|
|
193
|
+
### Creating a Vectara search tool
|
|
194
|
+
|
|
195
|
+
The Vectara search tool allows the agent to list documents that match a query.
|
|
196
|
+
This can be helpful to the agent to answer queries like "how many documents discuss the iPhone?" or other
|
|
197
|
+
similar queries that require a response in terms of a list of matching documents.
|
|
198
|
+
|
|
199
|
+
## 🛠️ Agent Tools at a Glance
|
|
200
|
+
|
|
201
|
+
`vectara-agentic` provides a few tools out of the box (see ToolsCatalog for details):
|
|
130
202
|
|
|
131
|
-
`vectara-agentic` provides a few tools out of the box:
|
|
132
203
|
1. **Standard tools**:
|
|
133
204
|
- `summarize_text`: a tool to summarize a long text into a shorter summary (uses LLM)
|
|
134
205
|
- `rephrase_text`: a tool to rephrase a given text, given a set of rephrase instructions (uses LLM)
|
|
135
|
-
|
|
206
|
+
These tools use an LLM and so would use the `Tools` LLM specified in your `AgentConfig`.
|
|
207
|
+
To instantiate them:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from vectara_agentic.tools_catalog import ToolsCatalog
|
|
211
|
+
summarize_text = ToolsCatalog(agent_config).summarize_text
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
This ensures the summarize_text tool is configured with the proper LLM provider and model as
|
|
215
|
+
specified in the Agent configuration.
|
|
216
|
+
|
|
136
217
|
2. **Legal tools**: a set of tools for the legal vertical, such as:
|
|
137
218
|
- `summarize_legal_text`: summarize legal text with a certain point of view
|
|
138
219
|
- `critique_as_judge`: critique a legal text as a judge, providing their perspective
|
|
@@ -150,10 +231,9 @@ print(response)
|
|
|
150
231
|
- `load_unique_values`: returns the top unique values for a given column
|
|
151
232
|
|
|
152
233
|
In addition, we include various other tools from LlamaIndex ToolSpecs:
|
|
153
|
-
* Tavily search
|
|
154
|
-
* EXA.AI
|
|
234
|
+
* Tavily search and EXA.AI
|
|
155
235
|
* arxiv
|
|
156
|
-
* neo4j & Kuzu for Graph integration
|
|
236
|
+
* neo4j & Kuzu for Graph DB integration
|
|
157
237
|
* Google tools (including gmail, calendar, and search)
|
|
158
238
|
* Slack
|
|
159
239
|
|
|
@@ -170,19 +250,44 @@ mult_tool = ToolsFactory().create_tool(mult_func)
|
|
|
170
250
|
|
|
171
251
|
## 🛠️ Configuration
|
|
172
252
|
|
|
253
|
+
## Configuring Vectara-agentic
|
|
254
|
+
|
|
173
255
|
The main way to control the behavior of `vectara-agentic` is by passing an `AgentConfig` object to your `Agent` when creating it.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
256
|
+
For example:
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
agent_config = AgentConfig(
|
|
260
|
+
agent_type = AgentType.REACT,
|
|
261
|
+
main_llm_provider = ModelProvider.ANTHROPIC,
|
|
262
|
+
main_llm_model_name = 'claude-3-5-sonnet-20241022',
|
|
263
|
+
tool_llm_provider = ModelProvider.TOGETHER,
|
|
264
|
+
tool_llm_model_name = 'meta-llama/Llama-3.3-70B-Instruct-Turbo'
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
agent = Agent(
|
|
268
|
+
tools=[query_financial_reports_tool],
|
|
269
|
+
topic="10-K financial reports",
|
|
270
|
+
custom_instructions="You are a helpful financial assistant in conversation with a user.",
|
|
271
|
+
agent_config=agent_config
|
|
272
|
+
)
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
The `AgentConfig` object may include the following items:
|
|
276
|
+
- `agent_type`: the agent type. Valid values are `REACT`, `LLMCOMPILER`, `LATS` or `OPENAI` (default: `OPENAI`).
|
|
277
|
+
- `main_llm_provider` and `tool_llm_provider`: the LLM provider for main agent and for the tools. Valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `BEDROCK`, `GEMINI` or `FIREWORKS` (default: `OPENAI`).
|
|
278
|
+
- `main_llm_model_name` and `tool_llm_model_name`: agent model name for agent and tools (default depends on provider).
|
|
279
|
+
- `observer`: the observer type; should be `ARIZE_PHOENIX` or if undefined no observation framework will be used.
|
|
280
|
+
- `endpoint_api_key`: a secret key if using the API endpoint option (defaults to `dev-api-key`)
|
|
182
281
|
|
|
183
282
|
If any of these are not provided, `AgentConfig` first tries to read the values from the OS environment.
|
|
184
283
|
|
|
185
|
-
|
|
284
|
+
## Configuring Vectara RAG or search tools
|
|
285
|
+
|
|
286
|
+
When creating a `VectaraToolFactory`, you can pass in a `vectara_api_key`, `vectara_customer_id`, and `vectara_corpus_id` to the factory.
|
|
287
|
+
|
|
288
|
+
If not passed in, it will be taken from the environment variables (`VECTARA_API_KEY`, `VECTARA_CUSTOMER_ID` and `VECTARA_CORPUS_ID`). Note that `VECTARA_CORPUS_ID` can be a single ID or a comma-separated list of IDs (if you want to query multiple corpora).
|
|
289
|
+
|
|
290
|
+
These values will be used as credentials when creating Vectara tools - in `create_rag_tool()` and `create_search_tool()`.
|
|
186
291
|
|
|
187
292
|
## ℹ️ Additional Information
|
|
188
293
|
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
llama-index==0.12.
|
|
1
|
+
llama-index==0.12.11
|
|
2
2
|
llama-index-indices-managed-vectara==0.3.1
|
|
3
3
|
llama-index-agent-llm-compiler==0.3.0
|
|
4
4
|
llama-index-agent-lats==0.3.0
|
|
5
|
-
llama-index-agent-openai==0.4.
|
|
6
|
-
llama-index-llms-openai==0.3.
|
|
7
|
-
llama-index-llms-anthropic==0.6.
|
|
5
|
+
llama-index-agent-openai==0.4.3
|
|
6
|
+
llama-index-llms-openai==0.3.18
|
|
7
|
+
llama-index-llms-anthropic==0.6.4
|
|
8
8
|
llama-index-llms-together==0.3.1
|
|
9
9
|
llama-index-llms-groq==0.3.1
|
|
10
|
-
llama-index-llms-fireworks==0.3.
|
|
10
|
+
llama-index-llms-fireworks==0.3.1
|
|
11
11
|
llama-index-llms-cohere==0.4.0
|
|
12
|
-
llama-index-llms-gemini==0.4.
|
|
12
|
+
llama-index-llms-gemini==0.4.4
|
|
13
|
+
llama-index-llms-bedrock==0.3.3
|
|
13
14
|
llama-index-tools-yahoo-finance==0.3.0
|
|
14
15
|
llama-index-tools-arxiv==0.3.0
|
|
15
16
|
llama-index-tools-database==0.3.0
|
|
16
17
|
llama-index-tools-google==0.3.0
|
|
17
18
|
llama-index-tools-tavily_research==0.3.0
|
|
18
19
|
llama-index-tools-neo4j==0.3.0
|
|
19
|
-
llama-index-graph-stores-kuzu==0.
|
|
20
|
+
llama-index-graph-stores-kuzu==0.6.0
|
|
20
21
|
llama-index-tools-slack==0.3.0
|
|
21
22
|
llama-index-tools-exa==0.3.0
|
|
22
23
|
tavily-python==0.5.0
|
|
23
|
-
exa-py==1.
|
|
24
|
+
exa-py==1.8.5
|
|
24
25
|
yahoo-finance==1.4.0
|
|
25
|
-
openinference-instrumentation-llama-index==3.
|
|
26
|
+
openinference-instrumentation-llama-index==3.1.4
|
|
26
27
|
opentelemetry-proto==1.26.0
|
|
27
|
-
arize-phoenix==
|
|
28
|
+
arize-phoenix==7.11.0
|
|
28
29
|
arize-phoenix-otel==0.6.1
|
|
29
30
|
protobuf==4.25.5
|
|
30
31
|
tokenizers>=0.20
|
|
31
|
-
pydantic==2.
|
|
32
|
+
pydantic==2.10.3
|
|
32
33
|
retrying==1.3.4
|
|
33
|
-
pymongo==4.10.1
|
|
34
34
|
python-dotenv==1.0.1
|
|
35
35
|
tiktoken==0.8.0
|
|
36
36
|
dill>=0.3.7
|
|
@@ -7,3 +7,10 @@ from .tools import VectaraToolFactory, VectaraTool
|
|
|
7
7
|
|
|
8
8
|
# Define the __all__ variable for wildcard imports
|
|
9
9
|
__all__ = ['Agent', 'VectaraToolFactory', 'VectaraTool']
|
|
10
|
+
|
|
11
|
+
# Ensure package version is available
|
|
12
|
+
try:
|
|
13
|
+
import importlib.metadata
|
|
14
|
+
__version__ = importlib.metadata.version("vectara_agentic")
|
|
15
|
+
except Exception:
|
|
16
|
+
__version__ = "0.0.0" # fallback if not installed
|
|
@@ -5,6 +5,7 @@ This file contains the prompt templates for the different types of agents.
|
|
|
5
5
|
# General (shared) instructions
|
|
6
6
|
GENERAL_INSTRUCTIONS = """
|
|
7
7
|
- Use tools as your main source of information, do not respond without using a tool. Do not respond based on pre-trained knowledge.
|
|
8
|
+
- Always call the 'get_current_date' tool to ensure you know the exact date when a user asks a question.
|
|
8
9
|
- When using a tool with arguments, simplify the query as much as possible if you use the tool with arguments.
|
|
9
10
|
For example, if the original query is "revenue for apple in 2021", you can use the tool with a query "revenue" with arguments year=2021 and company=apple.
|
|
10
11
|
- If a tool responds with "I do not have enough information", try one of the following:
|
|
@@ -43,7 +44,7 @@ GENERAL_PROMPT_TEMPLATE = """
|
|
|
43
44
|
You are a helpful chatbot in conversation with a user, with expertise in {chat_topic}.
|
|
44
45
|
|
|
45
46
|
## Date
|
|
46
|
-
|
|
47
|
+
Your birth date is {today}.
|
|
47
48
|
|
|
48
49
|
## INSTRUCTIONS:
|
|
49
50
|
IMPORTANT - FOLLOW THESE INSTRUCTIONS CAREFULLY:
|
|
@@ -63,7 +64,7 @@ You are designed to help with a variety of tasks, from answering questions to pr
|
|
|
63
64
|
You have expertise in {chat_topic}.
|
|
64
65
|
|
|
65
66
|
## Date
|
|
66
|
-
|
|
67
|
+
Your birth date is {today}.
|
|
67
68
|
|
|
68
69
|
## Tools
|
|
69
70
|
You have access to a wide variety of tools.
|