forked from dforwardfeed/memo_generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagents.py
127 lines (112 loc) · 4.86 KB
/
agents.py
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
#agents.py
import os
from crewai import Agent
from langchain_openai import ChatOpenAI
from langchain.tools import Tool
from crewai_tools import EXASearchTool
#Portkey, fallback to direct OpenAI if not available
try:
from portkey_ai import createHeaders, PORTKEY_GATEWAY_URL
PORTKEY_AVAILABLE = True
except ImportError:
PORTKEY_AVAILABLE = False
print("Portkey not available, falling back to direct OpenAI usage")
def get_portkey_llm(trace_id=None, span_id=None, agent_name=None):
if PORTKEY_AVAILABLE:
headers = createHeaders(
provider="openai",
api_key=os.getenv("PORTKEY_API_KEY"),
trace_id=trace_id,
)
if span_id:
headers['x-portkey-span-id'] = span_id
if agent_name:
headers['x-portkey-span-name'] = f'Agent: {agent_name}'
return ChatOpenAI(
model="gpt-4o",
base_url=PORTKEY_GATEWAY_URL,
default_headers=headers,
api_key=os.getenv("OPENAI_API_KEY")
)
else:
# Fallback to direct OpenAI usage
return ChatOpenAI(
model="gpt-4",
api_key=os.getenv("OPENAI_API_KEY")
)
# EXA Search tool
class CustomEXASearchTool(EXASearchTool):
def __init__(self):
super().__init__(
type='neural',
use_autoprompt=True,
startPublishedDate='2021-10-01T00:00:00.000Z',
endPublishedDate='2023-10-31T23:59:59.999Z',
excludeText=[
'OpenAI', 'Anthropic', 'Google', 'Mistral', 'Microsoft', 'Nvidia',
'general AI market', 'overall AI industry', 'IBM', 'Mistral'
],
numResults=10
)
exa_search_tool = CustomEXASearchTool()
# Market Size tool
def estimate_market_size(data: str) -> str:
return f"Estimated market size based on: {data}"
market_size_tool = Tool(
name="Market Size Estimator",
func=estimate_market_size,
description="Estimates market size based on provided data."
)
# CAGR calculator tool
def calculate_cagr(initial_value: float, final_value: float, num_years: int) -> float:
cagr = (final_value / initial_value) ** (1 / num_years) - 1
return cagr
cagr_tool = Tool(
name="CAGR Calculator",
func=calculate_cagr,
description="Calculates CAGR given initial value, final value, and number of years."
)
# Agents
def create_agent(role, goal, backstory, tools, trace_id=None, agent_name=None):
span_id = os.urandom(16).hex() if trace_id else None
llm = get_portkey_llm(trace_id, span_id, agent_name)
return Agent(
role=role,
goal=goal,
backstory=backstory,
tools=tools,
llm=llm,
verbose=True,
allow_delegation=True,
max_iter=25,
max_execution_time=300
)
def get_market_analyst(trace_id=None):
return create_agent(
role='Market size Research Analyst',
goal='Research and analyze the market size TAM of AI subsegment markets focusing on specialized market sizes and growth rates',
backstory='Expert in doing research and calculating the market size TAM of specific subsegments of the AI market, and growth rates. Also search for sector-specific growth drivers. Known for providing granular market insights rather than general AI market statistics like the overall size of AI market which is irrelevant.',
tools=[exa_search_tool, market_size_tool, cagr_tool],
trace_id=trace_id,
agent_name='market_analyst'
)
def get_competitor_analyst(trace_id=None):
return create_agent(
role='AI Startup Intelligence Specialist',
goal='Identify and analyze relevant AI startups within specific AI subsegment markets',
backstory="""Expert in mapping competitive landscapes for specific AI verticals.
Specialized in identifying real, named emerging startups and scale-ups rather than tech giants like IBM, OpenAI, Google, META, Anthropic, HuggingFace. Known for finding verifiable information about startups' funding, technology, and market focus.""",
tools=[exa_search_tool],
trace_id=trace_id,
agent_name='competitor_analyst'
)
def get_strategy_advisor(trace_id=None):
return create_agent(
role='Project Manager',
goal='Efficiently manage the crew and ensure high-quality task completion with a focus on ensuring that the results are very specific and relevant and not generic and too zoom out',
backstory="""You're an experienced project manager, skilled in overseeing complex projects and guiding teams to success. Your role is to coordinate the efforts of the crew members, ensuring that each task is completed on time and that the results are relevant and specific to the market.""",
tools=[],
trace_id=trace_id,
agent_name='strategy_advisor'
)
__all__ = ['get_market_analyst', 'get_competitor_analyst', 'get_strategy_advisor']