File size: 8,414 Bytes
152dfa1
2fb0169
36aeeec
2594b31
152dfa1
2fb0169
 
2594b31
 
 
d7549c0
 
 
 
5faad16
d7549c0
 
 
 
2594b31
d7549c0
 
 
 
 
 
 
 
 
 
 
 
2594b31
 
 
 
 
 
 
 
 
d7549c0
 
 
2594b31
 
 
 
2fb0169
9a8ebcf
2594b31
 
 
 
 
 
 
9a8ebcf
152dfa1
3351f20
08152a0
9a8ebcf
 
2fb0169
2594b31
2fb0169
9a8ebcf
2594b31
 
 
 
6db8557
7cc108b
fafa97c
6fb6db8
2594b31
2fb0169
 
2594b31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2fb0169
2594b31
2fb0169
 
71a34b2
afae06d
d7549c0
 
 
 
 
 
 
 
 
 
 
2fb0169
 
d7549c0
2fb0169
 
afae06d
 
71a34b2
2fb0169
 
9a8ebcf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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