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, agent_progress_callback: Callable[[AgentStatusType, str], None] | None = None, agent_type: AgentType | 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

clear_memory() None[source]

Clear the agent’s memory.

dumps() str[source]

Serialize the Agent instance to a JSON string.

classmethod from_corpus(tool_name: str, data_description: str, assistant_specialty: str, vectara_customer_id: str = '', vectara_corpus_id: str = '', vectara_api_key: str = '', agent_progress_callback: Callable[[AgentStatusType, str], None] | None = None, 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 (or comma separated list of IDs).

  • vectara_api_key (str) – The Vectara API key.

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

  • 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 maps field name to Tuple[type, 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_dict(data: Dict[str, Any]) Agent[source]

Create an Agent instance from a dictionary.

classmethod from_tools(tools: List[FunctionTool], topic: str = 'general', custom_instructions: str = '', verbose: bool = True, update_func: Callable[[AgentStatusType, str], None] | None = None, agent_progress_callback: Callable[[AgentStatusType, str], None] | None = None, agent_type: AgentType | 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.

  • agent_progress_callback (Callable) – A callback function the code calls on any agent updates. update_func (Callable): old name for agent_progress_callback. Will be deprecated in future.

  • agent_type (AgentType, optional) – The type of agent to be used. Defaults to None.

Returns:

An instance of the Agent class.

Return type:

Agent

classmethod loads(data: str) Agent[source]

Create an Agent instance from a JSON string.

report() None[source]

Get a report from the agent.

Returns:

The report from the agent.

Return type:

str

to_dict() Dict[str, Any][source]

Serialize the Agent instance to a dictionary.

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, metadata: ToolMetadata, fn: Callable[[...], Any] | None = None, async_fn: Callable[[...], Awaitable[Any]] | None = None)[source]

Bases: FunctionTool

A subclass of FunctionTool adding the tool_type attribute.

classmethod from_defaults(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, tool_type: ToolType = ToolType.QUERY) 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, udf_expression: str | None = None, rerank_chain: List[Dict] | None = None, 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.

  • udf_expression (str, optional) – the user defined expression for reranking results.

  • rerank_chain (List[Dict], optional) – A list of rerankers to be applied sequentially. Each dictionary should specify the “type” of reranker (mmr, slingshot, udf) and any other parameters (e.g. “limit” or “cutoff” for any type, “diversity_bias” for mmr, and “user_function” for udf).

  • If using slingshot/multilingual_reranker_v1, it must be first in the list.

  • 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

class vectara_agentic.tools.VectaraToolMetadata(tool_type: ToolType, **kwargs)[source]

Bases: ToolMetadata

A subclass of ToolMetadata adding the tool_type attribute.

tool_type: ToolType

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 = FieldInfo(annotation=NoneType, required=False, default=None, description='the role of the person providing critique.'), point_of_view: str = 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.get_bad_topics() List[str][source]

Get the list of topics to avoid in the response.

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.agent_endpoint module

This module contains functions to start the agent behind an API endpoint.

class vectara_agentic.agent_endpoint.ChatRequest(*, message: str)[source]

Bases: BaseModel

A request model for the chat endpoint.

message: str
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'message': FieldInfo(annotation=str, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

vectara_agentic.agent_endpoint.create_app(agent: Agent) FastAPI[source]

Create a FastAPI application with a chat endpoint.

vectara_agentic.agent_endpoint.start_app(agent: Agent, host='0.0.0.0', port=8000)[source]

Start the FastAPI server.

Parameters:
  • host (str, optional) – The host address for the API. Defaults to ‘127.0.0.1’.

  • port (int, optional) – The port for the API. Defaults to 8000.

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_STEP = 'agent_step'
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'
GEMINI = 'GEMINI'
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'