vectara_agentic package

Submodules

vectara_agentic.agent module

This module contains the Agent class for handling different types of agents and their interactions.

class vectara_agentic.agent.Agent(tools: list[FunctionTool], topic: str = 'general', custom_instructions: str = '', verbose: bool = True, update_func: Callable[[AgentStatusType, str], None] | None = None)[source]

Bases: object

Agent class for handling different types of agents and their interactions.

chat(prompt: str) str[source]

Interact with the agent using a chat prompt.

Parameters:

prompt (str) – The chat prompt.

Returns:

The response from the agent.

Return type:

str

classmethod from_corpus(tool_name: str, vectara_customer_id: str, vectara_corpus_id: str, vectara_api_key: str, data_description: str, assistant_specialty: str, verbose: bool = False, vectara_filter_fields: list[dict] = [], vectara_lambda_val: float = 0.005, vectara_reranker: str = 'mmr', vectara_rerank_k: int = 50, vectara_n_sentences_before: int = 2, vectara_n_sentences_after: int = 2, vectara_summary_num_results: int = 10, vectara_summarizer: str = 'vectara-summary-ext-24-05-sml') Agent[source]

Create an agent from a single Vectara corpus

Parameters:
  • tool_name (str) – The name of Vectara tool used by the agent

  • vectara_customer_id (str) – The Vectara customer ID.

  • vectara_corpus_id (str) – The Vectara corpus ID.

  • vectara_api_key (str) – The Vectara API key.

  • data_description (str) – The description of the data.

  • assistant_specialty (str) – The specialty of the assistant.

  • verbose (bool, optional) – Whether to print verbose output.

  • vectara_filter_fields (List[dict], optional) – The filterable attributes (each dict includes name, type, and description).

  • vectara_lambda_val (float, optional) – The lambda value for Vectara hybrid search.

  • vectara_reranker (str, optional) – The Vectara reranker name (default “mmr”)

  • vectara_rerank_k (int, optional) – The number of results to use with reranking.

  • vectara_n_sentences_before (int, optional) – The number of sentences before the matching text

  • vectara_n_sentences_after (int, optional) – The number of sentences after the matching text.

  • vectara_summary_num_results (int, optional) – The number of results to use in summarization.

  • vectara_summarizer (str, optional) – The Vectara summarizer name.

Returns:

An instance of the Agent class.

Return type:

Agent

classmethod from_tools(tools: List[FunctionTool], topic: str = 'general', custom_instructions: str = '', verbose: bool = True, update_func: Callable[[AgentStatusType, str], None] | None = None) Agent[source]

Create an agent from tools, agent type, and language model.

Parameters:
  • tools (list[FunctionTool]) – A list of tools to be used by the agent.

  • topic (str, optional) – The topic for the agent. Defaults to ‘general’.

  • custom_instructions (str, optional) – custom instructions for the agent. Defaults to ‘’.

  • verbose (bool, optional) – Whether the agent should print its steps. Defaults to True.

  • update_func (Callable) – A callback function the code calls on any agent updates.

Returns:

An instance of the Agent class.

Return type:

Agent

report() None[source]

Get a report from the agent.

Returns:

The report from the agent.

Return type:

str

token_counts() dict[source]

Get the token counts for the agent and tools.

Returns:

The token counts for the agent and tools.

Return type:

dict

vectara_agentic.tools module

This module contains the ToolsFactory class for creating agent tools.

class vectara_agentic.tools.ToolsFactory[source]

Bases: object

A factory class for creating agent tools.

create_tool(function: Callable, tool_type: ToolType = ToolType.QUERY) VectaraTool[source]

Create a tool from a function.

Parameters:
  • function (Callable) – a function to convert into a tool.

  • tool_type (ToolType) – the type of tool.

Returns:

A VectaraTool object.

Return type:

VectaraTool

database_tools(tool_name_prefix: str = '', content_description: str | None = None, sql_database: SQLDatabase | None = None, scheme: str | None = None, host: str = 'localhost', port: str = '5432', user: str = 'postgres', password: str = 'Password', dbname: str = 'postgres') List[VectaraTool][source]

Returns a list of database tools.

