vectara-agentic 0.2.14__py3-none-any.whl → 0.2.16__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_agent.py +2 -2
- tests/test_agent_planning.py +1 -1
- tests/test_groq.py +3 -1
- tests/test_return_direct.py +49 -0
- tests/test_tools.py +120 -18
- tests/test_vectara_llms.py +4 -1
- vectara_agentic/_observability.py +43 -21
- vectara_agentic/_prompts.py +5 -3
- vectara_agentic/_version.py +1 -1
- vectara_agentic/agent.py +114 -49
- vectara_agentic/db_tools.py +2 -2
- vectara_agentic/llm_utils.py +10 -6
- vectara_agentic/tool_utils.py +182 -133
- vectara_agentic/tools.py +19 -9
- vectara_agentic/tools_catalog.py +2 -1
- {vectara_agentic-0.2.14.dist-info → vectara_agentic-0.2.16.dist-info}/METADATA +5 -5
- vectara_agentic-0.2.16.dist-info/RECORD +34 -0
- {vectara_agentic-0.2.14.dist-info → vectara_agentic-0.2.16.dist-info}/WHEEL +1 -1
- vectara_agentic-0.2.14.dist-info/RECORD +0 -33
- {vectara_agentic-0.2.14.dist-info → vectara_agentic-0.2.16.dist-info}/licenses/LICENSE +0 -0
- {vectara_agentic-0.2.14.dist-info → vectara_agentic-0.2.16.dist-info}/top_level.txt +0 -0
vectara_agentic/tool_utils.py
CHANGED
|
@@ -7,7 +7,7 @@ import re
|
|
|
7
7
|
|
|
8
8
|
from typing import (
|
|
9
9
|
Callable, List, Dict, Any, Optional, Union, Type, Tuple,
|
|
10
|
-
Sequence
|
|
10
|
+
Sequence, get_origin, get_args
|
|
11
11
|
)
|
|
12
12
|
from pydantic import BaseModel, create_model
|
|
13
13
|
from pydantic_core import PydanticUndefined
|
|
@@ -140,37 +140,20 @@ class VectaraTool(FunctionTool):
|
|
|
140
140
|
return str(self)
|
|
141
141
|
|
|
142
142
|
def __eq__(self, other):
|
|
143
|
-
if not isinstance(other, VectaraTool):
|
|
144
|
-
return False
|
|
145
|
-
|
|
146
|
-
if self.metadata.tool_type != other.metadata.tool_type:
|
|
147
|
-
return False
|
|
148
|
-
|
|
149
|
-
if self.metadata.name != other.metadata.name:
|
|
150
|
-
return False
|
|
151
|
-
|
|
152
|
-
# If schema is a dict-like object, compare the dict representation
|
|
153
143
|
try:
|
|
154
144
|
# Try to get schema as dict if possible
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
other_schema = other.metadata.fn_schema.schema
|
|
158
|
-
|
|
159
|
-
# Compare only properties and required fields
|
|
160
|
-
self_props = self_schema.get("properties", {})
|
|
161
|
-
other_props = other_schema.get("properties", {})
|
|
162
|
-
|
|
163
|
-
self_required = self_schema.get("required", [])
|
|
164
|
-
other_required = other_schema.get("required", [])
|
|
165
|
-
|
|
166
|
-
return self_props.keys() == other_props.keys() and set(
|
|
167
|
-
self_required
|
|
168
|
-
) == set(other_required)
|
|
145
|
+
self_schema = self.metadata.fn_schema.model_json_schema()
|
|
146
|
+
other_schema = other.metadata.fn_schema.model_json_schema()
|
|
169
147
|
except Exception:
|
|
170
|
-
|
|
171
|
-
pass
|
|
148
|
+
return False
|
|
172
149
|
|
|
173
|
-
|
|
150
|
+
is_equal = (
|
|
151
|
+
isinstance(other, VectaraTool)
|
|
152
|
+
and self.metadata.tool_type == other.metadata.tool_type
|
|
153
|
+
and self.metadata.name == other.metadata.name
|
|
154
|
+
and self_schema == other_schema
|
|
155
|
+
)
|
|
156
|
+
return is_equal
|
|
174
157
|
|
|
175
158
|
def call(
|
|
176
159
|
self, *args: Any, ctx: Optional[Context] = None, **kwargs: Any
|
|
@@ -185,7 +168,7 @@ class VectaraTool(FunctionTool):
|
|
|
185
168
|
err_output = ToolOutput(
|
|
186
169
|
tool_name=self.metadata.name,
|
|
187
170
|
content=(
|
|
188
|
-
f"Wrong argument used when calling {self.metadata.name}: {str(e)}.
|
|
171
|
+
f"Wrong argument used when calling {self.metadata.name}: {str(e)}."
|
|
189
172
|
f"Valid arguments: {params_str}. please call the tool again with the correct arguments."
|
|
190
173
|
),
|
|
191
174
|
raw_input={"args": args, "kwargs": kwargs},
|
|
@@ -222,74 +205,188 @@ class VectaraTool(FunctionTool):
|
|
|
222
205
|
)
|
|
223
206
|
return err_output
|
|
224
207
|
except Exception as e:
|
|
208
|
+
import traceback
|
|
225
209
|
err_output = ToolOutput(
|
|
226
210
|
tool_name=self.metadata.name,
|
|
227
|
-
content=f"Tool {self.metadata.name} Malfunction: {str(e)}",
|
|
211
|
+
content=f"Tool {self.metadata.name} Malfunction: {str(e)}, traceback: {traceback.format_exc()}",
|
|
228
212
|
raw_input={"args": args, "kwargs": kwargs},
|
|
229
213
|
raw_output={"response": str(e)},
|
|
230
214
|
)
|
|
231
215
|
return err_output
|
|
232
216
|
|
|
233
217
|
|
|
234
|
-
|
|
218
|
+
class EmptyBaseModel(BaseModel):
|
|
219
|
+
"""empty base model"""
|
|
220
|
+
|
|
221
|
+
def _clean_type_repr(type_repr: str) -> str:
|
|
222
|
+
"""Cleans the string representation of a type."""
|
|
223
|
+
# Replace <class 'somename'> with somename
|
|
224
|
+
match = re.match(r"<class '(\w+)'>", type_repr)
|
|
225
|
+
if match:
|
|
226
|
+
type_repr = match.group(1)
|
|
227
|
+
|
|
228
|
+
type_repr = type_repr.replace("typing.", "")
|
|
229
|
+
return type_repr
|
|
230
|
+
|
|
231
|
+
def _format_type(annotation) -> str:
|
|
232
|
+
"""
|
|
233
|
+
Turn things like Union[int, str, NoneType] into 'int | str | None',
|
|
234
|
+
and replace any leftover 'NoneType' → 'None'.
|
|
235
|
+
"""
|
|
236
|
+
origin = get_origin(annotation)
|
|
237
|
+
if origin is Union:
|
|
238
|
+
parts = []
|
|
239
|
+
for arg in get_args(annotation):
|
|
240
|
+
if arg is type(None):
|
|
241
|
+
parts.append("None")
|
|
242
|
+
else:
|
|
243
|
+
# recurse in case of nested unions
|
|
244
|
+
parts.append(_format_type(arg))
|
|
245
|
+
return " | ".join(parts)
|
|
246
|
+
|
|
247
|
+
# Fallback
|
|
248
|
+
type_repr = str(annotation)
|
|
249
|
+
type_repr = _clean_type_repr(type_repr)
|
|
250
|
+
return type_repr.replace("NoneType", "None")
|
|
251
|
+
|
|
252
|
+
def _make_docstring(
|
|
253
|
+
function: Callable[..., ToolOutput],
|
|
254
|
+
tool_name: str,
|
|
255
|
+
tool_description: str,
|
|
256
|
+
fn_schema: Type[BaseModel],
|
|
257
|
+
all_params: List[inspect.Parameter],
|
|
258
|
+
compact_docstring: bool,
|
|
259
|
+
) -> str:
|
|
260
|
+
"""
|
|
261
|
+
Generates a docstring for a function based on its signature, description,
|
|
262
|
+
and Pydantic schema, correctly handling complex type annotations.
|
|
263
|
+
|
|
264
|
+
Args:
|
|
265
|
+
function: The function for which to generate the docstring.
|
|
266
|
+
tool_name: The desired name for the tool/function in the docstring.
|
|
267
|
+
tool_description: The main description of the tool/function.
|
|
268
|
+
fn_schema: The Pydantic model representing the function's arguments schema.
|
|
269
|
+
all_params: A list of inspect.Parameter objects for the function signature.
|
|
270
|
+
compact_docstring: If True, omits the signature line in the main description.
|
|
271
|
+
|
|
272
|
+
Returns:
|
|
273
|
+
A formatted docstring string.
|
|
274
|
+
"""
|
|
275
|
+
params_str_parts = []
|
|
276
|
+
for p in all_params:
|
|
277
|
+
type_repr = _format_type(p.annotation)
|
|
278
|
+
params_str_parts.append(f"{p.name}: {type_repr}")
|
|
279
|
+
|
|
280
|
+
params_str = ", ".join(params_str_parts)
|
|
281
|
+
signature_line = f"{tool_name}({params_str}) -> dict[str, Any]"
|
|
282
|
+
|
|
283
|
+
if compact_docstring:
|
|
284
|
+
doc_lines = [tool_description.strip()]
|
|
285
|
+
else:
|
|
286
|
+
doc_lines = [signature_line, "", tool_description.strip()]
|
|
287
|
+
|
|
288
|
+
full_schema = fn_schema.model_json_schema()
|
|
289
|
+
props = full_schema.get("properties", {})
|
|
290
|
+
|
|
291
|
+
if props:
|
|
292
|
+
doc_lines.extend(["", "Args:"])
|
|
293
|
+
for prop_name, schema_prop in props.items():
|
|
294
|
+
desc = schema_prop.get("description", "")
|
|
295
|
+
|
|
296
|
+
# pick up any examples you declared on the Field or via schema_extra
|
|
297
|
+
examples = schema_prop.get("examples", [])
|
|
298
|
+
default = schema_prop.get("default", PydanticUndefined)
|
|
299
|
+
|
|
300
|
+
# format the type, default, description, examples
|
|
301
|
+
# find the matching inspect.Parameter so you get its annotation
|
|
302
|
+
param = next((p for p in all_params if p.name == prop_name), None)
|
|
303
|
+
ty_str = ""
|
|
304
|
+
if param:
|
|
305
|
+
ty_str = _format_type(param.annotation)
|
|
306
|
+
elif "type" in schema_prop:
|
|
307
|
+
ty_info = schema_prop["type"]
|
|
308
|
+
if isinstance(ty_info, str):
|
|
309
|
+
ty_str = _clean_type_repr(ty_info)
|
|
310
|
+
elif isinstance(ty_info, list): # Handle JSON schema array type e.g., ["integer", "string"]
|
|
311
|
+
ty_str = " | ".join([_clean_type_repr(t) for t in ty_info])
|
|
312
|
+
|
|
313
|
+
# inline default if present
|
|
314
|
+
default_txt = f", default={default!r}" if default is not PydanticUndefined else ""
|
|
315
|
+
|
|
316
|
+
# inline examples if any
|
|
317
|
+
if examples:
|
|
318
|
+
examples_txt = ", ".join(repr(e) for e in examples)
|
|
319
|
+
desc = f"{desc} (e.g., {examples_txt})"
|
|
320
|
+
|
|
321
|
+
doc_lines.append(f" - {prop_name} ({ty_str}{default_txt}): {desc}")
|
|
322
|
+
|
|
323
|
+
doc_lines.append("")
|
|
324
|
+
doc_lines.append("Returns:")
|
|
325
|
+
return_desc = getattr(
|
|
326
|
+
function, "__return_description__", "A dictionary containing the result data."
|
|
327
|
+
)
|
|
328
|
+
doc_lines.append(f" dict[str, Any]: {return_desc}")
|
|
329
|
+
|
|
330
|
+
initial_docstring = "\n".join(doc_lines)
|
|
331
|
+
collapsed_spaces = re.sub(r' {2,}', ' ', initial_docstring)
|
|
332
|
+
final_docstring = re.sub(r'\n{2,}', '\n', collapsed_spaces).strip()
|
|
333
|
+
return final_docstring
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def create_tool_from_dynamic_function(
|
|
235
337
|
function: Callable[..., ToolOutput],
|
|
236
338
|
tool_name: str,
|
|
237
339
|
tool_description: str,
|
|
238
340
|
base_params_model: Type[BaseModel],
|
|
239
341
|
tool_args_schema: Type[BaseModel],
|
|
240
342
|
compact_docstring: bool = False,
|
|
343
|
+
return_direct: bool = False,
|
|
241
344
|
) -> VectaraTool:
|
|
242
|
-
|
|
243
|
-
|
|
345
|
+
"""
|
|
346
|
+
Create a VectaraTool from a dynamic function.
|
|
347
|
+
Args:
|
|
348
|
+
function (Callable[..., ToolOutput]): The function to wrap as a tool.
|
|
349
|
+
tool_name (str): The name of the tool.
|
|
350
|
+
tool_description (str): The description of the tool.
|
|
351
|
+
base_params_model (Type[BaseModel]): The Pydantic model for the base parameters.
|
|
352
|
+
tool_args_schema (Type[BaseModel]): The Pydantic model for the tool arguments.
|
|
353
|
+
compact_docstring (bool): Whether to use a compact docstring format.
|
|
354
|
+
Returns:
|
|
355
|
+
VectaraTool: The created VectaraTool.
|
|
356
|
+
"""
|
|
244
357
|
if tool_args_schema is None:
|
|
245
|
-
|
|
246
|
-
class EmptyBaseModel(BaseModel):
|
|
247
|
-
"""empty base model"""
|
|
248
|
-
|
|
249
358
|
tool_args_schema = EmptyBaseModel
|
|
250
359
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if model_field.default is not None
|
|
259
|
-
else inspect.Parameter.empty
|
|
260
|
-
)
|
|
360
|
+
if not isinstance(tool_args_schema, type) or not issubclass(tool_args_schema, BaseModel):
|
|
361
|
+
raise TypeError("tool_args_schema must be a Pydantic BaseModel subclass")
|
|
362
|
+
|
|
363
|
+
fields: Dict[str, Any] = {}
|
|
364
|
+
base_params = []
|
|
365
|
+
for field_name, field_info in base_params_model.model_fields.items():
|
|
366
|
+
default = Ellipsis if field_info.default is PydanticUndefined else field_info.default
|
|
261
367
|
param = inspect.Parameter(
|
|
262
|
-
|
|
368
|
+
field_name,
|
|
263
369
|
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
264
|
-
default=
|
|
265
|
-
annotation=
|
|
370
|
+
default=default if default is not Ellipsis else inspect.Parameter.empty,
|
|
371
|
+
annotation=field_info.annotation,
|
|
266
372
|
)
|
|
267
373
|
base_params.append(param)
|
|
268
|
-
fields[
|
|
269
|
-
field_type,
|
|
270
|
-
model_field.default if model_field.default is not None else ...,
|
|
271
|
-
)
|
|
374
|
+
fields[field_name] = (field_info.annotation, field_info)
|
|
272
375
|
|
|
273
376
|
# Add tool_args_schema fields to the fields dict if not already included.
|
|
274
|
-
# Also add them to the function signature by creating new inspect.Parameter objects.
|
|
275
377
|
for field_name, field_info in tool_args_schema.model_fields.items():
|
|
276
378
|
if field_name in fields:
|
|
277
379
|
continue
|
|
278
380
|
|
|
279
|
-
|
|
280
|
-
field_type = tool_args_schema.__annotations__.get(field_name, None)
|
|
281
|
-
fields[field_name] = (field_type, default_value)
|
|
381
|
+
default = Ellipsis if field_info.default is PydanticUndefined else field_info.default
|
|
282
382
|
param = inspect.Parameter(
|
|
283
383
|
field_name,
|
|
284
384
|
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
285
|
-
default=
|
|
286
|
-
|
|
287
|
-
if default_value is not ...
|
|
288
|
-
else inspect.Parameter.empty
|
|
289
|
-
),
|
|
290
|
-
annotation=field_type,
|
|
385
|
+
default=default if default is not Ellipsis else inspect.Parameter.empty,
|
|
386
|
+
annotation=field_info.annotation,
|
|
291
387
|
)
|
|
292
388
|
base_params.append(param)
|
|
389
|
+
fields[field_name] = (field_info.annotation, field_info)
|
|
293
390
|
|
|
294
391
|
# Create the dynamic schema with both base_params_model and tool_args_schema fields.
|
|
295
392
|
fn_schema = create_model(f"{tool_name}_schema", **fields)
|
|
@@ -304,94 +401,46 @@ def _create_tool_from_dynamic_function(
|
|
|
304
401
|
function.__annotations__["return"] = dict[str, Any]
|
|
305
402
|
function.__name__ = re.sub(r"[^A-Za-z0-9_]", "_", tool_name)
|
|
306
403
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
404
|
+
function.__doc__ = _make_docstring(
|
|
405
|
+
function,
|
|
406
|
+
tool_name, tool_description, fn_schema,
|
|
407
|
+
all_params, compact_docstring
|
|
311
408
|
)
|
|
312
|
-
signature_line = f"{tool_name}({params_str}) -> dict[str, Any]"
|
|
313
|
-
if compact_docstring:
|
|
314
|
-
doc_lines = [
|
|
315
|
-
tool_description.strip(),
|
|
316
|
-
]
|
|
317
|
-
else:
|
|
318
|
-
doc_lines = [
|
|
319
|
-
signature_line,
|
|
320
|
-
"",
|
|
321
|
-
tool_description.strip(),
|
|
322
|
-
]
|
|
323
|
-
doc_lines += [
|
|
324
|
-
"",
|
|
325
|
-
"Args:",
|
|
326
|
-
]
|
|
327
|
-
for param in all_params:
|
|
328
|
-
description = ""
|
|
329
|
-
if param.name in base_params_model.model_fields:
|
|
330
|
-
description = base_params_model.model_fields[param.name].description
|
|
331
|
-
elif param.name in tool_args_schema.model_fields:
|
|
332
|
-
description = tool_args_schema.model_fields[param.name].description
|
|
333
|
-
if not description:
|
|
334
|
-
description = ""
|
|
335
|
-
type_name = (
|
|
336
|
-
param.annotation.__name__
|
|
337
|
-
if hasattr(param.annotation, "__name__")
|
|
338
|
-
else str(param.annotation)
|
|
339
|
-
)
|
|
340
|
-
if (
|
|
341
|
-
param.default is not inspect.Parameter.empty
|
|
342
|
-
and param.default is not PydanticUndefined
|
|
343
|
-
):
|
|
344
|
-
default_text = f", default={param.default!r}"
|
|
345
|
-
else:
|
|
346
|
-
default_text = ""
|
|
347
|
-
doc_lines.append(f" - {param.name} ({type_name}){default_text}: {description}")
|
|
348
|
-
doc_lines.append("")
|
|
349
|
-
doc_lines.append("Returns:")
|
|
350
|
-
return_desc = getattr(
|
|
351
|
-
function, "__return_description__", "A dictionary containing the result data."
|
|
352
|
-
)
|
|
353
|
-
doc_lines.append(f" dict[str, Any]: {return_desc}")
|
|
354
|
-
|
|
355
|
-
initial_docstring = "\n".join(doc_lines)
|
|
356
|
-
collapsed_spaces = re.sub(r' {2,}', ' ', initial_docstring)
|
|
357
|
-
final_docstring = re.sub(r'\n{2,}', '\n', collapsed_spaces).strip()
|
|
358
|
-
function.__doc__ = final_docstring
|
|
359
|
-
|
|
360
409
|
tool = VectaraTool.from_defaults(
|
|
361
410
|
fn=function,
|
|
362
411
|
name=tool_name,
|
|
363
412
|
description=function.__doc__,
|
|
364
413
|
fn_schema=fn_schema,
|
|
365
414
|
tool_type=ToolType.QUERY,
|
|
415
|
+
return_direct=return_direct,
|
|
366
416
|
)
|
|
367
417
|
return tool
|
|
368
418
|
|
|
369
419
|
|
|
370
|
-
|
|
420
|
+
_PARSE_RANGE_REGEX = re.compile(
|
|
421
|
+
r"""
|
|
422
|
+
^([\[\(])\s* # opening bracket
|
|
423
|
+
([+-]?\d+(\.\d*)?)\s*, # first number
|
|
424
|
+
\s*([+-]?\d+(\.\d*)?) # second number
|
|
425
|
+
\s*([\]\)])$ # closing bracket
|
|
426
|
+
""",
|
|
427
|
+
re.VERBOSE,
|
|
428
|
+
)
|
|
371
429
|
|
|
372
430
|
|
|
373
|
-
def _parse_range(val_str: str) ->
|
|
431
|
+
def _parse_range(val_str: str) -> Tuple[str, str, bool, bool]:
|
|
374
432
|
"""
|
|
375
433
|
Parses '[1,10)' or '(0.5, 5]' etc.
|
|
376
434
|
Returns (start, end, start_incl, end_incl) or raises ValueError.
|
|
377
435
|
"""
|
|
378
|
-
m =
|
|
379
|
-
r"""
|
|
380
|
-
^([\[\(])\s* # opening bracket
|
|
381
|
-
([+-]?\d+(\.\d*)?)\s*, # first number
|
|
382
|
-
\s*([+-]?\d+(\.\d*)?) # second number
|
|
383
|
-
\s*([\]\)])$ # closing bracket
|
|
384
|
-
""",
|
|
385
|
-
val_str,
|
|
386
|
-
re.VERBOSE,
|
|
387
|
-
)
|
|
436
|
+
m = _PARSE_RANGE_REGEX.match(val_str)
|
|
388
437
|
if not m:
|
|
389
438
|
raise ValueError(f"Invalid range syntax: {val_str!r}")
|
|
390
439
|
start_inc = m.group(1) == "["
|
|
391
|
-
end_inc = m.group(
|
|
392
|
-
start =
|
|
393
|
-
end =
|
|
394
|
-
if start > end:
|
|
440
|
+
end_inc = m.group(6) == "]"
|
|
441
|
+
start = m.group(2)
|
|
442
|
+
end = m.group(4)
|
|
443
|
+
if float(start) > float(end):
|
|
395
444
|
raise ValueError(f"Range lower bound greater than upper bound: {val_str!r}")
|
|
396
445
|
return start, end, start_inc, end_inc
|
|
397
446
|
|
|
@@ -426,7 +475,7 @@ def _parse_comparison(val_str: str) -> Tuple[str, Union[float, str, bool]]:
|
|
|
426
475
|
raise ValueError(f"No valid comparison operator at start of {val_str!r}")
|
|
427
476
|
|
|
428
477
|
|
|
429
|
-
def
|
|
478
|
+
def build_filter_string(
|
|
430
479
|
kwargs: Dict[str, Any], tool_args_type: Dict[str, dict], fixed_filter: str
|
|
431
480
|
) -> str:
|
|
432
481
|
"""
|
vectara_agentic/tools.py
CHANGED
|
@@ -22,9 +22,9 @@ from .db_tools import DatabaseTools
|
|
|
22
22
|
from .utils import summarize_documents, is_float
|
|
23
23
|
from .agent_config import AgentConfig
|
|
24
24
|
from .tool_utils import (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
VectaraTool
|
|
25
|
+
create_tool_from_dynamic_function,
|
|
26
|
+
build_filter_string,
|
|
27
|
+
VectaraTool,
|
|
28
28
|
)
|
|
29
29
|
|
|
30
30
|
LI_packages = {
|
|
@@ -62,6 +62,7 @@ LI_packages = {
|
|
|
62
62
|
},
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
|
|
65
66
|
class VectaraToolFactory:
|
|
66
67
|
"""
|
|
67
68
|
A factory class for creating Vectara RAG tools.
|
|
@@ -108,6 +109,7 @@ class VectaraToolFactory:
|
|
|
108
109
|
mmr_diversity_bias: float = 0.2,
|
|
109
110
|
udf_expression: str = None,
|
|
110
111
|
rerank_chain: List[Dict] = None,
|
|
112
|
+
return_direct: bool = False,
|
|
111
113
|
save_history: bool = True,
|
|
112
114
|
verbose: bool = False,
|
|
113
115
|
vectara_base_url: str = "https://api.vectara.io",
|
|
@@ -142,6 +144,7 @@ class VectaraToolFactory:
|
|
|
142
144
|
"diversity_bias" for mmr, and "user_function" for udf).
|
|
143
145
|
If using slingshot/multilingual_reranker_v1, it must be first in the list.
|
|
144
146
|
save_history (bool, optional): Whether to save the query in history.
|
|
147
|
+
return_direct (bool, optional): Whether the agent should return the tool's response directly.
|
|
145
148
|
verbose (bool, optional): Whether to print verbose output.
|
|
146
149
|
vectara_base_url (str, optional): The base URL for the Vectara API.
|
|
147
150
|
vectara_verify_ssl (bool, optional): Whether to verify SSL certificates for the Vectara API.
|
|
@@ -177,7 +180,7 @@ class VectaraToolFactory:
|
|
|
177
180
|
else summarize_docs
|
|
178
181
|
)
|
|
179
182
|
try:
|
|
180
|
-
filter_string =
|
|
183
|
+
filter_string = build_filter_string(
|
|
181
184
|
kwargs, tool_args_type, fixed_filter
|
|
182
185
|
)
|
|
183
186
|
except ValueError as e:
|
|
@@ -216,7 +219,7 @@ class VectaraToolFactory:
|
|
|
216
219
|
response = vectara_retriever.retrieve(query)
|
|
217
220
|
|
|
218
221
|
if len(response) == 0:
|
|
219
|
-
msg = "Vectara Tool failed to
|
|
222
|
+
msg = "Vectara Tool failed to retrieve any results for the query."
|
|
220
223
|
return ToolOutput(
|
|
221
224
|
tool_name=search_function.__name__,
|
|
222
225
|
content=msg,
|
|
@@ -289,7 +292,7 @@ class VectaraToolFactory:
|
|
|
289
292
|
+ "Use this tool to search for relevant documents, not to ask questions."
|
|
290
293
|
)
|
|
291
294
|
|
|
292
|
-
tool =
|
|
295
|
+
tool = create_tool_from_dynamic_function(
|
|
293
296
|
search_function,
|
|
294
297
|
tool_name,
|
|
295
298
|
search_tool_extra_desc,
|
|
@@ -300,6 +303,7 @@ class VectaraToolFactory:
|
|
|
300
303
|
),
|
|
301
304
|
tool_args_schema,
|
|
302
305
|
compact_docstring=self.compact_docstring,
|
|
306
|
+
return_direct=return_direct,
|
|
303
307
|
)
|
|
304
308
|
return tool
|
|
305
309
|
|
|
@@ -336,6 +340,7 @@ class VectaraToolFactory:
|
|
|
336
340
|
include_citations: bool = True,
|
|
337
341
|
save_history: bool = False,
|
|
338
342
|
fcs_threshold: float = 0.0,
|
|
343
|
+
return_direct: bool = False,
|
|
339
344
|
verbose: bool = False,
|
|
340
345
|
vectara_base_url: str = "https://api.vectara.io",
|
|
341
346
|
vectara_verify_ssl: bool = True,
|
|
@@ -388,6 +393,7 @@ class VectaraToolFactory:
|
|
|
388
393
|
save_history (bool, optional): Whether to save the query in history.
|
|
389
394
|
fcs_threshold (float, optional): A threshold for factual consistency.
|
|
390
395
|
If set above 0, the tool notifies the calling agent that it "cannot respond" if FCS is too low.
|
|
396
|
+
return_direct (bool, optional): Whether the agent should return the tool's response directly.
|
|
391
397
|
verbose (bool, optional): Whether to print verbose output.
|
|
392
398
|
vectara_base_url (str, optional): The base URL for the Vectara API.
|
|
393
399
|
vectara_verify_ssl (bool, optional): Whether to verify SSL certificates for the Vectara API.
|
|
@@ -417,7 +423,7 @@ class VectaraToolFactory:
|
|
|
417
423
|
|
|
418
424
|
query = kwargs.pop("query")
|
|
419
425
|
try:
|
|
420
|
-
filter_string =
|
|
426
|
+
filter_string = build_filter_string(
|
|
421
427
|
kwargs, tool_args_type, fixed_filter
|
|
422
428
|
)
|
|
423
429
|
except ValueError as e:
|
|
@@ -468,7 +474,10 @@ class VectaraToolFactory:
|
|
|
468
474
|
response = vectara_query_engine.query(query)
|
|
469
475
|
|
|
470
476
|
if len(response.source_nodes) == 0:
|
|
471
|
-
msg =
|
|
477
|
+
msg = (
|
|
478
|
+
"Tool failed to generate a response since no matches were found. "
|
|
479
|
+
"Please check the arguments and try again."
|
|
480
|
+
)
|
|
472
481
|
return ToolOutput(
|
|
473
482
|
tool_name=rag_function.__name__,
|
|
474
483
|
content=msg,
|
|
@@ -545,13 +554,14 @@ class VectaraToolFactory:
|
|
|
545
554
|
description="The search query to perform, in the form of a question",
|
|
546
555
|
)
|
|
547
556
|
|
|
548
|
-
tool =
|
|
557
|
+
tool = create_tool_from_dynamic_function(
|
|
549
558
|
rag_function,
|
|
550
559
|
tool_name,
|
|
551
560
|
tool_description,
|
|
552
561
|
RagToolBaseParams,
|
|
553
562
|
tool_args_schema,
|
|
554
563
|
compact_docstring=self.compact_docstring,
|
|
564
|
+
return_direct=return_direct,
|
|
555
565
|
)
|
|
556
566
|
return tool
|
|
557
567
|
|
vectara_agentic/tools_catalog.py
CHANGED
|
@@ -25,7 +25,8 @@ get_headers = {
|
|
|
25
25
|
|
|
26
26
|
def get_current_date() -> str:
|
|
27
27
|
"""
|
|
28
|
-
Returns
|
|
28
|
+
Returns the current date as a string.
|
|
29
|
+
Call this tool to get the current date in the format "Day, Month Day, Year".
|
|
29
30
|
"""
|
|
30
31
|
return date.today().strftime("%A, %B %d, %Y")
|
|
31
32
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vectara_agentic
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.16
|
|
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.34
|
|
20
|
+
Requires-Dist: llama-index-indices-managed-vectara==0.4.5
|
|
21
21
|
Requires-Dist: llama-index-agent-llm-compiler==0.3.0
|
|
22
22
|
Requires-Dist: llama-index-agent-lats==0.3.0
|
|
23
|
-
Requires-Dist: llama-index-agent-openai==0.4.
|
|
23
|
+
Requires-Dist: llama-index-agent-openai==0.4.7
|
|
24
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-google-genai==0.1.
|
|
30
|
+
Requires-Dist: llama-index-llms-google-genai==0.1.12
|
|
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
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
tests/endpoint.py,sha256=frnpdZQpnuQNNKNYgAn2rFTarNG8MCJaNA77Bw_W22A,1420
|
|
3
|
+
tests/test_agent.py,sha256=o5U3K1AJllsSDvucrgFJPQRdAmHPq3LCuFpsnECUTFk,5483
|
|
4
|
+
tests/test_agent_planning.py,sha256=JwEebGooROAvsQ9JZoaH6KEcrSyv1F0lL4TD4FjP8a8,2213
|
|
5
|
+
tests/test_agent_type.py,sha256=mWo-pTQNDj4fWFPETm5jnb7Y5N48aW35keTVvxdIaCc,7173
|
|
6
|
+
tests/test_fallback.py,sha256=M5YD7NHZ0joVU1frYIr9_OiRAIje5mrXrYVcekzlyGs,2829
|
|
7
|
+
tests/test_groq.py,sha256=Knsz-xEBY-eoq8T0DzAC09UJWZqwtLmcjbx6QY37rJg,4235
|
|
8
|
+
tests/test_private_llm.py,sha256=CY-_rCpxGUuxnZ3ypkodw5Jj-sJCNdh6rLbCvULwuJI,2247
|
|
9
|
+
tests/test_return_direct.py,sha256=Y_K_v88eS_kJfxE6A0Yghma0nUT8u6COitj0SNnZGNs,1523
|
|
10
|
+
tests/test_serialization.py,sha256=Ed23GN2zhSJNdPFrVK4aqLkOhJKviczR_o0t-r9TuRI,4762
|
|
11
|
+
tests/test_tools.py,sha256=MWExM3n1oKmVpLmayIgHXqF6_hOPq44KPkRphitBKik,15709
|
|
12
|
+
tests/test_vectara_llms.py,sha256=m-fDAamJR1I5IdV0IpXuTegerTUNCVRm27lsHd4wQjg,2367
|
|
13
|
+
tests/test_workflow.py,sha256=lVyrVHdRO5leYNbYtHTmKqMX0c8_xehCpUA7cXQKVsc,2175
|
|
14
|
+
vectara_agentic/__init__.py,sha256=2GLDS3U6KckK-dBRl9v_x1kSV507gEhjOfuMmmu0Qxg,850
|
|
15
|
+
vectara_agentic/_callback.py,sha256=ron49t1t-ox-736WaXzrZ99vhN4NI9bMiHFyj0iIPqg,13062
|
|
16
|
+
vectara_agentic/_observability.py,sha256=UbJxiOJFOdLq3b1t0-Y7swMC3BzJu3IOlTUM-c1oUk8,4328
|
|
17
|
+
vectara_agentic/_prompts.py,sha256=vAb02oahA7GKRgLOsDGqgKl-BLBop2AjOlCTgLrf3M4,9694
|
|
18
|
+
vectara_agentic/_version.py,sha256=zjobn8jIz8O5910X5cnrTC2MH3U93-ntXMSx5_WVmW8,66
|
|
19
|
+
vectara_agentic/agent.py,sha256=bHeRh0kug3I8X1wZ73byrrRNfVX3QEXxwTukqAFh0jE,53761
|
|
20
|
+
vectara_agentic/agent_config.py,sha256=E-rtYMcpoGxnEAyy8231bizo2n0uGQ2qWxuSgTEfwdQ,4327
|
|
21
|
+
vectara_agentic/agent_endpoint.py,sha256=QIMejCLlpW2qzXxeDAxv3anF46XMDdVMdKGWhJh3azY,1996
|
|
22
|
+
vectara_agentic/db_tools.py,sha256=Kfz6n-rSj5TQEbAiJnWGmqWtcwB0A5GpxD7d1UwGzlc,11194
|
|
23
|
+
vectara_agentic/llm_utils.py,sha256=FOQG6if6D7l1eVRx_r-HSUhh5wBguIaxsYMKrZl2fJo,6302
|
|
24
|
+
vectara_agentic/sub_query_workflow.py,sha256=xjySd2qjLAKwK6XuS0R0PTyk2uXraHCgCbDP1xDoFVI,12175
|
|
25
|
+
vectara_agentic/tool_utils.py,sha256=sB-_UwDi9qNStkDWX_AHIfoxMlTMiWWfTIOBxvHpOkU,20422
|
|
26
|
+
vectara_agentic/tools.py,sha256=hppc2KZ_zMYCiEHsoAS7nMaDgXfAwQZ0b7kyitm95V8,32856
|
|
27
|
+
vectara_agentic/tools_catalog.py,sha256=cAN_kDOWZUoW4GNFwY5GdS6ImMUQNnF2sggx9OGK9Cg,4906
|
|
28
|
+
vectara_agentic/types.py,sha256=HcS7vR8P2v2xQTlOc6ZFV2vvlr3OpzSNWhtcLMxqUZc,1792
|
|
29
|
+
vectara_agentic/utils.py,sha256=q14S8nm3UFFI3ksk-xszd9xgFrtXdIt_tdRiBMFjaa0,2529
|
|
30
|
+
vectara_agentic-0.2.16.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
31
|
+
vectara_agentic-0.2.16.dist-info/METADATA,sha256=vTZeO3QsdOOHAKOJ5CvEmSa67E8DjluaZKxOEq6GgaE,28115
|
|
32
|
+
vectara_agentic-0.2.16.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
|
33
|
+
vectara_agentic-0.2.16.dist-info/top_level.txt,sha256=Y7TQTFdOYGYodQRltUGRieZKIYuzeZj2kHqAUpfCUfg,22
|
|
34
|
+
vectara_agentic-0.2.16.dist-info/RECORD,,
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
tests/endpoint.py,sha256=frnpdZQpnuQNNKNYgAn2rFTarNG8MCJaNA77Bw_W22A,1420
|
|
3
|
-
tests/test_agent.py,sha256=nkg3SefST9Q-38Ys9yLJZr2RN6FxeXonMGj7uRCsta8,5482
|
|
4
|
-
tests/test_agent_planning.py,sha256=r_Qk63aK6gAzIluv3X6CLCNIbE1ExWJEUIkvoI6U7RE,2213
|
|
5
|
-
tests/test_agent_type.py,sha256=mWo-pTQNDj4fWFPETm5jnb7Y5N48aW35keTVvxdIaCc,7173
|
|
6
|
-
tests/test_fallback.py,sha256=M5YD7NHZ0joVU1frYIr9_OiRAIje5mrXrYVcekzlyGs,2829
|
|
7
|
-
tests/test_groq.py,sha256=0FFnQ91o9UjOIAIe_JMxyBl4dz_38RRbl00j9dFudMs,4170
|
|
8
|
-
tests/test_private_llm.py,sha256=CY-_rCpxGUuxnZ3ypkodw5Jj-sJCNdh6rLbCvULwuJI,2247
|
|
9
|
-
tests/test_serialization.py,sha256=Ed23GN2zhSJNdPFrVK4aqLkOhJKviczR_o0t-r9TuRI,4762
|
|
10
|
-
tests/test_tools.py,sha256=b90pbLHEqjbtfiCVDOsYCwUCJXTEE-jIu5WuA8r6Yg8,11920
|
|
11
|
-
tests/test_vectara_llms.py,sha256=wpDFOuExoUqRwqH7Ikhb8mVmkq1e85m2p1fMMFF2_GE,2298
|
|
12
|
-
tests/test_workflow.py,sha256=lVyrVHdRO5leYNbYtHTmKqMX0c8_xehCpUA7cXQKVsc,2175
|
|
13
|
-
vectara_agentic/__init__.py,sha256=2GLDS3U6KckK-dBRl9v_x1kSV507gEhjOfuMmmu0Qxg,850
|
|
14
|
-
vectara_agentic/_callback.py,sha256=ron49t1t-ox-736WaXzrZ99vhN4NI9bMiHFyj0iIPqg,13062
|
|
15
|
-
vectara_agentic/_observability.py,sha256=BA2zhwa5930aaDUJxHefPlmIPt8kZOuLHVBc9PtYNuU,3839
|
|
16
|
-
vectara_agentic/_prompts.py,sha256=8d5gaaY_OrNVDlGqb7cqIZq0WnK5RY7yVa8LgHDjbhA,9508
|
|
17
|
-
vectara_agentic/_version.py,sha256=yDIvGWQ2X4m-Tnp9W4synsKkQknhptDZf8ZdOLb-NJ8,66
|
|
18
|
-
vectara_agentic/agent.py,sha256=v6LdfDckGtcUomxiTsIsslBqJCW2eOApEwK67f6AWVw,50283
|
|
19
|
-
vectara_agentic/agent_config.py,sha256=E-rtYMcpoGxnEAyy8231bizo2n0uGQ2qWxuSgTEfwdQ,4327
|
|
20
|
-
vectara_agentic/agent_endpoint.py,sha256=QIMejCLlpW2qzXxeDAxv3anF46XMDdVMdKGWhJh3azY,1996
|
|
21
|
-
vectara_agentic/db_tools.py,sha256=bAgqQMrpmu7KBaiAjJ4tpH8JwsFGEDk8iru5Deu0SEk,11179
|
|
22
|
-
vectara_agentic/llm_utils.py,sha256=Isf1d9K4Jpn-IwMZn-liPUTEF-bpiqp0XIiNRohtwTQ,6152
|
|
23
|
-
vectara_agentic/sub_query_workflow.py,sha256=xjySd2qjLAKwK6XuS0R0PTyk2uXraHCgCbDP1xDoFVI,12175
|
|
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
|
|
27
|
-
vectara_agentic/types.py,sha256=HcS7vR8P2v2xQTlOc6ZFV2vvlr3OpzSNWhtcLMxqUZc,1792
|
|
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
|