GiantAnalytics commited on
Commit
02d400e
·
verified ·
1 Parent(s): 27b69f6

Create VisionaryAgent

Browse files
Files changed (1) hide show
  1. VisionaryAgent +363 -0
VisionaryAgent ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from phi.agent import Agent
3
+ from phi.tools.firecrawl import FirecrawlTools
4
+ from phi.tools.duckduckgo import DuckDuckGo
5
+ from phi.model.openai import OpenAIChat
6
+ from phi.knowledge.pdf import PDFUrlKnowledgeBase
7
+ from phi.embedder.openai import OpenAIEmbedder
8
+ from phi.vectordb.lancedb import LanceDb, SearchType
9
+ from selenium import webdriver
10
+ from selenium.webdriver.common.by import By
11
+ from selenium.webdriver.common.keys import Keys
12
+ import helium
13
+ from typing import List
14
+ from pydantic import BaseModel, Field
15
+ from fastapi import UploadFile
16
+
17
+ # Load environment variables (API keys, etc.)
18
+ from dotenv import load_dotenv
19
+ load_dotenv()
20
+
21
+ #####################################################################################
22
+ # PHASE 1 #
23
+ #####################################################################################
24
+
25
+
26
+ ##############################
27
+ # 1️⃣ Company Search Agent #
28
+ ##############################
29
+ company_search_agent = Agent(
30
+ name="Company Search Agent",
31
+ model=OpenAIChat(id="gpt-4o"),
32
+ tools=[DuckDuckGo()],
33
+ description="Finds company details based on name using web search.",
34
+ instructions=["Always include sources in search results."],
35
+ show_tool_calls=True,
36
+ markdown=True,
37
+ )
38
+
39
+ def search_company(company_name: str):
40
+ query = f"Find detailed company information for {company_name}. Extract its official website, mission, services, and any AI-related initiatives. Prioritize official sources and provide links where available."
41
+ return company_search_agent.print_response(query)
42
+
43
+
44
+ ##############################
45
+ # 2️⃣ Website Scraper Agent #
46
+ ##############################
47
+ firecrawl_agent = Agent(
48
+ name="Website Scraper Agent",
49
+ tools=[FirecrawlTools(scrape=True, crawl=False)],
50
+ description="Extracts content from company websites.",
51
+ show_tool_calls=True,
52
+ markdown=True,
53
+ )
54
+
55
+ def scrape_website(url: str):
56
+ return firecrawl_agent.print_response(f"Extract all relevant business information from {url}, including mission statement, services, case studies, and AI-related content. Provide structured output.")
57
+
58
+ # Helium for dynamic websites
59
+ chrome_options = webdriver.ChromeOptions()
60
+ chrome_options.add_argument("--headless")
61
+ driver = helium.start_chrome(headless=True, options=chrome_options)
62
+
63
+ def scrape_dynamic_website(url: str):
64
+ helium.go_to(url)
65
+ text = helium.get_driver().page_source
66
+ return text
67
+
68
+
69
+ ##############################
70
+ # 3️⃣ Text Processing Agent #
71
+ ##############################
72
+ class CompanySummary(BaseModel):
73
+ summary: str = Field(..., description="Summarized company details based on user input.")
74
+
75
+ text_processing_agent = Agent(
76
+ model=OpenAIChat(id="gpt-4o"),
77
+ description="Summarizes user-written company descriptions.",
78
+ response_model=CompanySummary,
79
+ )
80
+
81
+ def process_company_description(text: str):
82
+ return text_processing_agent.print_response(f"Summarize the following company description: {text}. Focus on key services, mission, industry, and potential AI use cases where applicable.")
83
+
84
+
85
+ #################################
86
+ # 4️⃣ Document Processing Agent #
87
+ #################################
88
+ # LanceDB for storing extracted knowledge
89
+ knowledge_base = PDFUrlKnowledgeBase(
90
+ urls=[], # PDFs will be dynamically added
91
+ vector_db=LanceDb(
92
+ table_name="company_docs",
93
+ uri="tmp/lancedb",
94
+ search_type=SearchType.vector,
95
+ embedder=OpenAIEmbedder(model="text-embedding-3-small"),
96
+ ),
97
+ )
98
+ knowledge_base.load(recreate=False)
99
+
100
+ document_processing_agent = Agent(
101
+ model=OpenAIChat(id="gpt-4o"),
102
+ knowledge=knowledge_base,
103
+ description="Extracts and processes data from uploaded PDFs/PPTs.",
104
+ show_tool_calls=True,
105
+ markdown=True,
106
+ )
107
+
108
+ def process_uploaded_document(file: UploadFile):
109
+ file_path = f"tmp/{file.filename}"
110
+ with open(file_path, "wb") as buffer:
111
+ buffer.write(file.file.read())
112
+
113
+ knowledge_base.load(recreate=False)
114
+ return document_processing_agent.print_response(f"Analyze and extract key insights from the uploaded document: {file.filename}. Summarize business operations, AI-related discussions, financial details, and relevant strategic insights.")
115
+
116
+
117
+ #####################################################################################
118
+ # PHASE 2 #
119
+ #####################################################################################
120
+
121
+
122
+ ###########################
123
+ # Example Usage #
124
+ ###########################
125
+ # if __name__ == "__main__":
126
+ # company_name = "Tesla"
127
+ # print("Company Search Results:")
128
+ # search_company(company_name)
129
+
130
+ # website_url = "https://www.tesla.com"
131
+ # print("\nScraped Website Data:")
132
+ # scrape_website(website_url)
133
+
134
+ # user_description = "We are a renewable energy startup focusing on solar solutions."
135
+ # print("\nProcessed Company Description:")
136
+ # process_company_description(user_description)
137
+
138
+ # Example of handling an uploaded file
139
+ # process_uploaded_document(uploaded_file)
140
+
141
+
142
+ import os
143
+ from phi.agent import Agent
144
+ from phi.tools.duckduckgo import DuckDuckGo
145
+ from phi.tools.exa import ExaTools
146
+ from phi.model.openai import OpenAIChat
147
+ from typing import List
148
+ from pydantic import BaseModel, Field
149
+
150
+ # Load environment variables (API keys, etc.)
151
+ from dotenv import load_dotenv
152
+ load_dotenv()
153
+
154
+ ##############################
155
+ # 1️⃣ Industry Trends Agent #
156
+ ##############################
157
+ industry_trends_agent = Agent(
158
+ name="Industry Trends Agent",
159
+ model=OpenAIChat(id="gpt-4o"),
160
+ tools=[ExaTools(include_domains=["cnbc.com", "reuters.com", "bloomberg.com"])],
161
+ description="Finds the latest AI advancements in a given industry.",
162
+ show_tool_calls=True,
163
+ markdown=True,
164
+ )
165
+
166
+ def get_industry_trends(industry: str):
167
+ query = f"Find the latest AI advancements, innovations, and emerging technologies in the {industry} sector. Include breakthroughs, adoption trends, and notable implementations by leading companies. Provide references and insights from credible sources."
168
+ return industry_trends_agent.print_response(query)
169
+
170
+
171
+ ##################################
172
+ # 2️⃣ AI Use Case Discovery Agent #
173
+ ##################################
174
+ ai_use_case_agent = Agent(
175
+ name="AI Use Case Discovery Agent",
176
+ model=OpenAIChat(id="gpt-4o"),
177
+ tools=[DuckDuckGo()],
178
+ description="Identifies AI applications relevant to a given industry.",
179
+ show_tool_calls=True,
180
+ markdown=True,
181
+ )
182
+
183
+ def get_ai_use_cases(industry: str):
184
+ query = f"Identify the most impactful AI use cases in the {industry} sector. Include real-world applications, automation improvements, cost-saving innovations, and data-driven decision-making processes. Provide case studies and examples of successful AI implementation."
185
+ return ai_use_case_agent.print_response(query)
186
+
187
+
188
+ ####################################
189
+ # 3️⃣ Competitive Analysis Agent #
190
+ ####################################
191
+ competitive_analysis_agent = Agent(
192
+ name="Competitive Analysis Agent",
193
+ model=OpenAIChat(id="gpt-4o"),
194
+ tools=[DuckDuckGo(), ExaTools(include_domains=["techcrunch.com", "forbes.com", "businessinsider.com"])],
195
+ description="Analyzes how competitors are using AI in their businesses.",
196
+ show_tool_calls=True,
197
+ markdown=True,
198
+ )
199
+
200
+ def get_competitor_ai_strategies(company_name: str):
201
+ query = f"Analyze how {company_name} is leveraging AI in its business operations. Find recent reports, product innovations, automation strategies, and AI-driven transformations. Highlight competitive advantages gained through AI adoption. Provide references and sources."
202
+ return competitive_analysis_agent.print_response(query)
203
+
204
+
205
+ ###########################
206
+ # Example Usage #
207
+ ###########################
208
+ # if __name__ == "__main__":
209
+ # industry = "Healthcare"
210
+ # print("Industry Trends:")
211
+ # get_industry_trends(industry)
212
+
213
+ # print("\nAI Use Cases:")
214
+ # get_ai_use_cases(industry)
215
+
216
+ # competitor = "Pfizer"
217
+ # print("\nCompetitor AI Strategies:")
218
+ # get_competitor_ai_strategies(competitor)
219
+
220
+
221
+ #####################################################################################
222
+ # PHASE 3 #
223
+ #####################################################################################
224
+
225
+
226
+ ##############################
227
+ # 1️⃣ Reasoning Agent #
228
+ ##############################
229
+ reasoning_agent = Agent(
230
+ name="Reasoning Agent",
231
+ model=OpenAIChat(id="gpt-4o"),
232
+ description="Processes all collected data and generates structured AI adoption strategies.",
233
+ show_tool_calls=True,
234
+ markdown=True,
235
+ )
236
+
237
+ def generate_ai_strategy(company_data: str, industry_trends: str, ai_use_cases: str, competitor_analysis: str):
238
+ query = f"""
239
+ You are an AI business strategist analyzing a company's potential AI adoption. Given the following:
240
+
241
+ - **Company Overview:** {company_data}
242
+ - **Industry Trends:** {industry_trends}
243
+ - **AI Use Cases:** {ai_use_cases}
244
+ - **Competitor AI Strategies:** {competitor_analysis}
245
+
246
+ Generate a structured AI adoption strategy that includes:
247
+ 1. **AI Opportunities**: Identify key areas where AI can enhance operations, customer experience, or business efficiency.
248
+ 2. **Technology Fit**: Recommend specific AI tools, models, or methodologies that fit this company's needs.
249
+ 3. **Implementation Roadmap**: Step-by-step guidance on integrating AI, considering costs, scalability, and ROI.
250
+ 4. **Future Scalability**: How AI adoption can evolve over time for long-term growth.
251
+
252
+ Provide structured insights with a logical flow and avoid generic statements. Use industry benchmarks where possible.
253
+ """
254
+ return reasoning_agent.print_response(query)
255
+
256
+
257
+ ##############################
258
+ # 2️⃣ AI Integration Advisor #
259
+ ##############################
260
+ ai_integration_agent = Agent(
261
+ name="AI Integration Advisor",
262
+ model=OpenAIChat(id="gpt-4o"),
263
+ description="Suggests AI implementation strategies based on industry insights and company operations.",
264
+ show_tool_calls=True,
265
+ markdown=True,
266
+ )
267
+
268
+ def suggest_ai_integration(company_data: str, ai_strategy: str):
269
+ query = f"""
270
+ Based on the AI adoption strategy:
271
+
272
+ - **Company Context:** {company_data}
273
+ - **AI Strategy Summary:** {ai_strategy}
274
+
275
+ Provide a structured AI implementation plan:
276
+ 1. **Step-by-step AI Integration**: List phases of AI adoption, from pilot testing to full deployment.
277
+ 2. **Technology & Infrastructure**: Recommend necessary AI tools, cloud platforms, and software.
278
+ 3. **Workforce & Training**: Suggest ways to upskill employees for AI adoption.
279
+ 4. **Risk & Compliance Considerations**: Highlight data security, compliance, and ethical concerns.
280
+ 5. **KPIs for Success**: Define measurable AI performance indicators.
281
+
282
+ The output should be detailed, actionable, and specific to the business domain.
283
+ """
284
+ return ai_integration_agent.print_response(query)
285
+
286
+
287
+ ##############################
288
+ # 3️⃣ Revenue Growth Agent #
289
+ ##############################
290
+ revenue_growth_agent = Agent(
291
+ name="Revenue Growth Agent",
292
+ model=OpenAIChat(id="gpt-4o"),
293
+ description="Identifies AI-driven opportunities to enhance revenue and efficiency.",
294
+ show_tool_calls=True,
295
+ markdown=True,
296
+ )
297
+
298
+ def identify_revenue_opportunities(company_data: str, ai_strategy: str):
299
+ query = f"""
300
+ You are an AI business analyst tasked with identifying AI-driven revenue growth opportunities for:
301
+
302
+ - **Company Overview:** {company_data}
303
+ - **AI Strategy:** {ai_strategy}
304
+
305
+ Provide:
306
+ 1. **AI Monetization Strategies**: Explain how AI can create new revenue streams (e.g., AI-driven products, services, or data monetization).
307
+ 2. **Cost Reduction & Efficiency Gains**: Highlight AI automation that lowers operational costs.
308
+ 3. **Market Expansion**: Discuss how AI can help enter new markets or scale offerings.
309
+ 4. **Competitive Positioning**: Compare with industry leaders and suggest differentiation tactics.
310
+
311
+ Ensure detailed, actionable insights with real-world examples where applicable.
312
+ """
313
+ return revenue_growth_agent.print_response(query)
314
+
315
+
316
+ ##############################
317
+ # 4️⃣ Report Generation Agent #
318
+ ##############################
319
+ def generate_report(company_name: str, ai_strategy: str, ai_integration: str, revenue_opportunities: str):
320
+ report_content = f"""
321
+ # AI Strategy Report for {company_name}
322
+
323
+ ## AI Adoption Strategy
324
+ {ai_strategy}
325
+
326
+ ## AI Implementation Plan
327
+ {ai_integration}
328
+
329
+ ## Revenue Growth Opportunities
330
+ {revenue_opportunities}
331
+
332
+ """
333
+
334
+ # Convert to Markdown
335
+ markdown_report = markdown2.markdown(report_content)
336
+
337
+ # Convert Markdown to PDF
338
+ pdfkit.from_string(markdown_report, f"{company_name}_AI_Report.pdf")
339
+
340
+ return f"Report generated: {company_name}_AI_Report.pdf"
341
+
342
+
343
+ ###########################
344
+ # Example Usage #
345
+ ###########################
346
+ # if __name__ == "__main__":
347
+ # company_name = "Tesla"
348
+ # company_data = "Tesla specializes in electric vehicles and AI-powered self-driving technology."
349
+ # industry_trends = "Latest AI advancements in autonomous driving and battery optimization."
350
+ # ai_use_cases = "AI used in predictive maintenance, customer behavior analysis, and automation."
351
+ # competitor_analysis = "Ford and GM are integrating AI into manufacturing and autonomous vehicle tech."
352
+
353
+ # print("Generating AI Strategy...")
354
+ # ai_strategy = generate_ai_strategy(company_data, industry_trends, ai_use_cases, competitor_analysis)
355
+
356
+ # print("\nSuggesting AI Integration Plan...")
357
+ # ai_integration = suggest_ai_integration(company_data, ai_strategy)
358
+
359
+ # print("\nIdentifying Revenue Growth Opportunities...")
360
+ # revenue_opportunities = identify_revenue_opportunities(company_data, ai_strategy)
361
+
362
+ # print("\nGenerating Final Report...")
363
+ # generate_report(company_name, ai_strategy, ai_integration, revenue_opportunities)