vectara-agentic 0.1.23__tar.gz → 0.1.25__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.
- {vectara_agentic-0.1.23/vectara_agentic.egg-info → vectara_agentic-0.1.25}/PKG-INFO +122 -38
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/README.md +96 -23
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/requirements.txt +12 -12
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/setup.py +10 -3
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/tests/test_agent.py +44 -1
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/tests/test_tools.py +3 -3
- vectara_agentic-0.1.25/vectara_agentic/__init__.py +16 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/_observability.py +3 -3
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/_prompts.py +5 -3
- vectara_agentic-0.1.25/vectara_agentic/_version.py +4 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/agent.py +126 -40
- vectara_agentic-0.1.25/vectara_agentic/agent_config.py +86 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/agent_endpoint.py +6 -7
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/tools.py +275 -61
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/tools_catalog.py +8 -1
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/types.py +10 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/utils.py +50 -34
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25/vectara_agentic.egg-info}/PKG-INFO +122 -38
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic.egg-info/SOURCES.txt +2 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic.egg-info/requires.txt +12 -12
- vectara_agentic-0.1.23/vectara_agentic/__init__.py +0 -23
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/LICENSE +0 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/MANIFEST.in +0 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/setup.cfg +0 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/tests/__init__.py +0 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/_callback.py +0 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic/db_tools.py +0 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic.egg-info/dependency_links.txt +0 -0
- {vectara_agentic-0.1.23 → vectara_agentic-0.1.25}/vectara_agentic.egg-info/top_level.txt +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: vectara_agentic
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.25
|
|
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
|
|
7
7
|
Author-email: ofer@vectara.com
|
|
8
8
|
Project-URL: Documentation, https://vectara.github.io/vectara-agentic-docs/
|
|
9
|
-
Keywords: LLM,NLP,RAG,Agentic-RAG
|
|
9
|
+
Keywords: LLM,NLP,RAG,Agentic-RAG,AI assistant,AI Agent,Vectara
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
11
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
@@ -16,43 +16,54 @@ 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.16
|
|
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
|
|
55
55
|
Requires-Dist: httpx==0.27.2
|
|
56
|
+
Dynamic: author
|
|
57
|
+
Dynamic: author-email
|
|
58
|
+
Dynamic: classifier
|
|
59
|
+
Dynamic: description
|
|
60
|
+
Dynamic: description-content-type
|
|
61
|
+
Dynamic: home-page
|
|
62
|
+
Dynamic: keywords
|
|
63
|
+
Dynamic: project-url
|
|
64
|
+
Dynamic: requires-dist
|
|
65
|
+
Dynamic: requires-python
|
|
66
|
+
Dynamic: summary
|
|
56
67
|
|
|
57
68
|
# <img src="https://raw.githubusercontent.com/vectara/py-vectara-agentic/main/.github/assets/Vectara-logo.png" alt="Vectara Logo" width="30" height="30" style="vertical-align: middle;"> vectara-agentic
|
|
58
69
|
|
|
@@ -76,7 +87,7 @@ Requires-Dist: httpx==0.27.2
|
|
|
76
87
|
|
|
77
88
|
## ✨ Overview
|
|
78
89
|
|
|
79
|
-
`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.
|
|
80
91
|
|
|
81
92
|
<p align="center">
|
|
82
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;">
|
|
@@ -85,10 +96,10 @@ Requires-Dist: httpx==0.27.2
|
|
|
85
96
|
### Features
|
|
86
97
|
|
|
87
98
|
- Enables easy creation of custom AI assistants and agents.
|
|
88
|
-
- Create a Vectara RAG tool with a single line of code.
|
|
89
|
-
- 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.
|
|
90
101
|
- Includes pre-built tools for various domains (e.g., finance, legal).
|
|
91
|
-
- 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
|
|
92
103
|
- Built-in support for observability with Arize Phoenix
|
|
93
104
|
|
|
94
105
|
### 📚 Example AI Assistants
|
|
@@ -98,14 +109,14 @@ Check out our example AI assistants:
|
|
|
98
109
|
- [Financial Assistant](https://huggingface.co/spaces/vectara/finance-chat)
|
|
99
110
|
- [Justice Harvard Teaching Assistant](https://huggingface.co/spaces/vectara/Justice-Harvard)
|
|
100
111
|
- [Legal Assistant](https://huggingface.co/spaces/vectara/legal-agent)
|
|
101
|
-
|
|
112
|
+
- [EV Assistant](https://huggingface.co/spaces/vectara/ev-assistant)
|
|
102
113
|
|
|
103
114
|
### Prerequisites
|
|
104
115
|
|
|
105
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)
|
|
106
117
|
- A Vectara corpus with an [API key](https://docs.vectara.com/docs/api-keys)
|
|
107
118
|
- [Python 3.10 or higher](https://www.python.org/downloads/)
|
|
108
|
-
- 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)
|
|
109
120
|
|
|
110
121
|
### Installation
|
|
111
122
|
|
|
@@ -115,18 +126,25 @@ pip install vectara-agentic
|
|
|
115
126
|
|
|
116
127
|
## 🚀 Quick Start
|
|
117
128
|
|
|
118
|
-
### 1.
|
|
129
|
+
### 1. Initialize the Vectara tool factory
|
|
119
130
|
|
|
120
131
|
```python
|
|
121
132
|
import os
|
|
122
133
|
from vectara_agentic.tools import VectaraToolFactory
|
|
123
|
-
from pydantic import BaseModel, Field
|
|
124
134
|
|
|
125
135
|
vec_factory = VectaraToolFactory(
|
|
126
136
|
vectara_api_key=os.environ['VECTARA_API_KEY'],
|
|
127
137
|
vectara_customer_id=os.environ['VECTARA_CUSTOMER_ID'],
|
|
128
138
|
vectara_corpus_id=os.environ['VECTARA_CORPUS_ID']
|
|
129
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
|
|
130
148
|
|
|
131
149
|
years = list(range(2020, 2024))
|
|
132
150
|
tickers = {
|
|
@@ -145,17 +163,22 @@ query_financial_reports_tool = vec_factory.create_rag_tool(
|
|
|
145
163
|
tool_name="query_financial_reports",
|
|
146
164
|
tool_description="Query financial reports for a company and year",
|
|
147
165
|
tool_args_schema=QueryFinancialReportsArgs,
|
|
166
|
+
lambda_val=0.005,
|
|
167
|
+
summary_num_results=7,
|
|
168
|
+
# Additional arguments
|
|
148
169
|
)
|
|
149
170
|
```
|
|
150
171
|
|
|
151
|
-
|
|
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)
|
|
152
175
|
|
|
153
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
|
|
154
177
|
that call other APIs to get more information, or any other type of tool.
|
|
155
178
|
|
|
156
179
|
See [Agent Tools](#agent-tools) for more information.
|
|
157
180
|
|
|
158
|
-
###
|
|
181
|
+
### 4. Create your agent
|
|
159
182
|
|
|
160
183
|
```python
|
|
161
184
|
from vectara_agentic import Agent
|
|
@@ -175,14 +198,72 @@ agent = Agent(
|
|
|
175
198
|
)
|
|
176
199
|
```
|
|
177
200
|
|
|
178
|
-
|
|
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
|
|
179
204
|
|
|
180
205
|
```python
|
|
181
|
-
|
|
182
|
-
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
|
+
|
|
183
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.
|
|
184
244
|
|
|
185
|
-
|
|
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
|
|
186
267
|
|
|
187
268
|
`vectara-agentic` provides a few tools out of the box:
|
|
188
269
|
1. **Standard tools**:
|
|
@@ -206,10 +287,9 @@ print(response)
|
|
|
206
287
|
- `load_unique_values`: returns the top unique values for a given column
|
|
207
288
|
|
|
208
289
|
In addition, we include various other tools from LlamaIndex ToolSpecs:
|
|
209
|
-
* Tavily search
|
|
210
|
-
* EXA.AI
|
|
290
|
+
* Tavily search and EXA.AI
|
|
211
291
|
* arxiv
|
|
212
|
-
* neo4j & Kuzu for Graph integration
|
|
292
|
+
* neo4j & Kuzu for Graph DB integration
|
|
213
293
|
* Google tools (including gmail, calendar, and search)
|
|
214
294
|
* Slack
|
|
215
295
|
|
|
@@ -226,16 +306,19 @@ mult_tool = ToolsFactory().create_tool(mult_func)
|
|
|
226
306
|
|
|
227
307
|
## 🛠️ Configuration
|
|
228
308
|
|
|
229
|
-
|
|
230
|
-
|
|
309
|
+
The main way to control the behavior of `vectara-agentic` is by passing an `AgentConfig` object to your `Agent` when creating it.
|
|
310
|
+
This object will include the following items:
|
|
231
311
|
- `VECTARA_AGENTIC_AGENT_TYPE`: valid values are `REACT`, `LLMCOMPILER`, `LATS` or `OPENAI` (default: `OPENAI`)
|
|
232
|
-
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `GEMINI` or `FIREWORKS` (default: `OPENAI`)
|
|
312
|
+
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `BEDROCK`, `GEMINI` or `FIREWORKS` (default: `OPENAI`)
|
|
233
313
|
- `VECTARA_AGENTIC_MAIN_MODEL_NAME`: agent model name (default depends on provider)
|
|
234
314
|
- `VECTARA_AGENTIC_TOOL_LLM_PROVIDER`: tool LLM provider (default: `OPENAI`)
|
|
235
315
|
- `VECTARA_AGENTIC_TOOL_MODEL_NAME`: tool model name (default depends on provider)
|
|
236
316
|
- `VECTARA_AGENTIC_OBSERVER_TYPE`: valid values are `ARIZE_PHOENIX` or `NONE` (default: `NONE`)
|
|
317
|
+
- `VECTARA_AGENTIC_API_KEY`: a secret key if using the API endpoint option (defaults to `dev-api-key`)
|
|
237
318
|
|
|
238
|
-
|
|
319
|
+
If any of these are not provided, `AgentConfig` first tries to read the values from the OS environment.
|
|
320
|
+
|
|
321
|
+
When creating a `VectaraToolFactory`, you can pass in a `vectara_api_key`, `vectara_customer_id`, and `vectara_corpus_id` to the factory. 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).
|
|
239
322
|
|
|
240
323
|
## ℹ️ Additional Information
|
|
241
324
|
|
|
@@ -260,7 +343,8 @@ The `Agent` class supports serialization. Use the `dumps()` to serialize and `lo
|
|
|
260
343
|
### Observability
|
|
261
344
|
|
|
262
345
|
vectara-agentic supports observability via the existing integration of LlamaIndex and Arize Phoenix.
|
|
263
|
-
First, set `
|
|
346
|
+
First, set `VECTARA_AGENTIC_OBSERVER_TYPE` to `ARIZE_PHOENIX` in `AgentConfig` (or env variable).
|
|
347
|
+
|
|
264
348
|
Then you can use Arize Phoenix in three ways:
|
|
265
349
|
1. **Locally**.
|
|
266
350
|
1. If you have a local phoenix server that you've run using e.g. `python -m phoenix.server.main serve`, vectara-agentic will send all traces to it.
|
|
@@ -268,7 +352,7 @@ Then you can use Arize Phoenix in three ways:
|
|
|
268
352
|
3. In both cases, traces will be sent to the local instance, and you can see the dashboard at `http://localhost:6006`
|
|
269
353
|
2. **Hosted Instance**. In this case the traces are sent to the Phoenix instances hosted on Arize.
|
|
270
354
|
1. Go to `https://app.phoenix.arize.com`, setup an account if you don't have one.
|
|
271
|
-
2. create an API key and put it in the `PHOENIX_API_KEY` variable
|
|
355
|
+
2. create an API key and put it in the `PHOENIX_API_KEY` environment variable - this indicates you want to use the hosted version.
|
|
272
356
|
3. To view the traces go to `https://app.phoenix.arize.com`.
|
|
273
357
|
|
|
274
358
|
Now when you run your agent, all call traces are sent to Phoenix and recorded.
|
|
@@ -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,14 +131,72 @@ 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
|
|
130
200
|
|
|
131
201
|
`vectara-agentic` provides a few tools out of the box:
|
|
132
202
|
1. **Standard tools**:
|
|
@@ -150,10 +220,9 @@ print(response)
|
|
|
150
220
|
- `load_unique_values`: returns the top unique values for a given column
|
|
151
221
|
|
|
152
222
|
In addition, we include various other tools from LlamaIndex ToolSpecs:
|
|
153
|
-
* Tavily search
|
|
154
|
-
* EXA.AI
|
|
223
|
+
* Tavily search and EXA.AI
|
|
155
224
|
* arxiv
|
|
156
|
-
* neo4j & Kuzu for Graph integration
|
|
225
|
+
* neo4j & Kuzu for Graph DB integration
|
|
157
226
|
* Google tools (including gmail, calendar, and search)
|
|
158
227
|
* Slack
|
|
159
228
|
|
|
@@ -170,16 +239,19 @@ mult_tool = ToolsFactory().create_tool(mult_func)
|
|
|
170
239
|
|
|
171
240
|
## 🛠️ Configuration
|
|
172
241
|
|
|
173
|
-
|
|
174
|
-
|
|
242
|
+
The main way to control the behavior of `vectara-agentic` is by passing an `AgentConfig` object to your `Agent` when creating it.
|
|
243
|
+
This object will include the following items:
|
|
175
244
|
- `VECTARA_AGENTIC_AGENT_TYPE`: valid values are `REACT`, `LLMCOMPILER`, `LATS` or `OPENAI` (default: `OPENAI`)
|
|
176
|
-
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `GEMINI` or `FIREWORKS` (default: `OPENAI`)
|
|
245
|
+
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `BEDROCK`, `GEMINI` or `FIREWORKS` (default: `OPENAI`)
|
|
177
246
|
- `VECTARA_AGENTIC_MAIN_MODEL_NAME`: agent model name (default depends on provider)
|
|
178
247
|
- `VECTARA_AGENTIC_TOOL_LLM_PROVIDER`: tool LLM provider (default: `OPENAI`)
|
|
179
248
|
- `VECTARA_AGENTIC_TOOL_MODEL_NAME`: tool model name (default depends on provider)
|
|
180
249
|
- `VECTARA_AGENTIC_OBSERVER_TYPE`: valid values are `ARIZE_PHOENIX` or `NONE` (default: `NONE`)
|
|
250
|
+
- `VECTARA_AGENTIC_API_KEY`: a secret key if using the API endpoint option (defaults to `dev-api-key`)
|
|
181
251
|
|
|
182
|
-
|
|
252
|
+
If any of these are not provided, `AgentConfig` first tries to read the values from the OS environment.
|
|
253
|
+
|
|
254
|
+
When creating a `VectaraToolFactory`, you can pass in a `vectara_api_key`, `vectara_customer_id`, and `vectara_corpus_id` to the factory. 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).
|
|
183
255
|
|
|
184
256
|
## ℹ️ Additional Information
|
|
185
257
|
|
|
@@ -204,7 +276,8 @@ The `Agent` class supports serialization. Use the `dumps()` to serialize and `lo
|
|
|
204
276
|
### Observability
|
|
205
277
|
|
|
206
278
|
vectara-agentic supports observability via the existing integration of LlamaIndex and Arize Phoenix.
|
|
207
|
-
First, set `
|
|
279
|
+
First, set `VECTARA_AGENTIC_OBSERVER_TYPE` to `ARIZE_PHOENIX` in `AgentConfig` (or env variable).
|
|
280
|
+
|
|
208
281
|
Then you can use Arize Phoenix in three ways:
|
|
209
282
|
1. **Locally**.
|
|
210
283
|
1. If you have a local phoenix server that you've run using e.g. `python -m phoenix.server.main serve`, vectara-agentic will send all traces to it.
|
|
@@ -212,7 +285,7 @@ Then you can use Arize Phoenix in three ways:
|
|
|
212
285
|
3. In both cases, traces will be sent to the local instance, and you can see the dashboard at `http://localhost:6006`
|
|
213
286
|
2. **Hosted Instance**. In this case the traces are sent to the Phoenix instances hosted on Arize.
|
|
214
287
|
1. Go to `https://app.phoenix.arize.com`, setup an account if you don't have one.
|
|
215
|
-
2. create an API key and put it in the `PHOENIX_API_KEY` variable
|
|
288
|
+
2. create an API key and put it in the `PHOENIX_API_KEY` environment variable - this indicates you want to use the hosted version.
|
|
216
289
|
3. To view the traces go to `https://app.phoenix.arize.com`.
|
|
217
290
|
|
|
218
291
|
Now when you run your agent, all call traces are sent to Phoenix and recorded.
|
|
@@ -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.16
|
|
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
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
from setuptools import setup, find_packages
|
|
2
|
-
|
|
2
|
+
import os
|
|
3
|
+
import re
|
|
3
4
|
|
|
4
5
|
def read_requirements():
|
|
5
6
|
with open("requirements.txt") as req:
|
|
6
7
|
return req.read().splitlines()
|
|
7
8
|
|
|
9
|
+
def read_version():
|
|
10
|
+
version_file = os.path.join("vectara_agentic", "_version.py")
|
|
11
|
+
with open(version_file, "r") as vf:
|
|
12
|
+
content = vf.read()
|
|
13
|
+
return re.search(r'__version__\s*=\s*["\']([^"\']+)["\']', content).group(1)
|
|
14
|
+
|
|
8
15
|
|
|
9
16
|
setup(
|
|
10
17
|
name="vectara_agentic",
|
|
11
|
-
version=
|
|
18
|
+
version=read_version(),
|
|
12
19
|
author="Ofer Mendelevitch",
|
|
13
20
|
author_email="ofer@vectara.com",
|
|
14
21
|
description="A Python package for creating AI Assistants and AI Agents with Vectara",
|
|
@@ -25,7 +32,7 @@ setup(
|
|
|
25
32
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
26
33
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
34
|
],
|
|
28
|
-
keywords=["LLM", "NLP", "RAG", "Agentic-RAG"],
|
|
35
|
+
keywords=["LLM", "NLP", "RAG", "Agentic-RAG", "AI assistant", "AI Agent", "Vectara"],
|
|
29
36
|
project_urls={
|
|
30
37
|
"Documentation": "https://vectara.github.io/vectara-agentic-docs/",
|
|
31
38
|
},
|