vectara-agentic 0.2.13__py3-none-any.whl → 0.2.14__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.
Potentially problematic release.
This version of vectara-agentic might be problematic. Click here for more details.
- tests/test_groq.py +120 -0
- tests/test_tools.py +41 -5
- tests/test_vectara_llms.py +0 -11
- vectara_agentic/_version.py +1 -1
- vectara_agentic/agent.py +65 -1
- vectara_agentic/llm_utils.py +174 -0
- vectara_agentic/tool_utils.py +513 -0
- vectara_agentic/tools.py +23 -471
- vectara_agentic/tools_catalog.py +2 -1
- vectara_agentic/utils.py +0 -153
- {vectara_agentic-0.2.13.dist-info → vectara_agentic-0.2.14.dist-info}/METADATA +25 -11
- {vectara_agentic-0.2.13.dist-info → vectara_agentic-0.2.14.dist-info}/RECORD +15 -12
- {vectara_agentic-0.2.13.dist-info → vectara_agentic-0.2.14.dist-info}/WHEEL +1 -1
- {vectara_agentic-0.2.13.dist-info → vectara_agentic-0.2.14.dist-info}/licenses/LICENSE +0 -0
- {vectara_agentic-0.2.13.dist-info → vectara_agentic-0.2.14.dist-info}/top_level.txt +0 -0
vectara_agentic/utils.py
CHANGED
|
@@ -2,164 +2,11 @@
|
|
|
2
2
|
Utilities for the Vectara agentic.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from typing import Tuple, Callable, Optional
|
|
6
|
-
from functools import lru_cache
|
|
7
5
|
from inspect import signature
|
|
8
6
|
import json
|
|
9
7
|
import asyncio
|
|
10
|
-
import tiktoken
|
|
11
8
|
import aiohttp
|
|
12
9
|
|
|
13
|
-
from llama_index.core.llms import LLM
|
|
14
|
-
from llama_index.llms.openai import OpenAI
|
|
15
|
-
from llama_index.llms.anthropic import Anthropic
|
|
16
|
-
|
|
17
|
-
from .types import LLMRole, AgentType, ModelProvider
|
|
18
|
-
from .agent_config import AgentConfig
|
|
19
|
-
|
|
20
|
-
provider_to_default_model_name = {
|
|
21
|
-
ModelProvider.OPENAI: "gpt-4o",
|
|
22
|
-
ModelProvider.ANTHROPIC: "claude-3-7-sonnet-latest",
|
|
23
|
-
ModelProvider.TOGETHER: "Qwen/Qwen2.5-72B-Instruct-Turbo",
|
|
24
|
-
ModelProvider.GROQ: "meta-llama/llama-4-scout-17b-16e-instruct",
|
|
25
|
-
ModelProvider.FIREWORKS: "accounts/fireworks/models/firefunction-v2",
|
|
26
|
-
ModelProvider.BEDROCK: "anthropic.claude-3-7-sonnet-20250219-v1:0",
|
|
27
|
-
ModelProvider.COHERE: "command-a-03-2025",
|
|
28
|
-
ModelProvider.GEMINI: "models/gemini-2.0-flash",
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
DEFAULT_MODEL_PROVIDER = ModelProvider.OPENAI
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@lru_cache(maxsize=None)
|
|
35
|
-
def _get_llm_params_for_role(
|
|
36
|
-
role: LLMRole, config: Optional[AgentConfig] = None
|
|
37
|
-
) -> Tuple[ModelProvider, str]:
|
|
38
|
-
"""
|
|
39
|
-
Get the model provider and model name for the specified role.
|
|
40
|
-
|
|
41
|
-
If config is None, a new AgentConfig() is instantiated using environment defaults.
|
|
42
|
-
"""
|
|
43
|
-
config = config or AgentConfig() # fallback to default config
|
|
44
|
-
|
|
45
|
-
if role == LLMRole.TOOL:
|
|
46
|
-
model_provider = ModelProvider(config.tool_llm_provider)
|
|
47
|
-
# If the user hasn’t explicitly set a tool_llm_model_name,
|
|
48
|
-
# fallback to provider default from provider_to_default_model_name
|
|
49
|
-
model_name = config.tool_llm_model_name or provider_to_default_model_name.get(
|
|
50
|
-
model_provider
|
|
51
|
-
)
|
|
52
|
-
else:
|
|
53
|
-
model_provider = ModelProvider(config.main_llm_provider)
|
|
54
|
-
model_name = config.main_llm_model_name or provider_to_default_model_name.get(
|
|
55
|
-
model_provider
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
# If the agent type is OpenAI, check that the main LLM provider is also OpenAI.
|
|
59
|
-
if role == LLMRole.MAIN and config.agent_type == AgentType.OPENAI:
|
|
60
|
-
if model_provider != ModelProvider.OPENAI:
|
|
61
|
-
raise ValueError(
|
|
62
|
-
"OpenAI agent requested but main model provider is not OpenAI."
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
return model_provider, model_name
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
@lru_cache(maxsize=None)
|
|
69
|
-
def get_tokenizer_for_model(
|
|
70
|
-
role: LLMRole, config: Optional[AgentConfig] = None
|
|
71
|
-
) -> Optional[Callable]:
|
|
72
|
-
"""
|
|
73
|
-
Get the tokenizer for the specified model, as determined by the role & config.
|
|
74
|
-
"""
|
|
75
|
-
model_provider, model_name = _get_llm_params_for_role(role, config)
|
|
76
|
-
if model_provider == ModelProvider.OPENAI:
|
|
77
|
-
# This might raise an exception if the model_name is unknown to tiktoken
|
|
78
|
-
return tiktoken.encoding_for_model(model_name).encode
|
|
79
|
-
if model_provider == ModelProvider.ANTHROPIC:
|
|
80
|
-
return Anthropic().tokenizer
|
|
81
|
-
return None
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
@lru_cache(maxsize=None)
|
|
85
|
-
def get_llm(role: LLMRole, config: Optional[AgentConfig] = None) -> LLM:
|
|
86
|
-
"""
|
|
87
|
-
Get the LLM for the specified role, using the provided config
|
|
88
|
-
or a default if none is provided.
|
|
89
|
-
"""
|
|
90
|
-
max_tokens = 8192
|
|
91
|
-
model_provider, model_name = _get_llm_params_for_role(role, config)
|
|
92
|
-
if model_provider == ModelProvider.OPENAI:
|
|
93
|
-
llm = OpenAI(
|
|
94
|
-
model=model_name,
|
|
95
|
-
temperature=0,
|
|
96
|
-
is_function_calling_model=True,
|
|
97
|
-
strict=True,
|
|
98
|
-
max_tokens=max_tokens,
|
|
99
|
-
pydantic_program_mode="openai",
|
|
100
|
-
)
|
|
101
|
-
elif model_provider == ModelProvider.ANTHROPIC:
|
|
102
|
-
llm = Anthropic(
|
|
103
|
-
model=model_name,
|
|
104
|
-
temperature=0,
|
|
105
|
-
max_tokens=max_tokens,
|
|
106
|
-
)
|
|
107
|
-
elif model_provider == ModelProvider.GEMINI:
|
|
108
|
-
from llama_index.llms.gemini import Gemini
|
|
109
|
-
|
|
110
|
-
llm = Gemini(
|
|
111
|
-
model=model_name,
|
|
112
|
-
temperature=0,
|
|
113
|
-
is_function_calling_model=True,
|
|
114
|
-
allow_parallel_tool_calls=True,
|
|
115
|
-
max_tokens=max_tokens,
|
|
116
|
-
)
|
|
117
|
-
elif model_provider == ModelProvider.TOGETHER:
|
|
118
|
-
from llama_index.llms.together import TogetherLLM
|
|
119
|
-
|
|
120
|
-
llm = TogetherLLM(
|
|
121
|
-
model=model_name,
|
|
122
|
-
temperature=0,
|
|
123
|
-
is_function_calling_model=True,
|
|
124
|
-
max_tokens=max_tokens,
|
|
125
|
-
)
|
|
126
|
-
elif model_provider == ModelProvider.GROQ:
|
|
127
|
-
from llama_index.llms.groq import Groq
|
|
128
|
-
|
|
129
|
-
llm = Groq(
|
|
130
|
-
model=model_name,
|
|
131
|
-
temperature=0,
|
|
132
|
-
is_function_calling_model=True,
|
|
133
|
-
max_tokens=max_tokens,
|
|
134
|
-
)
|
|
135
|
-
elif model_provider == ModelProvider.FIREWORKS:
|
|
136
|
-
from llama_index.llms.fireworks import Fireworks
|
|
137
|
-
|
|
138
|
-
llm = Fireworks(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
139
|
-
elif model_provider == ModelProvider.BEDROCK:
|
|
140
|
-
from llama_index.llms.bedrock import Bedrock
|
|
141
|
-
|
|
142
|
-
llm = Bedrock(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
143
|
-
elif model_provider == ModelProvider.COHERE:
|
|
144
|
-
from llama_index.llms.cohere import Cohere
|
|
145
|
-
|
|
146
|
-
llm = Cohere(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
147
|
-
elif model_provider == ModelProvider.PRIVATE:
|
|
148
|
-
from llama_index.llms.openai_like import OpenAILike
|
|
149
|
-
|
|
150
|
-
llm = OpenAILike(
|
|
151
|
-
model=model_name,
|
|
152
|
-
temperature=0,
|
|
153
|
-
is_function_calling_model=True,
|
|
154
|
-
is_chat_model=True,
|
|
155
|
-
api_base=config.private_llm_api_base,
|
|
156
|
-
api_key=config.private_llm_api_key,
|
|
157
|
-
max_tokens=max_tokens,
|
|
158
|
-
)
|
|
159
|
-
else:
|
|
160
|
-
raise ValueError(f"Unknown LLM provider: {model_provider}")
|
|
161
|
-
return llm
|
|
162
|
-
|
|
163
10
|
|
|
164
11
|
def is_float(value: str) -> bool:
|
|
165
12
|
"""Check if a string can be converted to a float."""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vectara_agentic
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.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
|
|
@@ -16,18 +16,18 @@ 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.
|
|
20
|
-
Requires-Dist: llama-index-indices-managed-vectara==0.4.
|
|
19
|
+
Requires-Dist: llama-index==0.12.33
|
|
20
|
+
Requires-Dist: llama-index-indices-managed-vectara==0.4.4
|
|
21
21
|
Requires-Dist: llama-index-agent-llm-compiler==0.3.0
|
|
22
22
|
Requires-Dist: llama-index-agent-lats==0.3.0
|
|
23
23
|
Requires-Dist: llama-index-agent-openai==0.4.6
|
|
24
|
-
Requires-Dist: llama-index-llms-openai==0.3.
|
|
24
|
+
Requires-Dist: llama-index-llms-openai==0.3.38
|
|
25
25
|
Requires-Dist: llama-index-llms-anthropic==0.6.10
|
|
26
26
|
Requires-Dist: llama-index-llms-together==0.3.1
|
|
27
27
|
Requires-Dist: llama-index-llms-groq==0.3.1
|
|
28
28
|
Requires-Dist: llama-index-llms-fireworks==0.3.2
|
|
29
29
|
Requires-Dist: llama-index-llms-cohere==0.4.1
|
|
30
|
-
Requires-Dist: llama-index-llms-
|
|
30
|
+
Requires-Dist: llama-index-llms-google-genai==0.1.8
|
|
31
31
|
Requires-Dist: llama-index-llms-bedrock==0.3.8
|
|
32
32
|
Requires-Dist: llama-index-tools-yahoo-finance==0.3.0
|
|
33
33
|
Requires-Dist: llama-index-tools-arxiv==0.3.0
|
|
@@ -49,7 +49,7 @@ Requires-Dist: arize-phoenix==8.26.1
|
|
|
49
49
|
Requires-Dist: arize-phoenix-otel==0.9.2
|
|
50
50
|
Requires-Dist: protobuf==5.29.3
|
|
51
51
|
Requires-Dist: tokenizers>=0.20
|
|
52
|
-
Requires-Dist: pydantic==2.
|
|
52
|
+
Requires-Dist: pydantic==2.11.3
|
|
53
53
|
Requires-Dist: retrying==1.3.4
|
|
54
54
|
Requires-Dist: python-dotenv==1.0.1
|
|
55
55
|
Requires-Dist: tiktoken==0.9.0
|
|
@@ -292,13 +292,12 @@ For example, in the quickstart example the schema is:
|
|
|
292
292
|
|
|
293
293
|
```python
|
|
294
294
|
class QueryFinancialReportsArgs(BaseModel):
|
|
295
|
-
query: str = Field(..., description="The user query.")
|
|
296
295
|
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').")
|
|
297
296
|
ticker: str = Field(..., description=f"The company ticker. Must be a valid ticket symbol from the list {tickers.keys()}.")
|
|
298
297
|
```
|
|
299
298
|
|
|
300
|
-
|
|
301
|
-
|
|
299
|
+
Remember, the `query` argument is part of the rag_tool that is generated, but `vectara-agentic` creates it and you do
|
|
300
|
+
not need to specify it explicitly.
|
|
302
301
|
|
|
303
302
|
For example, in the example above, the agent may call the `query_financial_reports_tool` tool with
|
|
304
303
|
query='what is the revenue?', year=2022 and ticker='AAPL'. Subsequently the RAG tool will issue
|
|
@@ -483,13 +482,28 @@ class MyWorkflow(Workflow):
|
|
|
483
482
|
return StopEvent(result="Hello, world!")
|
|
484
483
|
```
|
|
485
484
|
|
|
486
|
-
When the `run()` method in vectara-agentic is invoked, it calls the workflow with the following variables in the StartEvent
|
|
485
|
+
When the `run()` method in vectara-agentic is invoked, it calls the workflow with the following variables in the `StartEvent`:
|
|
487
486
|
* `agent`: the agent object used to call `run()` (self)
|
|
488
487
|
* `tools`: the tools provided to the agent. Those can be used as needed in the flow.
|
|
489
488
|
* `llm`: a pointer to a LlamaIndex llm, so it can be used in the workflow. For example, one of the steps may call `llm.acomplete(prompt)`
|
|
490
489
|
* `verbose`: controls whether extra debug information is displayed
|
|
491
490
|
* `inputs`: this is the actual inputs to the workflow provided by the call to `run()` and must be of type `InputsModel`
|
|
492
491
|
|
|
492
|
+
If you want to use `agent`, `tools`, `llm` or `verbose` in other events (that are not `StartEvent`), you can store them in
|
|
493
|
+
the `Context` of the Workflow as follows:
|
|
494
|
+
|
|
495
|
+
```python
|
|
496
|
+
await ctx.set("agent", ev.agent)
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
and then in any other event you can pull that agent object with
|
|
500
|
+
|
|
501
|
+
```python
|
|
502
|
+
agent = await ctx.get("agent")
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
Similarly you can reuse the `llm`, `tools` or `verbose` arguments within other nodes in the workflow.
|
|
506
|
+
|
|
493
507
|
### Using the Workflow with Your Agent
|
|
494
508
|
|
|
495
509
|
When initializing your agent, pass the workflow class using the `workflow_cls` parameter:
|
|
@@ -521,7 +535,7 @@ print(workflow_result.answer)
|
|
|
521
535
|
|
|
522
536
|
### Built-in Workflows
|
|
523
537
|
|
|
524
|
-
`vectara-agentic` includes two
|
|
538
|
+
`vectara-agentic` includes two workflow implementations that you can use right away:
|
|
525
539
|
|
|
526
540
|
#### 1. `SubQuestionQueryWorkflow`
|
|
527
541
|
|
|
@@ -4,27 +4,30 @@ tests/test_agent.py,sha256=nkg3SefST9Q-38Ys9yLJZr2RN6FxeXonMGj7uRCsta8,5482
|
|
|
4
4
|
tests/test_agent_planning.py,sha256=r_Qk63aK6gAzIluv3X6CLCNIbE1ExWJEUIkvoI6U7RE,2213
|
|
5
5
|
tests/test_agent_type.py,sha256=mWo-pTQNDj4fWFPETm5jnb7Y5N48aW35keTVvxdIaCc,7173
|
|
6
6
|
tests/test_fallback.py,sha256=M5YD7NHZ0joVU1frYIr9_OiRAIje5mrXrYVcekzlyGs,2829
|
|
7
|
+
tests/test_groq.py,sha256=0FFnQ91o9UjOIAIe_JMxyBl4dz_38RRbl00j9dFudMs,4170
|
|
7
8
|
tests/test_private_llm.py,sha256=CY-_rCpxGUuxnZ3ypkodw5Jj-sJCNdh6rLbCvULwuJI,2247
|
|
8
9
|
tests/test_serialization.py,sha256=Ed23GN2zhSJNdPFrVK4aqLkOhJKviczR_o0t-r9TuRI,4762
|
|
9
|
-
tests/test_tools.py,sha256=
|
|
10
|
-
tests/test_vectara_llms.py,sha256=
|
|
10
|
+
tests/test_tools.py,sha256=b90pbLHEqjbtfiCVDOsYCwUCJXTEE-jIu5WuA8r6Yg8,11920
|
|
11
|
+
tests/test_vectara_llms.py,sha256=wpDFOuExoUqRwqH7Ikhb8mVmkq1e85m2p1fMMFF2_GE,2298
|
|
11
12
|
tests/test_workflow.py,sha256=lVyrVHdRO5leYNbYtHTmKqMX0c8_xehCpUA7cXQKVsc,2175
|
|
12
13
|
vectara_agentic/__init__.py,sha256=2GLDS3U6KckK-dBRl9v_x1kSV507gEhjOfuMmmu0Qxg,850
|
|
13
14
|
vectara_agentic/_callback.py,sha256=ron49t1t-ox-736WaXzrZ99vhN4NI9bMiHFyj0iIPqg,13062
|
|
14
15
|
vectara_agentic/_observability.py,sha256=BA2zhwa5930aaDUJxHefPlmIPt8kZOuLHVBc9PtYNuU,3839
|
|
15
16
|
vectara_agentic/_prompts.py,sha256=8d5gaaY_OrNVDlGqb7cqIZq0WnK5RY7yVa8LgHDjbhA,9508
|
|
16
|
-
vectara_agentic/_version.py,sha256=
|
|
17
|
-
vectara_agentic/agent.py,sha256=
|
|
17
|
+
vectara_agentic/_version.py,sha256=yDIvGWQ2X4m-Tnp9W4synsKkQknhptDZf8ZdOLb-NJ8,66
|
|
18
|
+
vectara_agentic/agent.py,sha256=v6LdfDckGtcUomxiTsIsslBqJCW2eOApEwK67f6AWVw,50283
|
|
18
19
|
vectara_agentic/agent_config.py,sha256=E-rtYMcpoGxnEAyy8231bizo2n0uGQ2qWxuSgTEfwdQ,4327
|
|
19
20
|
vectara_agentic/agent_endpoint.py,sha256=QIMejCLlpW2qzXxeDAxv3anF46XMDdVMdKGWhJh3azY,1996
|
|
20
21
|
vectara_agentic/db_tools.py,sha256=bAgqQMrpmu7KBaiAjJ4tpH8JwsFGEDk8iru5Deu0SEk,11179
|
|
22
|
+
vectara_agentic/llm_utils.py,sha256=Isf1d9K4Jpn-IwMZn-liPUTEF-bpiqp0XIiNRohtwTQ,6152
|
|
21
23
|
vectara_agentic/sub_query_workflow.py,sha256=xjySd2qjLAKwK6XuS0R0PTyk2uXraHCgCbDP1xDoFVI,12175
|
|
22
|
-
vectara_agentic/
|
|
23
|
-
vectara_agentic/
|
|
24
|
+
vectara_agentic/tool_utils.py,sha256=e3hSOblo5voDfY8tmNdKS9UCeq1jt24BMLPKuHB2UgE,18056
|
|
25
|
+
vectara_agentic/tools.py,sha256=qg103AizNYO1p7i_ZZGFwkmJj5FNdtHB4cgcvcxwDIE,32387
|
|
26
|
+
vectara_agentic/tools_catalog.py,sha256=s0tjmXAp-0wttRKy5QpWhYFBW-D6KNWbcARWLYVdEVo,4840
|
|
24
27
|
vectara_agentic/types.py,sha256=HcS7vR8P2v2xQTlOc6ZFV2vvlr3OpzSNWhtcLMxqUZc,1792
|
|
25
|
-
vectara_agentic/utils.py,sha256=
|
|
26
|
-
vectara_agentic-0.2.
|
|
27
|
-
vectara_agentic-0.2.
|
|
28
|
-
vectara_agentic-0.2.
|
|
29
|
-
vectara_agentic-0.2.
|
|
30
|
-
vectara_agentic-0.2.
|
|
28
|
+
vectara_agentic/utils.py,sha256=q14S8nm3UFFI3ksk-xszd9xgFrtXdIt_tdRiBMFjaa0,2529
|
|
29
|
+
vectara_agentic-0.2.14.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
30
|
+
vectara_agentic-0.2.14.dist-info/METADATA,sha256=agfZoMDE5zechuOTmlEiK-NLudqxDRKAdIvp2ngryOw,28114
|
|
31
|
+
vectara_agentic-0.2.14.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
|
32
|
+
vectara_agentic-0.2.14.dist-info/top_level.txt,sha256=Y7TQTFdOYGYodQRltUGRieZKIYuzeZj2kHqAUpfCUfg,22
|
|
33
|
+
vectara_agentic-0.2.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|