Parameters:
  • tool_name_prefix (str, optional) – The prefix to add to the tool names. Defaults to “”.

  • content_description (str, optional) – The content description for the database. Defaults to None.

  • sql_database (SQLDatabase, optional) – The SQLDatabase object. Defaults to None.

  • scheme (str, optional) – The database scheme. Defaults to None.

  • host (str, optional) – The database host. Defaults to “localhost”.

  • port (str, optional) – The database port. Defaults to “5432”.

  • user (str, optional) – The database user. Defaults to “postgres”.

  • password (str, optional) – The database password. Defaults to “Password”.

  • dbname (str, optional) – The database name. Defaults to “postgres”. You must specify either the sql_database object or the scheme, host, port, user, password, and dbname.

Returns:

A list of VectaraTool objects.

Return type:

List[VectaraTool]

financial_tools()[source]

Create a list of financial tools.

get_llama_index_tools(tool_package_name: str, tool_spec_name: str, tool_name_prefix: str = '', **kwargs: dict) List[VectaraTool][source]

Get a tool from the llama_index hub.

Parameters:
  • tool_package_name (str) – The name of the tool package.

  • tool_spec_name (str) – The name of the tool spec.

  • tool_name_prefix (str, optional) – The prefix to add to the tool names (added to every tool in the spec).

  • kwargs (dict) – The keyword arguments to pass to the tool constructor (see Hub for tool specific details).

Returns:

A list of VectaraTool objects.

Return type:

List[VectaraTool]

guardrail_tools() List[FunctionTool][source]

Create a list of guardrail tools to avoid controversial topics.

legal_tools() List[FunctionTool][source]

Create a list of legal tools.

standard_tools() List[FunctionTool][source]

Create a list of standard tools.

class vectara_agentic.tools.VectaraTool(tool_type: ToolType, fn: Callable[[...], Any] | None = None, metadata: ToolMetadata | None = None, async_fn: Callable[[...], Awaitable[Any]] | None = None)[source]

Bases: FunctionTool

A subclass of FunctionTool adding the tool_type attribute.

classmethod from_defaults(tool_type: ToolType, fn: Callable[[...], Any] | None = None, name: str | None = None, description: str | None = None, return_direct: bool = False, fn_schema: Type[BaseModel] | None = None, async_fn: Callable[[...], Awaitable[Any]] | None = None, tool_metadata: ToolMetadata | None = None) VectaraTool[source]
class vectara_agentic.tools.VectaraToolFactory(vectara_customer_id: str, vectara_corpus_id: str, vectara_api_key: str)[source]

Bases: object

A factory class for creating Vectara RAG tools.

create_rag_tool(tool_name: str, tool_description: str, tool_args_schema: type[BaseModel], vectara_summarizer: str = 'vectara-summary-ext-24-05-sml', summary_num_results: int = 5, summary_response_lang: str = 'eng', n_sentences_before: int = 2, n_sentences_after: int = 2, lambda_val: float = 0.005, reranker: str = 'mmr', rerank_k: int = 50, mmr_diversity_bias: float = 0.2, include_citations: bool = True, fcs_threshold: float = 0.0) VectaraTool[source]

Creates a RAG (Retrieve and Generate) tool.

Parameters:
  • tool_name (str) – The name of the tool.

  • tool_description (str) – The description of the tool.

  • tool_args_schema (BaseModel) – The schema for the tool arguments.

  • vectara_summarizer (str, optional) – The Vectara summarizer to use.

  • summary_num_results (int, optional) – The number of summary results.

  • summary_response_lang (str, optional) – The response language for the summary.

  • n_sentences_before (int, optional) – Number of sentences before the summary.

  • n_sentences_after (int, optional) – Number of sentences after the summary.

  • lambda_val (float, optional) – Lambda value for the Vectara query.

  • reranker (str, optional) – The reranker mode.

  • rerank_k (int, optional) – Number of top-k documents for reranking.

  • mmr_diversity_bias (float, optional) – MMR diversity bias.

  • include_citations (bool, optional) – Whether to include citations in the response. If True, uses markdown vectara citations that requires the Vectara scale plan.

  • fcs_threshold (float, optional) – a threshold for factual consistency. If set above 0, the tool notifies the calling agent that it “cannot respond” if FCS is too low

