vectara-agentic 0.1.24__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.24/vectara_agentic.egg-info → vectara_agentic-0.1.25}/PKG-INFO +100 -31
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/README.md +87 -18
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/requirements.txt +12 -12
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/__init__.py +7 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/_prompts.py +3 -2
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/_version.py +1 -1
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/agent.py +107 -28
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/agent_config.py +2 -2
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/tools.py +266 -113
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/tools_catalog.py +8 -1
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/types.py +10 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/utils.py +4 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25/vectara_agentic.egg-info}/PKG-INFO +100 -31
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic.egg-info/requires.txt +12 -12
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/LICENSE +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/MANIFEST.in +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/setup.cfg +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/setup.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/tests/__init__.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/tests/test_agent.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/tests/test_tools.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/_callback.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/_observability.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/agent_endpoint.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic/db_tools.py +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic.egg-info/SOURCES.txt +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/vectara_agentic.egg-info/dependency_links.txt +0 -0
- {vectara_agentic-0.1.24 → vectara_agentic-0.1.25}/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.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
|
|
@@ -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.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
|
|
@@ -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,14 +198,72 @@ 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)
|
|
194
208
|
```
|
|
195
209
|
|
|
196
|
-
|
|
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
|
+
|
|
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.
|
|
244
|
+
|
|
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
|
|
197
267
|
|
|
198
268
|
`vectara-agentic` provides a few tools out of the box:
|
|
199
269
|
1. **Standard tools**:
|
|
@@ -217,10 +287,9 @@ print(response)
|
|
|
217
287
|
- `load_unique_values`: returns the top unique values for a given column
|
|
218
288
|
|
|
219
289
|
In addition, we include various other tools from LlamaIndex ToolSpecs:
|
|
220
|
-
* Tavily search
|
|
221
|
-
* EXA.AI
|
|
290
|
+
* Tavily search and EXA.AI
|
|
222
291
|
* arxiv
|
|
223
|
-
* neo4j & Kuzu for Graph integration
|
|
292
|
+
* neo4j & Kuzu for Graph DB integration
|
|
224
293
|
* Google tools (including gmail, calendar, and search)
|
|
225
294
|
* Slack
|
|
226
295
|
|
|
@@ -240,7 +309,7 @@ mult_tool = ToolsFactory().create_tool(mult_func)
|
|
|
240
309
|
The main way to control the behavior of `vectara-agentic` is by passing an `AgentConfig` object to your `Agent` when creating it.
|
|
241
310
|
This object will include the following items:
|
|
242
311
|
- `VECTARA_AGENTIC_AGENT_TYPE`: valid values are `REACT`, `LLMCOMPILER`, `LATS` or `OPENAI` (default: `OPENAI`)
|
|
243
|
-
- `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`)
|
|
244
313
|
- `VECTARA_AGENTIC_MAIN_MODEL_NAME`: agent model name (default depends on provider)
|
|
245
314
|
- `VECTARA_AGENTIC_TOOL_LLM_PROVIDER`: tool LLM provider (default: `OPENAI`)
|
|
246
315
|
- `VECTARA_AGENTIC_TOOL_MODEL_NAME`: tool model name (default depends on provider)
|
|
@@ -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)
|
|
127
141
|
```
|
|
128
142
|
|
|
129
|
-
|
|
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
|
+
|
|
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.
|
|
177
|
+
|
|
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
|
|
|
@@ -173,7 +242,7 @@ mult_tool = ToolsFactory().create_tool(mult_func)
|
|
|
173
242
|
The main way to control the behavior of `vectara-agentic` is by passing an `AgentConfig` object to your `Agent` when creating it.
|
|
174
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)
|
|
@@ -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
|
|
@@ -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.
|