vectara-agentic 0.1.0__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.0/LICENSE +201 -0
- vectara_agentic-0.1.0/MANIFEST.in +7 -0
- vectara_agentic-0.1.0/PKG-INFO +190 -0
- vectara_agentic-0.1.0/README.md +176 -0
- vectara_agentic-0.1.0/requirements.txt +20 -0
- vectara_agentic-0.1.0/setup.cfg +4 -0
- vectara_agentic-0.1.0/setup.py +26 -0
- vectara_agentic-0.1.0/tests/test_agent.py +48 -0
- vectara_agentic-0.1.0/tests/test_tools.py +52 -0
- vectara_agentic-0.1.0/vectara_agentic/__init__.py +21 -0
- vectara_agentic-0.1.0/vectara_agentic/_callback.py +96 -0
- vectara_agentic-0.1.0/vectara_agentic/_prompts.py +106 -0
- vectara_agentic-0.1.0/vectara_agentic/agent.py +162 -0
- vectara_agentic-0.1.0/vectara_agentic/tools.py +415 -0
- vectara_agentic-0.1.0/vectara_agentic/tools_catalog.py +112 -0
- vectara_agentic-0.1.0/vectara_agentic/types.py +41 -0
- vectara_agentic-0.1.0/vectara_agentic/utils.py +69 -0
- vectara_agentic-0.1.0/vectara_agentic.egg-info/PKG-INFO +190 -0
- vectara_agentic-0.1.0/vectara_agentic.egg-info/SOURCES.txt +20 -0
- vectara_agentic-0.1.0/vectara_agentic.egg-info/dependency_links.txt +1 -0
- vectara_agentic-0.1.0/vectara_agentic.egg-info/requires.txt +20 -0
- vectara_agentic-0.1.0/vectara_agentic.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: vectara_agentic
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package for creating AI Assistants and AI Agents with Vectara
|
|
5
|
+
Home-page: https://github.com/vectara/py-vectara-agentic
|
|
6
|
+
Author: Ofer Mendelevitch
|
|
7
|
+
Author-email: ofer@vectara.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
|
|
15
|
+
# vectara-agentic
|
|
16
|
+
|
|
17
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
18
|
+
[](https://github.com/vectara/py-vectara-agentic/graphs/commit-activity)
|
|
19
|
+
|
|
20
|
+
[](https://twitter.com/vectara)
|
|
21
|
+
[](https://discord.com/invite/GFb8gMz6UH)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
The idea of LLM-based agents it to use the LLM for building sophisticated AI assistants:
|
|
25
|
+
- The LLM is used for reasoning and coming up with a game-plan for how to respond to the user query.
|
|
26
|
+
- There are 1 or more "tools" provided to the agent. These tools can be used by the LLM to execute its plan.
|
|
27
|
+
|
|
28
|
+
`vectara-agentic` is a Python library that let's you develop powerful AI assistants with Vectara, using Agentic-RAG:
|
|
29
|
+
* Based on LlamaIndex Agent framework, customized for use with Vectara.
|
|
30
|
+
* Supports the `ReAct` or `OpenAIAgent` agent types.
|
|
31
|
+
* Includes many tools out of the box (e.g. for finance, legal and other verticals).
|
|
32
|
+
|
|
33
|
+
## Getting Started
|
|
34
|
+
|
|
35
|
+
### Prerequisites
|
|
36
|
+
* A [Vectara account](https://console.vectara.com/signup)
|
|
37
|
+
* A Vectara corpus with an [API key](https://docs.vectara.com/docs/api-keys)
|
|
38
|
+
* [Python 3.10 (or higher)](https://www.python.org/downloads/)
|
|
39
|
+
* An OpenAI API key specified in your environment as `OPENAI_API_KEY`
|
|
40
|
+
|
|
41
|
+
### Install vectara-agentic
|
|
42
|
+
|
|
43
|
+
- `python -m pip install vectara-agentic`
|
|
44
|
+
|
|
45
|
+
### Create your AI assistant
|
|
46
|
+
|
|
47
|
+
Creating an AI assistant with `vectara-agentic` involves the following:
|
|
48
|
+
|
|
49
|
+
#### Step 1: Create Vectara RAG tool
|
|
50
|
+
|
|
51
|
+
First, create an instance of the `VectaraToolFactory` class as follows:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
vec_factory = VectaraToolFactory(vectara_api_key=os.environ['VECTARA_API_KEY'],
|
|
55
|
+
vectara_customer_id=os.environ['VECTARA_CUSTOMER_ID'],
|
|
56
|
+
vectara_corpus_id=os.environ['VECTARA_CORPUS_ID'])
|
|
57
|
+
```
|
|
58
|
+
The tools factory has a useful helper function called `create_rag_tool` which automates the creation of a
|
|
59
|
+
tool to query Vectara RAG.
|
|
60
|
+
|
|
61
|
+
For example if my Vectara corpus includes financial information from company
|
|
62
|
+
10K annual reports for multiple companies and years, I can use the following:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
|
|
66
|
+
class QueryFinancialReportsArgs(BaseModel):
|
|
67
|
+
query: str = Field(..., description="The user query. Must be a question about the company's financials, and should not include the company name, ticker or year.")
|
|
68
|
+
year: int = Field(..., description=f"The year. an integer.")
|
|
69
|
+
ticker: str = Field(..., description=f"The company ticker. Must be a valid ticket symbol.")
|
|
70
|
+
query_financial_reports = vec_factory.create_rag_tool(
|
|
71
|
+
tool_name = "query_financial_reports",
|
|
72
|
+
tool_description = """
|
|
73
|
+
Given a company name and year,
|
|
74
|
+
returns a response (str) to a user query about the company's financials for that year.
|
|
75
|
+
When using this tool, make sure to provide a valid company ticker and year.
|
|
76
|
+
Use this tool to get financial information one metric at a time.
|
|
77
|
+
""",
|
|
78
|
+
tool_args_schema = QueryFinancialReportsArgs,
|
|
79
|
+
tool_filter_template = "doc.year = {year} and doc.ticker = '{ticker}'"
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
Note how `QueryFinancialReportsArgs` defines the arguments for my tool using pydantic's `Field` class. The `tool_description`
|
|
83
|
+
as well as the description of each argument are important as they provide the LLM with the ability to understand how to use
|
|
84
|
+
this tool in the most effective way.
|
|
85
|
+
The `tool_filter_template` provides the template filtering expression the tool should use when calling Vectara.
|
|
86
|
+
|
|
87
|
+
You can of course create more than one Vectara tool; tools may point at different corpora or may have different parameters for search
|
|
88
|
+
or generation. Remember though to think about your tools wisely and from the agent point of view - at the end of the day they are just tools
|
|
89
|
+
in the service of the agent, so should be differentiated.
|
|
90
|
+
|
|
91
|
+
#### Step 2: Create Other Tools, as needed
|
|
92
|
+
|
|
93
|
+
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
|
|
94
|
+
that call other APIs to get more information, and much more.
|
|
95
|
+
|
|
96
|
+
`vectara-agentic` provides a few tools out of the box:
|
|
97
|
+
1. Standard tools:
|
|
98
|
+
- `get_current_date`: allows the agent to figure out which date it is.
|
|
99
|
+
- `summarize_text`: a tool to summarize a long text into a shorter summary (uses LLM)
|
|
100
|
+
- `rephrase_text`: a tool to rephrase a given text, given a set of rephrase instructions (uses LLM)
|
|
101
|
+
|
|
102
|
+
2. Financial tools: a set of tools for financial analysis of public company data:
|
|
103
|
+
- `get_company_name`: get company name given its ticker (uses Yahoo Finance)
|
|
104
|
+
- `calculate_return_on_equity`, `calculate_return_on_assets`, `calculate_debt_to_equity_ratio` and `calculate_ebitda`
|
|
105
|
+
|
|
106
|
+
You can create your own tool directly from a Python function using the `create_tool()` method:
|
|
107
|
+
|
|
108
|
+
```Python
|
|
109
|
+
def mult_func(x, y):
|
|
110
|
+
return x*y
|
|
111
|
+
|
|
112
|
+
mult_tool = ToolsFactory().create_tool(mult_func)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
3. More tools to be coming soon
|
|
116
|
+
|
|
117
|
+
#### Step 3: Create your agent
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
agent = Agent(
|
|
121
|
+
agent_type = agent_type,
|
|
122
|
+
tools = tools,
|
|
123
|
+
topic = topic_of_expertise
|
|
124
|
+
custom_instructions = financial_bot_instructions,
|
|
125
|
+
update_func = update_func
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- `agent_type` is one of `AgentType.REACT` or `AgentTypeOpenAI`
|
|
130
|
+
- `tools` is the list of tools you want to provide to the agent
|
|
131
|
+
- `topic` is a string that defines the expertise you want the agent to specialize in.
|
|
132
|
+
- `custom_instructions` is an optional string that defines special instructions to the agent
|
|
133
|
+
- `update_func` is a callback function that will be called by the agent as it performs its task
|
|
134
|
+
The inputs to this function you provide are `status_type` of type AgentStatusType and
|
|
135
|
+
`msg` which is a string.
|
|
136
|
+
|
|
137
|
+
For example, for a financial agent we can use:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
topic = "10-K financial reports",
|
|
141
|
+
|
|
142
|
+
financial_bot_instructions = """
|
|
143
|
+
- 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.
|
|
144
|
+
- You can answer questions, provide insights, or summarize any information from financial reports.
|
|
145
|
+
- 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.
|
|
146
|
+
- When calculating a financial metric, make sure you have all the information from tools to complete the calculation.
|
|
147
|
+
- In many cases you may need to query tools on each sub-metric separately before computing the final metric.
|
|
148
|
+
- 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.
|
|
149
|
+
- Report financial data in a consistent manner. For example if you report revenue in thousands, always report revenue in thousands.
|
|
150
|
+
"""
|
|
151
|
+
```
|
|
152
|
+
## Configuration
|
|
153
|
+
|
|
154
|
+
`vectara-agentic` is using environment variables for a few global configuration
|
|
155
|
+
- `VECTARA_AGENTIC_AGENT_TYPE`: type of agent - `REACT` or `OPENAI` (default `OPENAI`)
|
|
156
|
+
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: agent LLM provider `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, or `FIREWORKS` (default `OPENAI`)
|
|
157
|
+
- `VECTARA_AGENTIC_MAIN_MODEL_NAME`: agent model name (default depends on provider)
|
|
158
|
+
- `VECTARA_AGENTIC_TOOL_LLM_PROVIDER`: tool LLM provider `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, or `FIREWORKS` (default `OPENAI`)
|
|
159
|
+
- `VECTARA_AGENTIC_TOOL_MODEL_NAME`: tool model name (default depends on provider)
|
|
160
|
+
|
|
161
|
+
## Examples
|
|
162
|
+
|
|
163
|
+
We have created a few example AI assistants that you can look at for inspiration and code examples:
|
|
164
|
+
- [Financial Assistant](https://huggingface.co/spaces/vectara/finance-chat).
|
|
165
|
+
- [Justice Harvard Teaching Assistant](https://huggingface.co/spaces/vectara/Justice-Harvard).
|
|
166
|
+
- [Legal Assistant](https://huggingface.co/spaces/vectara/legal-agent).
|
|
167
|
+
|
|
168
|
+
## Author
|
|
169
|
+
|
|
170
|
+
👤 **Vectara**
|
|
171
|
+
|
|
172
|
+
- Website: [vectara.com](https://vectara.com)
|
|
173
|
+
- Twitter: [@vectara](https://twitter.com/vectara)
|
|
174
|
+
- GitHub: [@vectara](https://github.com/vectara)
|
|
175
|
+
- LinkedIn: [@vectara](https://www.linkedin.com/company/vectara/)
|
|
176
|
+
- Discord: [@vectara](https://discord.gg/GFb8gMz6UH)
|
|
177
|
+
|
|
178
|
+
## 🤝 Contributing
|
|
179
|
+
|
|
180
|
+
Contributions, issues and feature requests are welcome and appreciated!<br />
|
|
181
|
+
Feel free to check [issues page](https://github.com/vectara/py-vectara-agentic/issues). You can also take a look at the [contributing guide](https://github.com/vectara/py-vectara-agentic/blob/master/CONTRIBUTING.md).
|
|
182
|
+
|
|
183
|
+
## Show your support
|
|
184
|
+
|
|
185
|
+
Give a ⭐️ if this project helped you!
|
|
186
|
+
|
|
187
|
+
## 📝 License
|
|
188
|
+
|
|
189
|
+
Copyright © 2024 [Vectara](https://github.com/vectara).<br />
|
|
190
|
+
This project is [Apache 2.0](https://github.com/vectara/py-vectara-agentic/blob/master/LICENSE) licensed.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# vectara-agentic
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
4
|
+
[](https://github.com/vectara/py-vectara-agentic/graphs/commit-activity)
|
|
5
|
+
|
|
6
|
+
[](https://twitter.com/vectara)
|
|
7
|
+
[](https://discord.com/invite/GFb8gMz6UH)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
The idea of LLM-based agents it to use the LLM for building sophisticated AI assistants:
|
|
11
|
+
- The LLM is used for reasoning and coming up with a game-plan for how to respond to the user query.
|
|
12
|
+
- There are 1 or more "tools" provided to the agent. These tools can be used by the LLM to execute its plan.
|
|
13
|
+
|
|
14
|
+
`vectara-agentic` is a Python library that let's you develop powerful AI assistants with Vectara, using Agentic-RAG:
|
|
15
|
+
* Based on LlamaIndex Agent framework, customized for use with Vectara.
|
|
16
|
+
* Supports the `ReAct` or `OpenAIAgent` agent types.
|
|
17
|
+
* Includes many tools out of the box (e.g. for finance, legal and other verticals).
|
|
18
|
+
|
|
19
|
+
## Getting Started
|
|
20
|
+
|
|
21
|
+
### Prerequisites
|
|
22
|
+
* A [Vectara account](https://console.vectara.com/signup)
|
|
23
|
+
* A Vectara corpus with an [API key](https://docs.vectara.com/docs/api-keys)
|
|
24
|
+
* [Python 3.10 (or higher)](https://www.python.org/downloads/)
|
|
25
|
+
* An OpenAI API key specified in your environment as `OPENAI_API_KEY`
|
|
26
|
+
|
|
27
|
+
### Install vectara-agentic
|
|
28
|
+
|
|
29
|
+
- `python -m pip install vectara-agentic`
|
|
30
|
+
|
|
31
|
+
### Create your AI assistant
|
|
32
|
+
|
|
33
|
+
Creating an AI assistant with `vectara-agentic` involves the following:
|
|
34
|
+
|
|
35
|
+
#### Step 1: Create Vectara RAG tool
|
|
36
|
+
|
|
37
|
+
First, create an instance of the `VectaraToolFactory` class as follows:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
vec_factory = VectaraToolFactory(vectara_api_key=os.environ['VECTARA_API_KEY'],
|
|
41
|
+
vectara_customer_id=os.environ['VECTARA_CUSTOMER_ID'],
|
|
42
|
+
vectara_corpus_id=os.environ['VECTARA_CORPUS_ID'])
|
|
43
|
+
```
|
|
44
|
+
The tools factory has a useful helper function called `create_rag_tool` which automates the creation of a
|
|
45
|
+
tool to query Vectara RAG.
|
|
46
|
+
|
|
47
|
+
For example if my Vectara corpus includes financial information from company
|
|
48
|
+
10K annual reports for multiple companies and years, I can use the following:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
|
|
52
|
+
class QueryFinancialReportsArgs(BaseModel):
|
|
53
|
+
query: str = Field(..., description="The user query. Must be a question about the company's financials, and should not include the company name, ticker or year.")
|
|
54
|
+
year: int = Field(..., description=f"The year. an integer.")
|
|
55
|
+
ticker: str = Field(..., description=f"The company ticker. Must be a valid ticket symbol.")
|
|
56
|
+
query_financial_reports = vec_factory.create_rag_tool(
|
|
57
|
+
tool_name = "query_financial_reports",
|
|
58
|
+
tool_description = """
|
|
59
|
+
Given a company name and year,
|
|
60
|
+
returns a response (str) to a user query about the company's financials for that year.
|
|
61
|
+
When using this tool, make sure to provide a valid company ticker and year.
|
|
62
|
+
Use this tool to get financial information one metric at a time.
|
|
63
|
+
""",
|
|
64
|
+
tool_args_schema = QueryFinancialReportsArgs,
|
|
65
|
+
tool_filter_template = "doc.year = {year} and doc.ticker = '{ticker}'"
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
Note how `QueryFinancialReportsArgs` defines the arguments for my tool using pydantic's `Field` class. The `tool_description`
|
|
69
|
+
as well as the description of each argument are important as they provide the LLM with the ability to understand how to use
|
|
70
|
+
this tool in the most effective way.
|
|
71
|
+
The `tool_filter_template` provides the template filtering expression the tool should use when calling Vectara.
|
|
72
|
+
|
|
73
|
+
You can of course create more than one Vectara tool; tools may point at different corpora or may have different parameters for search
|
|
74
|
+
or generation. Remember though to think about your tools wisely and from the agent point of view - at the end of the day they are just tools
|
|
75
|
+
in the service of the agent, so should be differentiated.
|
|
76
|
+
|
|
77
|
+
#### Step 2: Create Other Tools, as needed
|
|
78
|
+
|
|
79
|
+
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
|
|
80
|
+
that call other APIs to get more information, and much more.
|
|
81
|
+
|
|
82
|
+
`vectara-agentic` provides a few tools out of the box:
|
|
83
|
+
1. Standard tools:
|
|
84
|
+
- `get_current_date`: allows the agent to figure out which date it is.
|
|
85
|
+
- `summarize_text`: a tool to summarize a long text into a shorter summary (uses LLM)
|
|
86
|
+
- `rephrase_text`: a tool to rephrase a given text, given a set of rephrase instructions (uses LLM)
|
|
87
|
+
|
|
88
|
+
2. Financial tools: a set of tools for financial analysis of public company data:
|
|
89
|
+
- `get_company_name`: get company name given its ticker (uses Yahoo Finance)
|
|
90
|
+
- `calculate_return_on_equity`, `calculate_return_on_assets`, `calculate_debt_to_equity_ratio` and `calculate_ebitda`
|
|
91
|
+
|
|
92
|
+
You can create your own tool directly from a Python function using the `create_tool()` method:
|
|
93
|
+
|
|
94
|
+
```Python
|
|
95
|
+
def mult_func(x, y):
|
|
96
|
+
return x*y
|
|
97
|
+
|
|
98
|
+
mult_tool = ToolsFactory().create_tool(mult_func)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
3. More tools to be coming soon
|
|
102
|
+
|
|
103
|
+
#### Step 3: Create your agent
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
agent = Agent(
|
|
107
|
+
agent_type = agent_type,
|
|
108
|
+
tools = tools,
|
|
109
|
+
topic = topic_of_expertise
|
|
110
|
+
custom_instructions = financial_bot_instructions,
|
|
111
|
+
update_func = update_func
|
|
112
|
+
)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- `agent_type` is one of `AgentType.REACT` or `AgentTypeOpenAI`
|
|
116
|
+
- `tools` is the list of tools you want to provide to the agent
|
|
117
|
+
- `topic` is a string that defines the expertise you want the agent to specialize in.
|
|
118
|
+
- `custom_instructions` is an optional string that defines special instructions to the agent
|
|
119
|
+
- `update_func` is a callback function that will be called by the agent as it performs its task
|
|
120
|
+
The inputs to this function you provide are `status_type` of type AgentStatusType and
|
|
121
|
+
`msg` which is a string.
|
|
122
|
+
|
|
123
|
+
For example, for a financial agent we can use:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
topic = "10-K financial reports",
|
|
127
|
+
|
|
128
|
+
financial_bot_instructions = """
|
|
129
|
+
- 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.
|
|
130
|
+
- You can answer questions, provide insights, or summarize any information from financial reports.
|
|
131
|
+
- 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.
|
|
132
|
+
- When calculating a financial metric, make sure you have all the information from tools to complete the calculation.
|
|
133
|
+
- In many cases you may need to query tools on each sub-metric separately before computing the final metric.
|
|
134
|
+
- 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.
|
|
135
|
+
- Report financial data in a consistent manner. For example if you report revenue in thousands, always report revenue in thousands.
|
|
136
|
+
"""
|
|
137
|
+
```
|
|
138
|
+
## Configuration
|
|
139
|
+
|
|
140
|
+
`vectara-agentic` is using environment variables for a few global configuration
|
|
141
|
+
- `VECTARA_AGENTIC_AGENT_TYPE`: type of agent - `REACT` or `OPENAI` (default `OPENAI`)
|
|
142
|
+
- `VECTARA_AGENTIC_MAIN_LLM_PROVIDER`: agent LLM provider `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, 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 `OPENAI`, `ANTHROPIC`, `TOGETHER`, `GROQ`, or `FIREWORKS` (default `OPENAI`)
|
|
145
|
+
- `VECTARA_AGENTIC_TOOL_MODEL_NAME`: tool model name (default depends on provider)
|
|
146
|
+
|
|
147
|
+
## Examples
|
|
148
|
+
|
|
149
|
+
We have created a few example AI assistants that you can look at for inspiration and code examples:
|
|
150
|
+
- [Financial Assistant](https://huggingface.co/spaces/vectara/finance-chat).
|
|
151
|
+
- [Justice Harvard Teaching Assistant](https://huggingface.co/spaces/vectara/Justice-Harvard).
|
|
152
|
+
- [Legal Assistant](https://huggingface.co/spaces/vectara/legal-agent).
|
|
153
|
+
|
|
154
|
+
## Author
|
|
155
|
+
|
|
156
|
+
👤 **Vectara**
|
|
157
|
+
|
|
158
|
+
- Website: [vectara.com](https://vectara.com)
|
|
159
|
+
- Twitter: [@vectara](https://twitter.com/vectara)
|
|
160
|
+
- GitHub: [@vectara](https://github.com/vectara)
|
|
161
|
+
- LinkedIn: [@vectara](https://www.linkedin.com/company/vectara/)
|
|
162
|
+
- Discord: [@vectara](https://discord.gg/GFb8gMz6UH)
|
|
163
|
+
|
|
164
|
+
## 🤝 Contributing
|
|
165
|
+
|
|
166
|
+
Contributions, issues and feature requests are welcome and appreciated!<br />
|
|
167
|
+
Feel free to check [issues page](https://github.com/vectara/py-vectara-agentic/issues). You can also take a look at the [contributing guide](https://github.com/vectara/py-vectara-agentic/blob/master/CONTRIBUTING.md).
|
|
168
|
+
|
|
169
|
+
## Show your support
|
|
170
|
+
|
|
171
|
+
Give a ⭐️ if this project helped you!
|
|
172
|
+
|
|
173
|
+
## 📝 License
|
|
174
|
+
|
|
175
|
+
Copyright © 2024 [Vectara](https://github.com/vectara).<br />
|
|
176
|
+
This project is [Apache 2.0](https://github.com/vectara/py-vectara-agentic/blob/master/LICENSE) licensed.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
llama-index==0.10.64
|
|
2
|
+
llama-index-indices-managed-vectara==0.1.7
|
|
3
|
+
llama-index-agent-llm-compiler==0.1.0
|
|
4
|
+
llama-index-agent-openai==0.2.9
|
|
5
|
+
llama-index-llms-openai==0.1.29
|
|
6
|
+
llama-index-llms-anthropic==0.1.17
|
|
7
|
+
llama-index-llms-together==0.1.3
|
|
8
|
+
llama-index-llms-groq==0.1.4
|
|
9
|
+
llama-index-tools-yahoo-finance==0.1.1
|
|
10
|
+
llama-index-tools-arxiv==0.1.3
|
|
11
|
+
llama-index-tools-database==0.1.3
|
|
12
|
+
llama-index-tools-google==0.1.6
|
|
13
|
+
llama-index-tools-tavily_research==0.1.3
|
|
14
|
+
llama-index-llms-fireworks==0.1.8
|
|
15
|
+
pydantic==1.10.17
|
|
16
|
+
retrying==1.3.4
|
|
17
|
+
mypy==1.11.0
|
|
18
|
+
pylint==3.2.6
|
|
19
|
+
flake8==7.1.0
|
|
20
|
+
pymongo==4.6.1
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def read_requirements():
|
|
5
|
+
with open("requirements.txt") as req:
|
|
6
|
+
return req.read().splitlines()
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
setup(
|
|
10
|
+
name="vectara_agentic",
|
|
11
|
+
version="0.1.0",
|
|
12
|
+
author="Ofer Mendelevitch",
|
|
13
|
+
author_email="ofer@vectara.com",
|
|
14
|
+
description="A Python package for creating AI Assistants and AI Agents with Vectara",
|
|
15
|
+
long_description=open("README.md").read(),
|
|
16
|
+
long_description_content_type="text/markdown",
|
|
17
|
+
url="https://github.com/vectara/py-vectara-agentic",
|
|
18
|
+
packages=find_packages(),
|
|
19
|
+
install_requires=read_requirements(),
|
|
20
|
+
classifiers=[
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
],
|
|
25
|
+
python_requires=">=3.10",
|
|
26
|
+
)
|