Returns:

A VectaraTool object.

Return type:

VectaraTool

vectara_agentic.tools_catalog module

This module contains the tools catalog for the Vectara Agentic.

vectara_agentic.tools_catalog.critique_text(text: str = FieldInfo(annotation=NoneType, required=True, description='the original text.'), role: str | None = FieldInfo(annotation=NoneType, required=False, default=None, description='the role of the person providing critique.'), point_of_view: str | None = FieldInfo(annotation=NoneType, required=False, default=None, description='the point of view with which to provide critique.')) str[source]

This is a helper tool. Critique the text from the specified point of view.

Parameters:
  • text (str) – The original text.

  • role (str) – The role of the person providing critique.

  • point_of_view (str) – The point of view with which to provide critique.

Returns:

The critique of the text.

Return type:

str

vectara_agentic.tools_catalog.guardrails_be_polite(text: str = FieldInfo(annotation=NoneType, required=True, description='the original text.')) str[source]

A guardrails tool. Given the input text, rephrases the text to ensure that the response is polite.

Parameters:

text (str) – The original text.

Returns:

The rephrased text.

Return type:

str

vectara_agentic.tools_catalog.guardrails_no_politics(text: str = FieldInfo(annotation=NoneType, required=True, description='the original text.')) str[source]

A guardrails tool. Given the input text, rephrases the text to ensure that the response avoids any specific political content.

Parameters:

text (str) – The original text.

Returns:

The rephrased text.

Return type:

str

vectara_agentic.tools_catalog.rephrase_text(text: str = FieldInfo(annotation=NoneType, required=True, description='the original text.'), instructions: str = FieldInfo(annotation=NoneType, required=True, description='the specific instructions for how to rephrase the text.')) str[source]

This is a helper tool. Use this tool to rephrase the text according to the provided instructions. For example, instructions could be “as a 5 year old would say it.”

Parameters:
  • text (str) – The original text.

  • instructions (str) – The specific instructions for how to rephrase the text.

Returns:

The rephrased text.

Return type:

str

vectara_agentic.tools_catalog.summarize_text(text: str = FieldInfo(annotation=NoneType, required=True, description='the original text.'), expertise: str = FieldInfo(annotation=NoneType, required=True, description='the expertise to apply to the summarization.')) str[source]

This is a helper tool. Use this tool to summarize text using a given expertise with no more than summary_max_length characters.

Parameters:
  • text (str) – The original text.

  • expertise (str) – The expertise to apply to the summarization.

Returns:

The summarized text.

Return type:

str

vectara_agentic.types module

This module contains the types used in the Vectara Agentic.

class vectara_agentic.types.AgentStatusType(value)[source]

Bases: Enum

Enumeration for different types of agent statuses.

AGENT_UPDATE = 'agent_update'
TOOL_CALL = 'tool_call'
TOOL_OUTPUT = 'tool_output'
class vectara_agentic.types.AgentType(value)[source]

Bases: Enum

Enumeration for different types of agents.

LLMCOMPILER = 'LLMCOMPILER'
OPENAI = 'OPENAI'
REACT = 'REACT'
class vectara_agentic.types.LLMRole(value)[source]

Bases: Enum

Enumeration for different types of LLM roles.

MAIN: str = 'MAIN'
TOOL: str = 'TOOL'
class vectara_agentic.types.ModelProvider(value)[source]

Bases: Enum

Enumeration for different types of model providers.

ANTHROPIC = 'ANTHROPIC'
COHERE = 'COHERE'
FIREWORKS = 'FIREWORKS'
GROQ = 'GROQ'
OPENAI = 'OPENAI'
TOGETHER = 'TOGETHER'
class vectara_agentic.types.ObserverType(value)[source]

Bases: Enum

Enumeration for different types of observability integrations.

ARIZE_PHOENIX = 'ARIZE_PHOENIX'
NO_OBSERVER = 'NO_OBSERVER'
class vectara_agentic.types.ToolType(value)[source]

Bases: Enum

Enumeration for different types of tools.

ACTION = 'action'
QUERY = 'query'