Visionary_Ai_2 / phase1_agents.py
GiantAnalytics's picture
Create phase1_agents.py
6dbe477 verified
raw
history blame
3.24 kB
import os
from phi.agent import Agent
from phi.tools.firecrawl import FirecrawlTools
from phi.tools.duckduckgo import DuckDuckGo
from phi.model.openai import OpenAIChat
from pydantic import BaseModel, Field
from fastapi import UploadFile
# Load environment variables (API keys, etc.)
from dotenv import load_dotenv
load_dotenv()
#####################################################################################
# PHASE 1 #
#####################################################################################
##############################
# 1️⃣ Company Search Agent #
##############################
company_search_agent = Agent(
name="Company Search Agent",
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGo()],
description="Finds company details based on name using web search.",
instructions=["Always include sources in search results."],
show_tool_calls=True,
markdown=True,
)
def search_company(company_name: str) -> dict:
""" Searches for detailed company information using web search. """
query = f"Find details for {company_name}, including its official website, mission, services, and AI-related initiatives. Include sources."
response = company_search_agent.print_response(query)
return {"company_name": company_name, "details": response}
##############################
# 2️⃣ Website Scraper Agent #
##############################
firecrawl_agent = Agent(
name="Website Scraper Agent",
tools=[FirecrawlTools(scrape=True, crawl=False)],
description="Extracts content from company websites.",
show_tool_calls=True,
markdown=True,
)
def scrape_website(url: str) -> dict:
""" Scrapes relevant company information from the given website. """
response = firecrawl_agent.print_response(f"Extract business details from {url}, including mission, services, and AI-related information.")
return {"website": url, "scraped_data": response}
##############################
# 3️⃣ Text Processing Agent #
##############################
class CompanySummary(BaseModel):
summary: str = Field(..., description="Summarized company details.")
text_processing_agent = Agent(
model=OpenAIChat(id="gpt-4o"),
description="Summarizes user-written company descriptions.",
response_model=CompanySummary,
)
def process_company_description(text: str) -> dict:
""" Summarizes the user-provided company description. """
response = text_processing_agent.print_response(f"Summarize the following description: {text}. Focus on mission, key services, industry, and AI potential.")
return {"user_description": text, "summary": response}
##############################
# 4️⃣ Document Processing Agent #
##############################
def process_uploaded_document(file: UploadFile) -> dict:
""" Reads and processes an uploaded document, returning extracted content. """
file_path = f"tmp/{file.filename}"
with open(file_path, "wb") as buffer:
buffer.write(file.file.read())
with open(file_path, "r", encoding="utf-8") as f:
document_text = f.read()
return {"document_name": file.filename, "content": document_text}