-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathagent_loader.py
51 lines (42 loc) · 1.41 KB
/
agent_loader.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
import json
class AgentLoader:
def __init__(self):
self.agents = self.load_agents()
def get_agent_names(self):
return self.agents.keys()
def load_agents(self):
agents = {}
with open("agents/agents.json") as f:
agents_data = json.load(f)
for agent in agents_data:
agents[agent["id"]] = agent
return agents
def get_agent(self, id, case_sensitive=False):
agent = None
if case_sensitive:
agent = self.agents.get(id, None)
else:
for name, agent in self.agents.items():
if name.lower() == id.lower():
agent = agent
break
#print(f"Debug: AgentLoader.get_agent('{id}') returned: {agent}")
return agent
def is_agent_email(self, email):
"""Check if the given email belongs to one of the agents."""
return bool(self.get_agent_by_email(email))
def get_agent_persona(self, id, case_sensitive=False):
agent = self.get_agent(id, case_sensitive)
if agent:
persona = agent.get("persona", None)
# print(f"Debug: AgentLoader.get_agent_persona('{id}') returned: {persona}")
return persona
else:
print(f"Debug: AgentLoader.get_agent_persona('{id}') found no agent.")
return None
def get_agent_by_email(self, email):
local_part = email.split('@')[0].lower()
for agent_id, agent in self.agents.items():
if agent_id.lower() == local_part:
return agent
return None