Update agent.py
Browse files
agent.py
CHANGED
@@ -1,63 +1,115 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
import requests
|
3 |
from pydantic import Field, BaseModel
|
4 |
|
5 |
-
from omegaconf import OmegaConf
|
6 |
-
|
7 |
from vectara_agentic.agent import Agent
|
8 |
-
from vectara_agentic.tools import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def create_assistant_tools(cfg):
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,
|
16 |
vectara_corpus_key=cfg.corpus_key)
|
17 |
-
summarizer = '
|
18 |
-
|
19 |
-
tool_name = "
|
20 |
tool_description = """
|
21 |
-
Responds to an user question about
|
22 |
""",
|
23 |
-
tool_args_schema =
|
24 |
-
reranker = "
|
25 |
-
|
26 |
-
{
|
27 |
-
"type": "multilingual_reranker_v1",
|
28 |
-
# "cutoff": 0.2
|
29 |
-
},
|
30 |
-
{
|
31 |
-
"type": "mmr",
|
32 |
-
"diversity_bias": 0.2,
|
33 |
-
"limit": 50
|
34 |
-
}
|
35 |
-
],
|
36 |
-
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
|
37 |
summary_num_results = 15,
|
|
|
38 |
vectara_summarizer = summarizer,
|
39 |
include_citations = True,
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
save_history = True,
|
42 |
-
verbose=False
|
43 |
)
|
44 |
-
|
|
|
45 |
return (
|
46 |
-
|
47 |
-
[ask_docs]
|
48 |
)
|
49 |
|
50 |
def initialize_agent(_cfg, agent_progress_callback=None):
|
51 |
-
|
52 |
-
-
|
53 |
-
-
|
54 |
-
- Always
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
"""
|
56 |
|
|
|
57 |
agent = Agent(
|
58 |
tools=create_assistant_tools(_cfg),
|
59 |
-
topic="
|
60 |
-
custom_instructions=
|
61 |
agent_progress_callback=agent_progress_callback,
|
62 |
)
|
63 |
agent.report()
|
|
|
|
|
|
|
1 |
from pydantic import Field, BaseModel
|
2 |
|
|
|
|
|
3 |
from vectara_agentic.agent import Agent
|
4 |
+
from vectara_agentic.tools import VectaraToolFactory
|
5 |
+
|
6 |
+
initial_prompt = "How can I help you today?"
|
7 |
+
|
8 |
+
prompt = """
|
9 |
+
[
|
10 |
+
{"role": "system", "content": "
|
11 |
+
You are an AI assistant that forms a detailed and comprehensive answer to a user question based solely on the search results provided.
|
12 |
+
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.
|
13 |
+
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.
|
14 |
+
Your response should detail company descriptions, competitor activities, M&A activity, exit strategies, and any relevant financial evidence and analysis.
|
15 |
+
If the question is vague or ambiguous, ask for clarification.
|
16 |
+
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.
|
17 |
+
Be precise, data-driven, and comprehensive in your analysis."},
|
18 |
+
|
19 |
+
{"role": "user", "content": "
|
20 |
+
[INSTRUCTIONS]
|
21 |
+
- Generate a highly detailed and comprehensive response to the question *** $vectaraQuery *** using the search results provided.
|
22 |
+
- 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.
|
23 |
+
- 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.***
|
24 |
+
- Do not include any information or analysis that is not explicitly supported by the search results.
|
25 |
+
- Ensure that you focus on detailed descriptions including metrics such as revenue growth, NAV, expense ratios, and any statistical financial indicators present.
|
26 |
+
- Follow all instructions in the search results and always prioritize results that appear earlier in the list.
|
27 |
+
- Only cite the relevant search results by following these specific instructions: $vectaraCitationInstructions.
|
28 |
+
- 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.
|
29 |
+
- Respond exclusively in the $vectaraLangName language, ensuring correct spelling and grammar for that language.
|
30 |
+
|
31 |
+
Search results for the question *** $vectaraQuery*** are listed below, including text excerpts and tables:
|
32 |
+
|
33 |
+
#foreach ($qResult in $vectaraQueryResultsDeduped)
|
34 |
+
[$esc.java($foreach.index + 1)]
|
35 |
+
#if($qResult.hasTable())
|
36 |
+
Table Title: $qResult.getTable().title() || Table Description: $qResult.getTable().description() || Table Data:
|
37 |
+
$qResult.getTable().markdown()
|
38 |
+
#else
|
39 |
+
$qResult.getText()
|
40 |
+
#end
|
41 |
+
#end
|
42 |
+
Respond always in the $vectaraLangName language, and only in that language.
|
43 |
+
"}
|
44 |
+
]
|
45 |
+
"""
|
46 |
|
47 |
def create_assistant_tools(cfg):
|
48 |
+
|
49 |
+
class QueryPublicationsArgs(BaseModel):
|
50 |
+
query: str = Field(..., description="The user query, always in the form of a question?"),
|
51 |
+
name: str = Field(..., description="The name of the memo use for research")
|
52 |
|
53 |
vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,
|
54 |
vectara_corpus_key=cfg.corpus_key)
|
55 |
+
summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
|
56 |
+
ask_publications = vec_factory.create_rag_tool(
|
57 |
+
tool_name = "ask_publications",
|
58 |
tool_description = """
|
59 |
+
Responds to an user question about investment opportunity, focusing on a specific information and data.
|
60 |
""",
|
61 |
+
tool_args_schema = QueryPublicationsArgs,
|
62 |
+
reranker = "slingshot", rerank_k = 100, rerank_cutoff = 0.1,
|
63 |
+
n_sentences_before = 1, n_sentences_after = 1, lambda_val = 0.1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
summary_num_results = 15,
|
65 |
+
max_response_chars = 8192, max_tokens = 4096,
|
66 |
vectara_summarizer = summarizer,
|
67 |
include_citations = True,
|
68 |
+
vectara_prompt_text = prompt,
|
69 |
+
save_history = True,
|
70 |
+
verbose = False
|
71 |
+
)
|
72 |
+
|
73 |
+
class SearchPublicationsArgs(BaseModel):
|
74 |
+
query: str = Field(..., description="The user query, always in the form of a question?"),
|
75 |
+
search_publications = vec_factory.create_search_tool(
|
76 |
+
tool_name = "search_publications",
|
77 |
+
tool_description = """
|
78 |
+
Responds with a list of relevant publications that match the user query
|
79 |
+
Use a high value for top_k (3 times what you think is needed) to make sure to get all relevant results.
|
80 |
+
""",
|
81 |
+
tool_args_schema = SearchPublicationsArgs,
|
82 |
+
reranker = "mmr", rerank_k = 100, mmr_diversity_bias = 0.5,
|
83 |
+
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.3,
|
84 |
save_history = True,
|
85 |
+
verbose = False
|
86 |
)
|
87 |
+
|
88 |
+
|
89 |
return (
|
90 |
+
[ask_publications, search_publications]
|
|
|
91 |
)
|
92 |
|
93 |
def initialize_agent(_cfg, agent_progress_callback=None):
|
94 |
+
proa_capital_bot_instructions = """
|
95 |
+
- You are an expert in market analysis, financial evaluation, and strategic competitor research with extensive experience in the mutual fund and private equity sectors.
|
96 |
+
- Your task is to answer user questions regarding market trends, detailed company profiles, competitor strategies, M&A activity, exit scenarios, and comprehensive financial analysis.
|
97 |
+
- 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.
|
98 |
+
- 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.
|
99 |
+
- 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?"
|
100 |
+
- 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.
|
101 |
+
- 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.
|
102 |
+
- 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.
|
103 |
+
- Provide precise, comprehensive, and evidence-based answers that are accessible to an audience familiar with sophisticated financial analysis and market research.
|
104 |
+
- Include sources and citations in your response, directly referencing the data obtained through the tools.
|
105 |
+
- Your final deliverable should be thorough, clear, and actionable for stakeholders seeking insights on mutual fund market dynamics and competitor strategies.
|
106 |
"""
|
107 |
|
108 |
+
|
109 |
agent = Agent(
|
110 |
tools=create_assistant_tools(_cfg),
|
111 |
+
topic="Market Analysis",
|
112 |
+
custom_instructions=proa_capital_bot_instructions,
|
113 |
agent_progress_callback=agent_progress_callback,
|
114 |
)
|
115 |
agent.report()
|