vectara-agentic 0.1.12__tar.gz → 0.1.14__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.12/vectara_agentic.egg-info → vectara_agentic-0.1.14}/PKG-INFO +88 -76
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/README.md +85 -76
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/requirements.txt +4 -1
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/setup.py +2 -2
- vectara_agentic-0.1.14/tests/__init__.py +0 -0
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/tests/test_tools.py +2 -1
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic/__init__.py +1 -1
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic/_callback.py +24 -5
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic/_observability.py +26 -8
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic/_prompts.py +3 -2
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic/agent.py +18 -42
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic/tools.py +16 -10
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic/tools_catalog.py +40 -16
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic/types.py +2 -1
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic/utils.py +5 -5
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14/vectara_agentic.egg-info}/PKG-INFO +88 -76
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic.egg-info/SOURCES.txt +1 -0
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic.egg-info/requires.txt +4 -1
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic.egg-info/top_level.txt +1 -0
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/LICENSE +0 -0
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/MANIFEST.in +0 -0
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/setup.cfg +0 -0
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/tests/test_agent.py +0 -0
- {vectara_agentic-0.1.12 → vectara_agentic-0.1.14}/vectara_agentic.egg-info/dependency_links.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vectara_agentic
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.14
|
|
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
|
|
@@ -32,8 +32,11 @@ Requires-Dist: llama-index-tools-arxiv==0.2.0
|
|
|
32
32
|
Requires-Dist: llama-index-tools-database==0.2.0
|
|
33
33
|
Requires-Dist: llama-index-tools-google==0.2.0
|
|
34
34
|
Requires-Dist: llama-index-tools-tavily_research==0.2.0
|
|
35
|
+
Requires-Dist: tavily-python==0.5.0
|
|
36
|
+
Requires-Dist: yahoo-finance==1.4.0
|
|
37
|
+
Requires-Dist: llama-index-tools-neo4j==0.2.0
|
|
35
38
|
Requires-Dist: openinference-instrumentation-llama-index==3.0.2
|
|
36
|
-
Requires-Dist:
|
|
39
|
+
Requires-Dist: arize-phoenix==4.35.1
|
|
37
40
|
Requires-Dist: arize-phoenix-otel==0.5.1
|
|
38
41
|
Requires-Dist: tokenizers>=0.20
|
|
39
42
|
Requires-Dist: pydantic==2.9.2
|
|
@@ -43,47 +46,57 @@ Requires-Dist: python-dotenv==1.0.1
|
|
|
43
46
|
Requires-Dist: tiktoken==0.7.0
|
|
44
47
|
Requires-Dist: dill==0.3.8
|
|
45
48
|
|
|
46
|
-
# vectara-agentic
|
|
49
|
+
# <img src=".github/assets/Vectara-logo.png" alt="Vectara Logo" width="30" height="30" style="vertical-align: middle;"> vectara-agentic
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
<p align="center">
|
|
52
|
+
<a href="https://vectara.github.io/vectara-agentic-docs">Documentation</a> ·
|
|
53
|
+
<a href="#examples">Examples</a> ·
|
|
54
|
+
<a href="https://discord.gg/S9dwgCNEFs">Discord</a>
|
|
55
|
+
</p>
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
<p align="center">
|
|
58
|
+
<a href="https://opensource.org/licenses/Apache-2.0">
|
|
59
|
+
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License">
|
|
60
|
+
</a>
|
|
61
|
+
<a href="https://github.com/vectara/py-vectara-agentic/graphs/commit-activity">
|
|
62
|
+
<img src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" alt="Maintained">
|
|
63
|
+
</a>
|
|
64
|
+
<a href="https://twitter.com/vectara">
|
|
65
|
+
<img src="https://img.shields.io/twitter/follow/vectara.svg?style=social&label=Follow%20%40Vectara" alt="Twitter">
|
|
66
|
+
</a>
|
|
67
|
+
</p>
|
|
68
|
+
|
|
69
|
+
## ✨ Overview
|
|
54
70
|
|
|
55
71
|
`vectara-agentic` is a Python library for developing powerful AI assistants using Vectara and Agentic-RAG. It leverages the LlamaIndex Agent framework, customized for use with Vectara.
|
|
56
72
|
|
|
57
|
-
###
|
|
73
|
+
### Key Features
|
|
58
74
|
|
|
59
|
-
- Supports `ReAct` and `
|
|
75
|
+
- Supports `ReAct`, `OpenAIAgent` and `LLMCompiler` agent types.
|
|
60
76
|
- Includes pre-built tools for various domains (e.g., finance, legal).
|
|
61
77
|
- Enables easy creation of custom AI assistants and agents.
|
|
62
78
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
- Documentation: [https://vectara.github.io/vectara-agentic-docs/](https://vectara.github.io/vectara-agentic-docs/)
|
|
66
|
-
|
|
67
|
-
## Prerequisites
|
|
79
|
+
### Prerequisites
|
|
68
80
|
|
|
69
81
|
- [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)
|
|
70
82
|
- A Vectara corpus with an [API key](https://docs.vectara.com/docs/api-keys)
|
|
71
83
|
- [Python 3.10 or higher](https://www.python.org/downloads/)
|
|
72
|
-
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Cohere, GEMINI or GROQ)
|
|
84
|
+
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Cohere, GEMINI or GROQ, if you choose to use them)
|
|
73
85
|
|
|
74
|
-
|
|
86
|
+
### Installation
|
|
75
87
|
|
|
76
88
|
```bash
|
|
77
89
|
pip install vectara-agentic
|
|
78
90
|
```
|
|
79
91
|
|
|
80
|
-
## Quick Start
|
|
92
|
+
## 🚀 Quick Start
|
|
81
93
|
|
|
82
|
-
1.
|
|
94
|
+
### 1. Create a Vectara RAG tool
|
|
83
95
|
|
|
84
96
|
```python
|
|
85
97
|
import os
|
|
86
98
|
from vectara_agentic import VectaraToolFactory
|
|
99
|
+
from pydantic import BaseModel, Field
|
|
87
100
|
|
|
88
101
|
vec_factory = VectaraToolFactory(
|
|
89
102
|
vectara_api_key=os.environ['VECTARA_API_KEY'],
|
|
@@ -92,108 +105,109 @@ vec_factory = VectaraToolFactory(
|
|
|
92
105
|
)
|
|
93
106
|
|
|
94
107
|
class QueryFinancialReportsArgs(BaseModel):
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
query: str = Field(..., description="The user query.")
|
|
109
|
+
year: int = Field(..., description="The year. An integer between {min(years)} and {max(years)}.")
|
|
110
|
+
ticker: str = Field(..., description="The company ticker. Must be a valid ticket symbol from the list {tickers.keys()}.")
|
|
98
111
|
|
|
99
|
-
|
|
112
|
+
query_financial_reports_tool = vec_factory.create_rag_tool(
|
|
100
113
|
tool_name="query_financial_reports",
|
|
101
114
|
tool_description="Query financial reports for a company and year",
|
|
102
115
|
tool_args_schema=QueryFinancialReportsArgs,
|
|
103
116
|
)
|
|
104
117
|
```
|
|
105
118
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
2. **Create other tools (optional)**
|
|
119
|
+
### 2. Create other tools (optional)
|
|
109
120
|
|
|
110
121
|
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
|
|
111
122
|
that call other APIs to get more information, or any other type of tool.
|
|
112
123
|
|
|
113
|
-
See [Tools](#agent-tools) for more information.
|
|
124
|
+
See [Agent Tools](#agent-tools) for more information.
|
|
114
125
|
|
|
115
|
-
3.
|
|
126
|
+
### 3. Create your agent
|
|
116
127
|
|
|
117
128
|
```python
|
|
129
|
+
from vectara_agentic import Agent
|
|
130
|
+
|
|
118
131
|
agent = Agent(
|
|
119
|
-
tools
|
|
120
|
-
topic
|
|
121
|
-
custom_instructions
|
|
132
|
+
tools=[query_financial_reports_tool],
|
|
133
|
+
topic="10-K financial reports",
|
|
134
|
+
custom_instructions="""
|
|
135
|
+
- You are a helpful financial assistant in conversation with a user. Use your financial expertise when crafting a query to the tool, to ensure you get the most accurate information.
|
|
136
|
+
- You can answer questions, provide insights, or summarize any information from financial reports.
|
|
137
|
+
- A user may refer to a company's ticker instead of its full name - consider those the same when a user is asking about a company.
|
|
138
|
+
- When calculating a financial metric, make sure you have all the information from tools to complete the calculation.
|
|
139
|
+
- In many cases you may need to query tools on each sub-metric separately before computing the final metric.
|
|
140
|
+
- When using a tool to obtain financial data, consider the fact that information for a certain year may be reported in the following year's report.
|
|
141
|
+
- Report financial data in a consistent manner. For example if you report revenue in thousands, always report revenue in thousands.
|
|
142
|
+
"""
|
|
122
143
|
)
|
|
123
144
|
```
|
|
124
|
-
- `tools` is the list of tools you want to provide to the agent. In this example it's just a single tool.
|
|
125
|
-
- `topic` is a string that defines the expertise you want the agent to specialize in.
|
|
126
|
-
- `custom_instructions` is an optional string that defines special instructions to the agent.
|
|
127
145
|
|
|
128
|
-
|
|
146
|
+
### 4. Run your agent
|
|
129
147
|
|
|
130
148
|
```python
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
financial_bot_instructions = """
|
|
134
|
-
- You are a helpful financial assistant in conversation with a user. Use your financial expertise when crafting a query to the tool, to ensure you get the most accurate information.
|
|
135
|
-
- You can answer questions, provide insights, or summarize any information from financial reports.
|
|
136
|
-
- A user may refer to a company's ticker instead of its full name - consider those the same when a user is asking about a company.
|
|
137
|
-
- When calculating a financial metric, make sure you have all the information from tools to complete the calculation.
|
|
138
|
-
- In many cases you may need to query tools on each sub-metric separately before computing the final metric.
|
|
139
|
-
- When using a tool to obtain financial data, consider the fact that information for a certain year may be reported in the the following year's report.
|
|
140
|
-
- Report financial data in a consistent manner. For example if you report revenue in thousands, always report revenue in thousands.
|
|
141
|
-
"""
|
|
149
|
+
response = agent.chat("What was the revenue for Apple in 2021?")
|
|
150
|
+
print(response)
|
|
142
151
|
```
|
|
143
152
|
|
|
144
|
-
##
|
|
145
|
-
|
|
146
|
-
Configure `vectara-agentic` using environment variables:
|
|
147
|
-
|
|
148
|
-
- `VECTARA_AGENTIC_AGENT_TYPE`: valid values are `REACT`, `LLMCOMPILER` or `OPENAI` (default: `OPENAI`)
|
|
149
|
-
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `GEMINI` or `FIREWORKS` (default: `OPENAI`)
|
|
150
|
-
- `VECTARA_AGENTIC_MAIN_MODEL_NAME`: agent model name (default depends on provider)
|
|
151
|
-
- `VECTARA_AGENTIC_TOOL_LLM_PROVIDER`: tool LLM provider (default: `OPENAI`)
|
|
152
|
-
- `VECTARA_AGENTIC_TOOL_MODEL_NAME`: tool model name (default depends on provider)
|
|
153
|
-
|
|
154
|
-
## Agent Tools
|
|
153
|
+
## 🛠️ Agent Tools
|
|
155
154
|
|
|
156
155
|
`vectara-agentic` provides a few tools out of the box:
|
|
157
|
-
1. Standard tools
|
|
156
|
+
1. **Standard tools**:
|
|
158
157
|
- `summarize_text`: a tool to summarize a long text into a shorter summary (uses LLM)
|
|
159
158
|
- `rephrase_text`: a tool to rephrase a given text, given a set of rephrase instructions (uses LLM)
|
|
160
159
|
|
|
161
|
-
2. Legal tools
|
|
160
|
+
2. **Legal tools**: a set of tools for the legal vertical, such as:
|
|
162
161
|
- `summarize_legal_text`: summarize legal text with a certain point of view
|
|
163
162
|
- `critique_as_judge`: critique a legal text as a judge, providing their perspective
|
|
164
163
|
|
|
165
|
-
3. Financial tools
|
|
164
|
+
3. **Financial tools**: based on tools from Yahoo! Finance:
|
|
166
165
|
- tools to understand the financials of a public company like: `balance_sheet`, `income_statement`, `cash_flow`
|
|
167
166
|
- `stock_news`: provides news about a company
|
|
168
167
|
- `stock_analyst_recommendations`: provides stock analyst recommendations for a company.
|
|
169
168
|
|
|
170
|
-
|
|
169
|
+
1. **Database tools**: providing tools to inspect and query a database
|
|
171
170
|
- `list_tables`: list all tables in the database
|
|
172
171
|
- `describe_tables`: describe the schema of tables in the database
|
|
173
172
|
- `load_data`: returns data based on a SQL query
|
|
174
173
|
|
|
175
|
-
More tools coming soon
|
|
174
|
+
More tools coming soon...
|
|
176
175
|
|
|
177
|
-
You can create your own tool directly from a Python function using the `create_tool()` method of the `
|
|
176
|
+
You can create your own tool directly from a Python function using the `create_tool()` method of the `ToolsFactory` class:
|
|
178
177
|
|
|
179
|
-
```
|
|
178
|
+
```python
|
|
180
179
|
def mult_func(x, y):
|
|
181
|
-
return x*y
|
|
180
|
+
return x * y
|
|
182
181
|
|
|
183
182
|
mult_tool = ToolsFactory().create_tool(mult_func)
|
|
184
183
|
```
|
|
185
184
|
|
|
186
|
-
##
|
|
185
|
+
## 🛠️ Configuration
|
|
186
|
+
|
|
187
|
+
Configure `vectara-agentic` using environment variables:
|
|
188
|
+
|
|
189
|
+
- `VECTARA_AGENTIC_AGENT_TYPE`: valid values are `REACT`, `LLMCOMPILER` or `OPENAI` (default: `OPENAI`)
|
|
190
|
+
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `GEMINI` or `FIREWORKS` (default: `OPENAI`)
|
|
191
|
+
- `VECTARA_AGENTIC_MAIN_MODEL_NAME`: agent model name (default depends on provider)
|
|
192
|
+
- `VECTARA_AGENTIC_TOOL_LLM_PROVIDER`: tool LLM provider (default: `OPENAI`)
|
|
193
|
+
- `VECTARA_AGENTIC_TOOL_MODEL_NAME`: tool model name (default depends on provider)
|
|
194
|
+
- `VECTARA_AGENTIC_OBSERVER_TYPE`: valid values are `ARIZE_PHOENIX` or `NONE` (default: `NONE`)
|
|
195
|
+
|
|
196
|
+
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. Note that `VECTARA_CORPUS_ID` can be a single ID or a comma-separated list of IDs (if you want to query multiple corpora).
|
|
197
|
+
|
|
198
|
+
## ℹ️ Additional Information
|
|
199
|
+
|
|
200
|
+
### Agent Diagnostics
|
|
187
201
|
|
|
188
202
|
The `Agent` class defines a few helpful methods to help you understand the internals of your application.
|
|
189
203
|
* The `report()` method prints out the agent object’s type, the tools, and the LLMs used for the main agent and tool calling.
|
|
190
204
|
* The `token_counts()` method tells you how many tokens you have used in the current session for both the main agent and tool calling LLMs. This can be helpful if you want to track spend by token.
|
|
191
205
|
|
|
192
|
-
|
|
206
|
+
### Serialization
|
|
193
207
|
|
|
194
208
|
The `Agent` class supports serialization. Use the `dumps()` to serialize and `loads()` to read back from a serialized stream.
|
|
195
209
|
|
|
196
|
-
|
|
210
|
+
### Observability
|
|
197
211
|
|
|
198
212
|
vectara-agentic supports observability via the existing integration of LlamaIndex and Arize Phoenix.
|
|
199
213
|
First, set `os["VECTARA_AGENTIC_OBSERVER_TYPE"] = "ARIZE_PHOENIX"`.
|
|
@@ -208,10 +222,9 @@ Then you can use Arize Phoenix in three ways:
|
|
|
208
222
|
3. To view the traces go to `https://app.phoenix.arize.com`.
|
|
209
223
|
|
|
210
224
|
Now when you run your agent, all call traces are sent to Phoenix and recorded.
|
|
211
|
-
In addition, vectara-agentic also records `FCS` values into Arize for every Vectara RAG call. You can see those results in the `Feedback` column of the arize UI.
|
|
212
|
-
|
|
225
|
+
In addition, vectara-agentic also records `FCS` (factual consistency score, aka HHEM) values into Arize for every Vectara RAG call. You can see those results in the `Feedback` column of the arize UI.
|
|
213
226
|
|
|
214
|
-
|
|
227
|
+
### About Custom Instructions
|
|
215
228
|
|
|
216
229
|
The custom instructions you provide to the agent guide its behavior.
|
|
217
230
|
Here are some guidelines when creating your instructions:
|
|
@@ -219,7 +232,7 @@ Here are some guidelines when creating your instructions:
|
|
|
219
232
|
- Consider edge cases and unusual or atypical scenarios.
|
|
220
233
|
- Be cautious to not over-specify behavior based on your primary use-case, as it may limit the agent's ability to behave properly in others.
|
|
221
234
|
|
|
222
|
-
## Examples
|
|
235
|
+
## 📚 Examples
|
|
223
236
|
|
|
224
237
|
Check out our example AI assistants:
|
|
225
238
|
|
|
@@ -227,16 +240,15 @@ Check out our example AI assistants:
|
|
|
227
240
|
- [Justice Harvard Teaching Assistant](https://huggingface.co/spaces/vectara/Justice-Harvard)
|
|
228
241
|
- [Legal Assistant](https://huggingface.co/spaces/vectara/legal-agent)
|
|
229
242
|
|
|
230
|
-
|
|
231
|
-
## Contributing
|
|
243
|
+
## 🤝 Contributing
|
|
232
244
|
|
|
233
245
|
We welcome contributions! Please see our [contributing guide](https://github.com/vectara/py-vectara-agentic/blob/main/CONTRIBUTING.md) for more information.
|
|
234
246
|
|
|
235
|
-
## License
|
|
247
|
+
## 📝 License
|
|
236
248
|
|
|
237
249
|
This project is licensed under the Apache 2.0 License. See the [LICENSE](https://github.com/vectara/py-vectara-agentic/blob/master/LICENSE) file for details.
|
|
238
250
|
|
|
239
|
-
## Contact
|
|
251
|
+
## 📞 Contact
|
|
240
252
|
|
|
241
253
|
- Website: [vectara.com](https://vectara.com)
|
|
242
254
|
- Twitter: [@vectara](https://twitter.com/vectara)
|
|
@@ -1,44 +1,54 @@
|
|
|
1
|
-
# vectara-agentic
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
# <img src=".github/assets/Vectara-logo.png" alt="Vectara Logo" width="30" height="30" style="vertical-align: middle;"> vectara-agentic
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://vectara.github.io/vectara-agentic-docs">Documentation</a> ·
|
|
5
|
+
<a href="#examples">Examples</a> ·
|
|
6
|
+
<a href="https://discord.gg/S9dwgCNEFs">Discord</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://opensource.org/licenses/Apache-2.0">
|
|
11
|
+
<img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License">
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://github.com/vectara/py-vectara-agentic/graphs/commit-activity">
|
|
14
|
+
<img src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" alt="Maintained">
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://twitter.com/vectara">
|
|
17
|
+
<img src="https://img.shields.io/twitter/follow/vectara.svg?style=social&label=Follow%20%40Vectara" alt="Twitter">
|
|
18
|
+
</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
## ✨ Overview
|
|
9
22
|
|
|
10
23
|
`vectara-agentic` is a Python library for developing powerful AI assistants using Vectara and Agentic-RAG. It leverages the LlamaIndex Agent framework, customized for use with Vectara.
|
|
11
24
|
|
|
12
|
-
###
|
|
25
|
+
### Key Features
|
|
13
26
|
|
|
14
|
-
- Supports `ReAct` and `
|
|
27
|
+
- Supports `ReAct`, `OpenAIAgent` and `LLMCompiler` agent types.
|
|
15
28
|
- Includes pre-built tools for various domains (e.g., finance, legal).
|
|
16
29
|
- Enables easy creation of custom AI assistants and agents.
|
|
17
30
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- Documentation: [https://vectara.github.io/vectara-agentic-docs/](https://vectara.github.io/vectara-agentic-docs/)
|
|
21
|
-
|
|
22
|
-
## Prerequisites
|
|
31
|
+
### Prerequisites
|
|
23
32
|
|
|
24
33
|
- [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)
|
|
25
34
|
- A Vectara corpus with an [API key](https://docs.vectara.com/docs/api-keys)
|
|
26
35
|
- [Python 3.10 or higher](https://www.python.org/downloads/)
|
|
27
|
-
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Cohere, GEMINI or GROQ)
|
|
36
|
+
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Cohere, GEMINI or GROQ, if you choose to use them)
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
### Installation
|
|
30
39
|
|
|
31
40
|
```bash
|
|
32
41
|
pip install vectara-agentic
|
|
33
42
|
```
|
|
34
43
|
|
|
35
|
-
## Quick Start
|
|
44
|
+
## 🚀 Quick Start
|
|
36
45
|
|
|
37
|
-
1.
|
|
46
|
+
### 1. Create a Vectara RAG tool
|
|
38
47
|
|
|
39
48
|
```python
|
|
40
49
|
import os
|
|
41
50
|
from vectara_agentic import VectaraToolFactory
|
|
51
|
+
from pydantic import BaseModel, Field
|
|
42
52
|
|
|
43
53
|
vec_factory = VectaraToolFactory(
|
|
44
54
|
vectara_api_key=os.environ['VECTARA_API_KEY'],
|
|
@@ -47,108 +57,109 @@ vec_factory = VectaraToolFactory(
|
|
|
47
57
|
)
|
|
48
58
|
|
|
49
59
|
class QueryFinancialReportsArgs(BaseModel):
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
query: str = Field(..., description="The user query.")
|
|
61
|
+
year: int = Field(..., description="The year. An integer between {min(years)} and {max(years)}.")
|
|
62
|
+
ticker: str = Field(..., description="The company ticker. Must be a valid ticket symbol from the list {tickers.keys()}.")
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
query_financial_reports_tool = vec_factory.create_rag_tool(
|
|
55
65
|
tool_name="query_financial_reports",
|
|
56
66
|
tool_description="Query financial reports for a company and year",
|
|
57
67
|
tool_args_schema=QueryFinancialReportsArgs,
|
|
58
68
|
)
|
|
59
69
|
```
|
|
60
70
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
2. **Create other tools (optional)**
|
|
71
|
+
### 2. Create other tools (optional)
|
|
64
72
|
|
|
65
73
|
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
|
|
66
74
|
that call other APIs to get more information, or any other type of tool.
|
|
67
75
|
|
|
68
|
-
See [Tools](#agent-tools) for more information.
|
|
76
|
+
See [Agent Tools](#agent-tools) for more information.
|
|
69
77
|
|
|
70
|
-
3.
|
|
78
|
+
### 3. Create your agent
|
|
71
79
|
|
|
72
80
|
```python
|
|
81
|
+
from vectara_agentic import Agent
|
|
82
|
+
|
|
73
83
|
agent = Agent(
|
|
74
|
-
tools
|
|
75
|
-
topic
|
|
76
|
-
custom_instructions
|
|
84
|
+
tools=[query_financial_reports_tool],
|
|
85
|
+
topic="10-K financial reports",
|
|
86
|
+
custom_instructions="""
|
|
87
|
+
- You are a helpful financial assistant in conversation with a user. Use your financial expertise when crafting a query to the tool, to ensure you get the most accurate information.
|
|
88
|
+
- You can answer questions, provide insights, or summarize any information from financial reports.
|
|
89
|
+
- A user may refer to a company's ticker instead of its full name - consider those the same when a user is asking about a company.
|
|
90
|
+
- When calculating a financial metric, make sure you have all the information from tools to complete the calculation.
|
|
91
|
+
- In many cases you may need to query tools on each sub-metric separately before computing the final metric.
|
|
92
|
+
- When using a tool to obtain financial data, consider the fact that information for a certain year may be reported in the following year's report.
|
|
93
|
+
- Report financial data in a consistent manner. For example if you report revenue in thousands, always report revenue in thousands.
|
|
94
|
+
"""
|
|
77
95
|
)
|
|
78
96
|
```
|
|
79
|
-
- `tools` is the list of tools you want to provide to the agent. In this example it's just a single tool.
|
|
80
|
-
- `topic` is a string that defines the expertise you want the agent to specialize in.
|
|
81
|
-
- `custom_instructions` is an optional string that defines special instructions to the agent.
|
|
82
97
|
|
|
83
|
-
|
|
98
|
+
### 4. Run your agent
|
|
84
99
|
|
|
85
100
|
```python
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
financial_bot_instructions = """
|
|
89
|
-
- You are a helpful financial assistant in conversation with a user. Use your financial expertise when crafting a query to the tool, to ensure you get the most accurate information.
|
|
90
|
-
- You can answer questions, provide insights, or summarize any information from financial reports.
|
|
91
|
-
- A user may refer to a company's ticker instead of its full name - consider those the same when a user is asking about a company.
|
|
92
|
-
- When calculating a financial metric, make sure you have all the information from tools to complete the calculation.
|
|
93
|
-
- In many cases you may need to query tools on each sub-metric separately before computing the final metric.
|
|
94
|
-
- When using a tool to obtain financial data, consider the fact that information for a certain year may be reported in the the following year's report.
|
|
95
|
-
- Report financial data in a consistent manner. For example if you report revenue in thousands, always report revenue in thousands.
|
|
96
|
-
"""
|
|
101
|
+
response = agent.chat("What was the revenue for Apple in 2021?")
|
|
102
|
+
print(response)
|
|
97
103
|
```
|
|
98
104
|
|
|
99
|
-
##
|
|
100
|
-
|
|
101
|
-
Configure `vectara-agentic` using environment variables:
|
|
102
|
-
|
|
103
|
-
- `VECTARA_AGENTIC_AGENT_TYPE`: valid values are `REACT`, `LLMCOMPILER` or `OPENAI` (default: `OPENAI`)
|
|
104
|
-
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `GEMINI` or `FIREWORKS` (default: `OPENAI`)
|
|
105
|
-
- `VECTARA_AGENTIC_MAIN_MODEL_NAME`: agent model name (default depends on provider)
|
|
106
|
-
- `VECTARA_AGENTIC_TOOL_LLM_PROVIDER`: tool LLM provider (default: `OPENAI`)
|
|
107
|
-
- `VECTARA_AGENTIC_TOOL_MODEL_NAME`: tool model name (default depends on provider)
|
|
108
|
-
|
|
109
|
-
## Agent Tools
|
|
105
|
+
## 🛠️ Agent Tools
|
|
110
106
|
|
|
111
107
|
`vectara-agentic` provides a few tools out of the box:
|
|
112
|
-
1. Standard tools
|
|
108
|
+
1. **Standard tools**:
|
|
113
109
|
- `summarize_text`: a tool to summarize a long text into a shorter summary (uses LLM)
|
|
114
110
|
- `rephrase_text`: a tool to rephrase a given text, given a set of rephrase instructions (uses LLM)
|
|
115
111
|
|
|
116
|
-
2. Legal tools
|
|
112
|
+
2. **Legal tools**: a set of tools for the legal vertical, such as:
|
|
117
113
|
- `summarize_legal_text`: summarize legal text with a certain point of view
|
|
118
114
|
- `critique_as_judge`: critique a legal text as a judge, providing their perspective
|
|
119
115
|
|
|
120
|
-
3. Financial tools
|
|
116
|
+
3. **Financial tools**: based on tools from Yahoo! Finance:
|
|
121
117
|
- tools to understand the financials of a public company like: `balance_sheet`, `income_statement`, `cash_flow`
|
|
122
118
|
- `stock_news`: provides news about a company
|
|
123
119
|
- `stock_analyst_recommendations`: provides stock analyst recommendations for a company.
|
|
124
120
|
|
|
125
|
-
|
|
121
|
+
1. **Database tools**: providing tools to inspect and query a database
|
|
126
122
|
- `list_tables`: list all tables in the database
|
|
127
123
|
- `describe_tables`: describe the schema of tables in the database
|
|
128
124
|
- `load_data`: returns data based on a SQL query
|
|
129
125
|
|
|
130
|
-
More tools coming soon
|
|
126
|
+
More tools coming soon...
|
|
131
127
|
|
|
132
|
-
You can create your own tool directly from a Python function using the `create_tool()` method of the `
|
|
128
|
+
You can create your own tool directly from a Python function using the `create_tool()` method of the `ToolsFactory` class:
|
|
133
129
|
|
|
134
|
-
```
|
|
130
|
+
```python
|
|
135
131
|
def mult_func(x, y):
|
|
136
|
-
return x*y
|
|
132
|
+
return x * y
|
|
137
133
|
|
|
138
134
|
mult_tool = ToolsFactory().create_tool(mult_func)
|
|
139
135
|
```
|
|
140
136
|
|
|
141
|
-
##
|
|
137
|
+
## 🛠️ Configuration
|
|
138
|
+
|
|
139
|
+
Configure `vectara-agentic` using environment variables:
|
|
140
|
+
|
|
141
|
+
- `VECTARA_AGENTIC_AGENT_TYPE`: valid values are `REACT`, `LLMCOMPILER` or `OPENAI` (default: `OPENAI`)
|
|
142
|
+
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: valid values are `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, `COHERE`, `GEMINI` or `FIREWORKS` (default: `OPENAI`)
|
|
143
|
+
- `VECTARA_AGENTIC_MAIN_MODEL_NAME`: agent model name (default depends on provider)
|
|
144
|
+
- `VECTARA_AGENTIC_TOOL_LLM_PROVIDER`: tool LLM provider (default: `OPENAI`)
|
|
145
|
+
- `VECTARA_AGENTIC_TOOL_MODEL_NAME`: tool model name (default depends on provider)
|
|
146
|
+
- `VECTARA_AGENTIC_OBSERVER_TYPE`: valid values are `ARIZE_PHOENIX` or `NONE` (default: `NONE`)
|
|
147
|
+
|
|
148
|
+
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. Note that `VECTARA_CORPUS_ID` can be a single ID or a comma-separated list of IDs (if you want to query multiple corpora).
|
|
149
|
+
|
|
150
|
+
## ℹ️ Additional Information
|
|
151
|
+
|
|
152
|
+
### Agent Diagnostics
|
|
142
153
|
|
|
143
154
|
The `Agent` class defines a few helpful methods to help you understand the internals of your application.
|
|
144
155
|
* The `report()` method prints out the agent object’s type, the tools, and the LLMs used for the main agent and tool calling.
|
|
145
156
|
* The `token_counts()` method tells you how many tokens you have used in the current session for both the main agent and tool calling LLMs. This can be helpful if you want to track spend by token.
|
|
146
157
|
|
|
147
|
-
|
|
158
|
+
### Serialization
|
|
148
159
|
|
|
149
160
|
The `Agent` class supports serialization. Use the `dumps()` to serialize and `loads()` to read back from a serialized stream.
|
|
150
161
|
|
|
151
|
-
|
|
162
|
+
### Observability
|
|
152
163
|
|
|
153
164
|
vectara-agentic supports observability via the existing integration of LlamaIndex and Arize Phoenix.
|
|
154
165
|
First, set `os["VECTARA_AGENTIC_OBSERVER_TYPE"] = "ARIZE_PHOENIX"`.
|
|
@@ -163,10 +174,9 @@ Then you can use Arize Phoenix in three ways:
|
|
|
163
174
|
3. To view the traces go to `https://app.phoenix.arize.com`.
|
|
164
175
|
|
|
165
176
|
Now when you run your agent, all call traces are sent to Phoenix and recorded.
|
|
166
|
-
In addition, vectara-agentic also records `FCS` values into Arize for every Vectara RAG call. You can see those results in the `Feedback` column of the arize UI.
|
|
167
|
-
|
|
177
|
+
In addition, vectara-agentic also records `FCS` (factual consistency score, aka HHEM) values into Arize for every Vectara RAG call. You can see those results in the `Feedback` column of the arize UI.
|
|
168
178
|
|
|
169
|
-
|
|
179
|
+
### About Custom Instructions
|
|
170
180
|
|
|
171
181
|
The custom instructions you provide to the agent guide its behavior.
|
|
172
182
|
Here are some guidelines when creating your instructions:
|
|
@@ -174,7 +184,7 @@ Here are some guidelines when creating your instructions:
|
|
|
174
184
|
- Consider edge cases and unusual or atypical scenarios.
|
|
175
185
|
- Be cautious to not over-specify behavior based on your primary use-case, as it may limit the agent's ability to behave properly in others.
|
|
176
186
|
|
|
177
|
-
## Examples
|
|
187
|
+
## 📚 Examples
|
|
178
188
|
|
|
179
189
|
Check out our example AI assistants:
|
|
180
190
|
|
|
@@ -182,16 +192,15 @@ Check out our example AI assistants:
|
|
|
182
192
|
- [Justice Harvard Teaching Assistant](https://huggingface.co/spaces/vectara/Justice-Harvard)
|
|
183
193
|
- [Legal Assistant](https://huggingface.co/spaces/vectara/legal-agent)
|
|
184
194
|
|
|
185
|
-
|
|
186
|
-
## Contributing
|
|
195
|
+
## 🤝 Contributing
|
|
187
196
|
|
|
188
197
|
We welcome contributions! Please see our [contributing guide](https://github.com/vectara/py-vectara-agentic/blob/main/CONTRIBUTING.md) for more information.
|
|
189
198
|
|
|
190
|
-
## License
|
|
199
|
+
## 📝 License
|
|
191
200
|
|
|
192
201
|
This project is licensed under the Apache 2.0 License. See the [LICENSE](https://github.com/vectara/py-vectara-agentic/blob/master/LICENSE) file for details.
|
|
193
202
|
|
|
194
|
-
## Contact
|
|
203
|
+
## 📞 Contact
|
|
195
204
|
|
|
196
205
|
- Website: [vectara.com](https://vectara.com)
|
|
197
206
|
- Twitter: [@vectara](https://twitter.com/vectara)
|
|
@@ -14,8 +14,11 @@ llama-index-tools-arxiv==0.2.0
|
|
|
14
14
|
llama-index-tools-database==0.2.0
|
|
15
15
|
llama-index-tools-google==0.2.0
|
|
16
16
|
llama-index-tools-tavily_research==0.2.0
|
|
17
|
+
tavily-python==0.5.0
|
|
18
|
+
yahoo-finance==1.4.0
|
|
19
|
+
llama-index-tools-neo4j==0.2.0
|
|
17
20
|
openinference-instrumentation-llama-index==3.0.2
|
|
18
|
-
|
|
21
|
+
arize-phoenix==4.35.1
|
|
19
22
|
arize-phoenix-otel==0.5.1
|
|
20
23
|
tokenizers>=0.20
|
|
21
24
|
pydantic==2.9.2
|
|
@@ -8,7 +8,7 @@ def read_requirements():
|
|
|
8
8
|
|
|
9
9
|
setup(
|
|
10
10
|
name="vectara_agentic",
|
|
11
|
-
version="0.1.
|
|
11
|
+
version="0.1.14",
|
|
12
12
|
author="Ofer Mendelevitch",
|
|
13
13
|
author_email="ofer@vectara.com",
|
|
14
14
|
description="A Python package for creating AI Assistants and AI Agents with Vectara",
|
|
@@ -25,7 +25,7 @@ setup(
|
|
|
25
25
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
26
26
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
27
|
],
|
|
28
|
-
keywords
|
|
28
|
+
keywords=["LLM", "NLP", "RAG", "Agentic-RAG"],
|
|
29
29
|
project_urls={
|
|
30
30
|
"Documentation": "https://vectara.github.io/vectara-agentic-docs/",
|
|
31
31
|
},
|
|
File without changes
|
|
@@ -76,7 +76,8 @@ class TestToolsPackage(unittest.TestCase):
|
|
|
76
76
|
vectara_summarizer="mockingbird-1.0-2024-07-16"
|
|
77
77
|
)
|
|
78
78
|
|
|
79
|
-
self.
|
|
79
|
+
self.assertIn("Vectara is an end-to-end platform", agent.chat("What is Vectara?"))
|
|
80
|
+
|
|
80
81
|
|
|
81
82
|
if __name__ == "__main__":
|
|
82
83
|
unittest.main()
|