vectara-agentic 0.1.8__py3-none-any.whl → 0.1.9__py3-none-any.whl
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/__init__.py +1 -1
- vectara_agentic/_prompts.py +4 -3
- vectara_agentic/agent.py +17 -9
- vectara_agentic/tools.py +13 -10
- {vectara_agentic-0.1.8.dist-info → vectara_agentic-0.1.9.dist-info}/METADATA +22 -2
- vectara_agentic-0.1.9.dist-info/RECORD +13 -0
- vectara_agentic-0.1.8.dist-info/RECORD +0 -13
- {vectara_agentic-0.1.8.dist-info → vectara_agentic-0.1.9.dist-info}/LICENSE +0 -0
- {vectara_agentic-0.1.8.dist-info → vectara_agentic-0.1.9.dist-info}/WHEEL +0 -0
- {vectara_agentic-0.1.8.dist-info → vectara_agentic-0.1.9.dist-info}/top_level.txt +0 -0
vectara_agentic/__init__.py
CHANGED
vectara_agentic/_prompts.py
CHANGED
|
@@ -88,16 +88,17 @@ If this format is used, the user will respond in the following format:
|
|
|
88
88
|
Observation: tool response
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
You should keep repeating the above format till you have enough information to answer the question without using any more tools.
|
|
91
|
+
You should keep repeating the above format till you have enough information to answer the question without using any more tools.
|
|
92
|
+
At that point, you MUST respond in the one of the following two formats (and do not include any Action):
|
|
92
93
|
|
|
93
94
|
```
|
|
94
95
|
Thought: I can answer without using any more tools. I'll use the user's language to answer
|
|
95
|
-
Answer: [your answer here (In the same language as the user's question)]
|
|
96
|
+
Answer: [your answer here (In the same language as the user's question, and maintain any references/citations)]
|
|
96
97
|
```
|
|
97
98
|
|
|
98
99
|
```
|
|
99
100
|
Thought: I cannot answer the question with the provided tools.
|
|
100
|
-
Answer: [your answer here (In the same language as the user's question)]
|
|
101
|
+
Answer: [your answer here (In the same language as the user's question, and maintain any references/citations)]
|
|
101
102
|
```
|
|
102
103
|
|
|
103
104
|
## Current Conversation
|
vectara_agentic/agent.py
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"""
|
|
2
2
|
This module contains the Agent class for handling different types of agents and their interactions.
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
4
|
from typing import List, Callable, Optional
|
|
6
5
|
import os
|
|
7
6
|
from datetime import date
|
|
8
7
|
import time
|
|
9
8
|
|
|
9
|
+
import logging
|
|
10
|
+
logger = logging.getLogger('opentelemetry.exporter.otlp.proto.http.trace_exporter')
|
|
11
|
+
logger.setLevel(logging.CRITICAL)
|
|
12
|
+
|
|
10
13
|
from retrying import retry
|
|
11
14
|
from pydantic import Field, create_model
|
|
12
15
|
|
|
13
|
-
|
|
14
16
|
from llama_index.core.tools import FunctionTool
|
|
15
17
|
from llama_index.core.agent import ReActAgent
|
|
16
18
|
from llama_index.core.agent.react.formatter import ReActChatFormatter
|
|
@@ -21,6 +23,7 @@ from llama_index.agent.openai import OpenAIAgent
|
|
|
21
23
|
from llama_index.core.memory import ChatMemoryBuffer
|
|
22
24
|
from llama_index.core import set_global_handler
|
|
23
25
|
|
|
26
|
+
import phoenix as px
|
|
24
27
|
|
|
25
28
|
from dotenv import load_dotenv
|
|
26
29
|
|
|
@@ -113,7 +116,7 @@ class Agent:
|
|
|
113
116
|
memory=memory,
|
|
114
117
|
verbose=verbose,
|
|
115
118
|
react_chat_formatter=ReActChatFormatter(system_header=prompt),
|
|
116
|
-
max_iterations=
|
|
119
|
+
max_iterations=30,
|
|
117
120
|
callable_manager=callback_manager,
|
|
118
121
|
)
|
|
119
122
|
elif self.agent_type == AgentType.OPENAI:
|
|
@@ -124,7 +127,7 @@ class Agent:
|
|
|
124
127
|
memory=memory,
|
|
125
128
|
verbose=verbose,
|
|
126
129
|
callable_manager=callback_manager,
|
|
127
|
-
max_function_calls=
|
|
130
|
+
max_function_calls=20,
|
|
128
131
|
system_prompt=prompt,
|
|
129
132
|
)
|
|
130
133
|
elif self.agent_type == AgentType.LLMCOMPILER:
|
|
@@ -139,8 +142,13 @@ class Agent:
|
|
|
139
142
|
|
|
140
143
|
observer = ObserverType(os.getenv("VECTARA_AGENTIC_OBSERVER_TYPE", "NO_OBSERVER"))
|
|
141
144
|
if observer == ObserverType.ARIZE_PHOENIX:
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
if os.environ.get("OTEL_EXPORTER_OTLP_HEADERS", None):
|
|
146
|
+
set_global_handler("arize_phoenix", endpoint="https://llamatrace.com/v1/traces")
|
|
147
|
+
print("Arize Phoenix observer set. https://llamatrace.com")
|
|
148
|
+
else:
|
|
149
|
+
px.launch_app()
|
|
150
|
+
set_global_handler("arize_phoenix", endpoint="http://localhost:6006/v1/traces")
|
|
151
|
+
print("Arize Phoenix observer set. http://localhost:6006/.")
|
|
144
152
|
else:
|
|
145
153
|
print("No observer set.")
|
|
146
154
|
|
|
@@ -174,11 +182,11 @@ class Agent:
|
|
|
174
182
|
def from_corpus(
|
|
175
183
|
cls,
|
|
176
184
|
tool_name: str,
|
|
177
|
-
vectara_customer_id: str,
|
|
178
|
-
vectara_corpus_id: str,
|
|
179
|
-
vectara_api_key: str,
|
|
180
185
|
data_description: str,
|
|
181
186
|
assistant_specialty: str,
|
|
187
|
+
vectara_customer_id: str = str(os.environ.get("VECTARA_CUSTOMER_ID", "")),
|
|
188
|
+
vectara_corpus_id: str = str(os.environ.get("VECTARA_CORPUS_ID", "")),
|
|
189
|
+
vectara_api_key: str = str(os.environ.get("VECTARA_API_KEY", "")),
|
|
182
190
|
verbose: bool = False,
|
|
183
191
|
vectara_filter_fields: list[dict] = [],
|
|
184
192
|
vectara_lambda_val: float = 0.005,
|
vectara_agentic/tools.py
CHANGED
|
@@ -5,6 +5,7 @@ This module contains the ToolsFactory class for creating agent tools.
|
|
|
5
5
|
import inspect
|
|
6
6
|
import re
|
|
7
7
|
import importlib
|
|
8
|
+
import os
|
|
8
9
|
|
|
9
10
|
from typing import Callable, List, Any, Optional, Type
|
|
10
11
|
from pydantic import BaseModel, Field
|
|
@@ -94,9 +95,9 @@ class VectaraToolFactory:
|
|
|
94
95
|
|
|
95
96
|
def __init__(
|
|
96
97
|
self,
|
|
97
|
-
vectara_customer_id: str,
|
|
98
|
-
vectara_corpus_id: str,
|
|
99
|
-
vectara_api_key: str,
|
|
98
|
+
vectara_customer_id: str = str(os.environ.get("VECTARA_CUSTOMER_ID", "")),
|
|
99
|
+
vectara_corpus_id: str = str(os.environ.get("VECTARA_CORPUS_ID", "")),
|
|
100
|
+
vectara_api_key: str = str(os.environ.get("VECTARA_API_KEY", "")),
|
|
100
101
|
) -> None:
|
|
101
102
|
"""
|
|
102
103
|
Initialize the VectaraToolFactory
|
|
@@ -154,6 +155,7 @@ class VectaraToolFactory:
|
|
|
154
155
|
vectara_api_key=self.vectara_api_key,
|
|
155
156
|
vectara_customer_id=self.vectara_customer_id,
|
|
156
157
|
vectara_corpus_id=self.vectara_corpus_id,
|
|
158
|
+
x_source_str="vectara-agentic"
|
|
157
159
|
)
|
|
158
160
|
|
|
159
161
|
def _build_filter_string(kwargs):
|
|
@@ -233,17 +235,18 @@ class VectaraToolFactory:
|
|
|
233
235
|
raw_output={'response': msg}
|
|
234
236
|
)
|
|
235
237
|
|
|
236
|
-
|
|
237
238
|
res = {
|
|
238
239
|
"response": response.response,
|
|
239
240
|
"references_metadata": citation_metadata,
|
|
240
241
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
242
|
+
if len(citation_metadata) > 0:
|
|
243
|
+
tool_output = f"""
|
|
244
|
+
Response: '''{res['response']}'''
|
|
245
|
+
References:
|
|
246
|
+
{res['references_metadata']}
|
|
247
|
+
"""
|
|
248
|
+
else:
|
|
249
|
+
tool_output = f"Response: '''{res['response']}'''"
|
|
247
250
|
out = ToolOutput(
|
|
248
251
|
tool_name=rag_function.__name__,
|
|
249
252
|
content=tool_output,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vectara_agentic
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.9
|
|
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
|
|
@@ -31,6 +31,7 @@ Requires-Dist: llama-index-tools-arxiv ==0.2.0
|
|
|
31
31
|
Requires-Dist: llama-index-tools-database ==0.2.0
|
|
32
32
|
Requires-Dist: llama-index-tools-google ==0.2.0
|
|
33
33
|
Requires-Dist: llama-index-tools-tavily-research ==0.2.0
|
|
34
|
+
Requires-Dist: llama-index-callbacks-arize-phoenix ==0.2.1
|
|
34
35
|
Requires-Dist: pydantic ==2.8.2
|
|
35
36
|
Requires-Dist: retrying ==1.3.4
|
|
36
37
|
Requires-Dist: pymongo ==4.6.1
|
|
@@ -63,7 +64,7 @@ Requires-Dist: tiktoken ==0.7.0
|
|
|
63
64
|
- [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)
|
|
64
65
|
- A Vectara corpus with an [API key](https://docs.vectara.com/docs/api-keys)
|
|
65
66
|
- [Python 3.10 or higher](https://www.python.org/downloads/)
|
|
66
|
-
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Cohere
|
|
67
|
+
- OpenAI API key (or API keys for Anthropic, TOGETHER.AI, Fireworks AI, Cohere or GROQ)
|
|
67
68
|
|
|
68
69
|
## Installation
|
|
69
70
|
|
|
@@ -181,6 +182,25 @@ The `Agent` class defines a few helpful methods to help you understand the inter
|
|
|
181
182
|
* The `report()` method prints out the agent object’s type, the tools, and the LLMs used for the main agent and tool calling.
|
|
182
183
|
* 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.
|
|
183
184
|
|
|
185
|
+
## Observability
|
|
186
|
+
|
|
187
|
+
vectara-agentic supports observability via the existing integration of LlamaIndex and Arize Phoenix.
|
|
188
|
+
To enable tracing of your vectara-agentic assistant, follow these steps (adapted from [here](https://docs.llamaindex.ai/en/stable/module_guides/observability/)):
|
|
189
|
+
1. Go to `https://llamatrace.com/login` an create an account, then create an API key and put it in the `PHOENIX_API_KEY` variable
|
|
190
|
+
2. `os["VECTARA_AGENTIC_OBSERVER_TYPE"] = "ARIZE_PHOENIX"`: to enable Arize Phoenix observability
|
|
191
|
+
3. `os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"api_key={PHOENIX_API_KEY}"`
|
|
192
|
+
|
|
193
|
+
Now when you run your agent, all metrics are sent to LlamaTrace and recorded. You can view them at `https://llamatrace.com`.
|
|
194
|
+
If you do not include the `OTEL_EXPORTER_OTLP_HEADERS` a local instance of Arize Phoenix will be setup instead and you can view it at `http://localhost:6006`
|
|
195
|
+
|
|
196
|
+
## About Custom Instructions
|
|
197
|
+
|
|
198
|
+
The custom instructions you provide to the agent guide its behavior.
|
|
199
|
+
Here are some guidelines when creating your instructions:
|
|
200
|
+
- Write precise and clear instructions, without overcomplicating.
|
|
201
|
+
- Consider edge cases and unusual or atypical scenarios.
|
|
202
|
+
- 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.
|
|
203
|
+
|
|
184
204
|
## Examples
|
|
185
205
|
|
|
186
206
|
Check out our example AI assistants:
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
vectara_agentic/__init__.py,sha256=G3eYLCGcu_y5lIBFLyoRX6wzdIYwT8GHtR4iz7YkG08,448
|
|
2
|
+
vectara_agentic/_callback.py,sha256=_o8XK1gBmsqpsJACAdJtbtnOnhLe6ZbGahCgb3WMuJQ,3674
|
|
3
|
+
vectara_agentic/_prompts.py,sha256=UV03GBdz0LplkyOacJyBLbrBpWSqUS7iRtM5xmJ0BVU,4572
|
|
4
|
+
vectara_agentic/agent.py,sha256=tcmrXDXX-c2XJgdul4HqfAxprE_25auoIFNrm0QUzC0,12810
|
|
5
|
+
vectara_agentic/tools.py,sha256=huien0lZfXtk4XPQZQ0QW5JN5QnW3Y8XvMB5n6qqtks,18065
|
|
6
|
+
vectara_agentic/tools_catalog.py,sha256=RByoXkF1GhY0rPQGLIeiqQo-j7o1h3lA6KY55ZM9mGg,4448
|
|
7
|
+
vectara_agentic/types.py,sha256=lTL3Is5W7IFyTKuEKu_VKaAsmVFVzKss_y184ayLti8,1080
|
|
8
|
+
vectara_agentic/utils.py,sha256=x8nBncooXHm6gXH-A77TRVzoPGoGleO5VeYi2fVRAA4,3340
|
|
9
|
+
vectara_agentic-0.1.9.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
10
|
+
vectara_agentic-0.1.9.dist-info/METADATA,sha256=fiS_NtQVOr2uAw-IDZLpIrxi7_7QnXCAOIGz8c8c6VE,10624
|
|
11
|
+
vectara_agentic-0.1.9.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
12
|
+
vectara_agentic-0.1.9.dist-info/top_level.txt,sha256=qT7JB9Xz7byehzlPd_rY4WWEAvPMhs63WMWgPsFthxU,16
|
|
13
|
+
vectara_agentic-0.1.9.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
vectara_agentic/__init__.py,sha256=qTixMQRPaRskeYlbYekridToyBvm5AN3ptDPATgwYlo,448
|
|
2
|
-
vectara_agentic/_callback.py,sha256=_o8XK1gBmsqpsJACAdJtbtnOnhLe6ZbGahCgb3WMuJQ,3674
|
|
3
|
-
vectara_agentic/_prompts.py,sha256=hoNiZLHDIuejunLkzXFcK562KFqGt60McoxU0BTkvgU,4461
|
|
4
|
-
vectara_agentic/agent.py,sha256=rNB3nr_RZWVkiz6xZvTRdfFKtu3sUOxjze284d6yFjw,12195
|
|
5
|
-
vectara_agentic/tools.py,sha256=GmGSpncxSwwBR-LHaG7XrVHVoGxQlveAjRQRArgD3Pk,17725
|
|
6
|
-
vectara_agentic/tools_catalog.py,sha256=RByoXkF1GhY0rPQGLIeiqQo-j7o1h3lA6KY55ZM9mGg,4448
|
|
7
|
-
vectara_agentic/types.py,sha256=lTL3Is5W7IFyTKuEKu_VKaAsmVFVzKss_y184ayLti8,1080
|
|
8
|
-
vectara_agentic/utils.py,sha256=x8nBncooXHm6gXH-A77TRVzoPGoGleO5VeYi2fVRAA4,3340
|
|
9
|
-
vectara_agentic-0.1.8.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
10
|
-
vectara_agentic-0.1.8.dist-info/METADATA,sha256=4WjHI_D1V9IAuG8REULeELHc-0SZEsETHmgGKqldiyE,9273
|
|
11
|
-
vectara_agentic-0.1.8.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
12
|
-
vectara_agentic-0.1.8.dist-info/top_level.txt,sha256=qT7JB9Xz7byehzlPd_rY4WWEAvPMhs63WMWgPsFthxU,16
|
|
13
|
-
vectara_agentic-0.1.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|