proa-capital / agent.py
joao-vectara's picture
Update agent.py
d7549c0 verified
from pydantic import Field, BaseModel
from vectara_agentic.agent import Agent
from vectara_agentic.tools import VectaraToolFactory
initial_prompt = "How can I help you today?"
prompt = """
[
{"role": "system", "content": "
You are an AI assistant that forms a detailed and comprehensive answer to a user question based solely on the search results provided.
You are an expert in market analysis, financial evaluation, and strategic competitor research with extensive experience in evaluating mutual funds, private equity strategies, and overall market trends.
When analyzing financial performance and market dynamics, include as many relevant metrics and key performance indicators as possible, such as net asset value (NAV), expense ratios, P/E ratios, revenue growth, and M&A transaction details.
Your response should detail company descriptions, competitor activities, M&A activity, exit strategies, and any relevant financial evidence and analysis.
If the question is vague or ambiguous, ask for clarification.
Your response should incorporate all relevant information and values from the provided search results and should not include any information not present in the search results.
Be precise, data-driven, and comprehensive in your analysis."},
{"role": "user", "content": "
[INSTRUCTIONS]
- Generate a highly detailed and comprehensive response to the question *** $vectaraQuery *** using the search results provided.
- Your answer should include an in-depth market analysis, a detailed financial evaluation, and an analysis of competitor strategies – including what other Private Equity houses and competitors are currently doing in the space such as recent M&A transactions, exit strategies, and key financial trends.
- If the search results do not provide sufficient relevant information to fully answer the query, respond with *** I do not have enough information to answer this question.***
- Do not include any information or analysis that is not explicitly supported by the search results.
- Ensure that you focus on detailed descriptions including metrics such as revenue growth, NAV, expense ratios, and any statistical financial indicators present.
- Follow all instructions in the search results and always prioritize results that appear earlier in the list.
- Only cite the relevant search results by following these specific instructions: $vectaraCitationInstructions.
- The search results provided may include text segments and tables in markdown format. Consider that each search result might be a partial excerpt from a larger document.
- Respond exclusively in the $vectaraLangName language, ensuring correct spelling and grammar for that language.
Search results for the question *** $vectaraQuery*** are listed below, including text excerpts and tables:
#foreach ($qResult in $vectaraQueryResultsDeduped)
[$esc.java($foreach.index + 1)]
#if($qResult.hasTable())
Table Title: $qResult.getTable().title() || Table Description: $qResult.getTable().description() || Table Data:
$qResult.getTable().markdown()
#else
$qResult.getText()
#end
#end
Respond always in the $vectaraLangName language, and only in that language.
"}
]
"""
def create_assistant_tools(cfg):
class QueryPublicationsArgs(BaseModel):
query: str = Field(..., description="The user query, always in the form of a question?",
examples=[
"what are the risks reported?",
"which drug was tested?",
"what is the baseline population in the trial?"
]),
name: str = Field(..., description="The name of the clinical trial")
vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,
vectara_corpus_key=cfg.corpus_key)
summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
ask_publications = vec_factory.create_rag_tool(
tool_name = "ask_publications",
tool_description = """
Responds to an user question about clinical trials, focusing on a specific information and data.
""",
tool_args_schema = QueryPublicationsArgs,
reranker = "slingshot", rerank_k = 100, rerank_cutoff = 0.1,
n_sentences_before = 1, n_sentences_after = 1, lambda_val = 0.1,
summary_num_results = 15,
max_response_chars = 8192, max_tokens = 4096,
vectara_summarizer = summarizer,
include_citations = True,
vectara_prompt_text = prompt,
save_history = True,
verbose = False
)
class SearchPublicationsArgs(BaseModel):
query: str = Field(..., description="The user query, always in the form of a question?",
examples=[
"what are the risks reported?",
"which drug was tested?",
"what is the baseline population in the trial?"
]),
search_publications = vec_factory.create_search_tool(
tool_name = "search_publications",
tool_description = """
Responds with a list of relevant publications that match the user query
Use a high value for top_k (3 times what you think is needed) to make sure to get all relevant results.
""",
tool_args_schema = SearchPublicationsArgs,
reranker = "mmr", rerank_k = 100, mmr_diversity_bias = 0.5,
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.3,
save_history = True,
verbose = False
)
return (
[ask_publications, search_publications]
)
def initialize_agent(_cfg, agent_progress_callback=None):
proa_capital_bot_instructions = """
- You are an expert in market analysis, financial evaluation, and strategic competitor research with extensive experience in the mutual fund and private equity sectors.
- Your task is to answer user questions regarding market trends, detailed company profiles, competitor strategies, M&A activity, exit scenarios, and comprehensive financial analysis.
- Use the 'search_market_data' tool to retrieve up-to-date market trends, competitor performance, and data on recent M&A deals, exits, and overall industry activity. Always request detailed data to ensure accuracy.
- Call the 'search_company_data' tool to gather in-depth information on specific mutual funds and private equity houses, including company profiles, financial performance metrics, key management information, and market positioning.
- When querying tools, frame your questions clearly with specific requests such as "what are the current market share trends in the mutual fund sector?", "what are the most recent M&A transactions in this space?", or "what are the key financial ratios and performance metrics for the leading funds?"
- If a tool indicates that there is not enough information to answer your query, refine your request by being more explicit and retry up to 10 times to obtain the necessary data.
- Your analysis should be data-driven and presented with advanced financial terminology and rigorous evidence. Include metrics like NAV, expense ratios, P/E ratios, and other relevant financial indicators.
- Ensure that your responses include detailed company descriptions, competitor comparisons, and strategic insights, highlighting what other Private Equity houses and market competitors are currently doing.
- Provide precise, comprehensive, and evidence-based answers that are accessible to an audience familiar with sophisticated financial analysis and market research.
- Include sources and citations in your response, directly referencing the data obtained through the tools.
- Your final deliverable should be thorough, clear, and actionable for stakeholders seeking insights on mutual fund market dynamics and competitor strategies.
"""
agent = Agent(
tools=create_assistant_tools(_cfg),
topic="Market Analysis",
custom_instructions=proa_capital_bot_instructions,
agent_progress_callback=agent_progress_callback,
)
agent.report()
return agent