fyodorov-llm-agents 0.4.2__py3-none-any.whl → 0.4.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fyodorov_llm_agents/agents/agent_service.py +148 -0
- fyodorov_llm_agents/instances/instance_service.py +4 -3
- {fyodorov_llm_agents-0.4.2.dist-info → fyodorov_llm_agents-0.4.3.dist-info}/METADATA +1 -1
- {fyodorov_llm_agents-0.4.2.dist-info → fyodorov_llm_agents-0.4.3.dist-info}/RECORD +7 -6
- /fyodorov_llm_agents/agents/{agent.py → agent_model.py} +0 -0
- {fyodorov_llm_agents-0.4.2.dist-info → fyodorov_llm_agents-0.4.3.dist-info}/WHEEL +0 -0
- {fyodorov_llm_agents-0.4.2.dist-info → fyodorov_llm_agents-0.4.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
from datetime import datetime
|
2
|
+
from supabase import Client
|
3
|
+
from fyodorov_llm_agents.agents.agent_model import Agent as AgentModel
|
4
|
+
from fyodorov_utils.config.supabase import get_supabase
|
5
|
+
from fyodorov_llm_agents.tools.tool import Tool as ToolModel
|
6
|
+
from fyodorov_llm_agents.models.llm_service import LLM
|
7
|
+
|
8
|
+
supabase: Client = get_supabase()
|
9
|
+
|
10
|
+
class Agent(AgentModel):
|
11
|
+
@staticmethod
|
12
|
+
async def create_in_db(access_token: str, agent: AgentModel) -> str:
|
13
|
+
try:
|
14
|
+
supabase = get_supabase(access_token)
|
15
|
+
result = supabase.table('agents').upsert(agent.to_dict()).execute()
|
16
|
+
agent_id = result.data[0]['id']
|
17
|
+
return agent_id
|
18
|
+
except Exception as e:
|
19
|
+
print('Error creating agent', str(e))
|
20
|
+
raise e
|
21
|
+
|
22
|
+
@staticmethod
|
23
|
+
async def create_agent_in_db(access_token: str, agent: dict, user_id: str) -> str:
|
24
|
+
try:
|
25
|
+
supabase = get_supabase(access_token)
|
26
|
+
agent['user_id'] = user_id
|
27
|
+
result = supabase.table('agents').upsert(agent).execute()
|
28
|
+
agent_dict = result.data[0]
|
29
|
+
return agent_dict
|
30
|
+
except Exception as e:
|
31
|
+
print('Error creating agent', str(e))
|
32
|
+
raise e
|
33
|
+
|
34
|
+
@staticmethod
|
35
|
+
async def update_in_db(id: str, agent: dict) -> dict:
|
36
|
+
if not id:
|
37
|
+
raise ValueError('Agent ID is required')
|
38
|
+
try:
|
39
|
+
result = supabase.table('agents').update(agent).eq('id', id).execute()
|
40
|
+
return result.data[0]
|
41
|
+
except Exception as e:
|
42
|
+
print('An error occurred while updating agent:', id, str(e))
|
43
|
+
raise
|
44
|
+
|
45
|
+
@staticmethod
|
46
|
+
async def delete_in_db(id: str) -> bool:
|
47
|
+
if not id:
|
48
|
+
raise ValueError('Agent ID is required')
|
49
|
+
try:
|
50
|
+
result = supabase.table('agents').delete().eq('id', id).execute()
|
51
|
+
return True
|
52
|
+
except Exception as e:
|
53
|
+
print('Error deleting agent', str(e))
|
54
|
+
raise e
|
55
|
+
|
56
|
+
@staticmethod
|
57
|
+
async def get_in_db(access_token: str, id: str) -> AgentModel:
|
58
|
+
if not id:
|
59
|
+
raise ValueError('Agent ID is required')
|
60
|
+
try:
|
61
|
+
supabase = get_supabase(access_token)
|
62
|
+
result = supabase.table('agents').select('*').eq('id', id).limit(1).execute()
|
63
|
+
agent_dict = result.data[0]
|
64
|
+
print(f"Fetched agent: {agent_dict}")
|
65
|
+
agent_dict["modelid"] = str(agent_dict["model_id"])
|
66
|
+
model = await LLM.get_model(access_token=access_token, id = agent_dict["modelid"])
|
67
|
+
agent_dict['model'] = model.name
|
68
|
+
agent = AgentModel(**agent_dict)
|
69
|
+
return agent
|
70
|
+
except Exception as e:
|
71
|
+
print('Error fetching agent', str(e))
|
72
|
+
raise e
|
73
|
+
|
74
|
+
@staticmethod
|
75
|
+
async def get_all_in_db(limit: int = 10, created_at_lt: datetime = datetime.now()) -> [dict]:
|
76
|
+
try:
|
77
|
+
result = supabase.from_('agents') \
|
78
|
+
.select("*") \
|
79
|
+
.limit(limit) \
|
80
|
+
.lt('created_at', created_at_lt) \
|
81
|
+
.order('created_at', desc=True) \
|
82
|
+
.execute()
|
83
|
+
agents = result.data
|
84
|
+
print(f"Fetched agents: {agents}")
|
85
|
+
return agents
|
86
|
+
except Exception as e:
|
87
|
+
print('Error fetching agents', str(e))
|
88
|
+
raise e
|
89
|
+
|
90
|
+
@staticmethod
|
91
|
+
async def save_from_dict(access_token: str, user_id: str, data):
|
92
|
+
agent = AgentModel.from_dict(data)
|
93
|
+
agent_dict = agent.to_dict()
|
94
|
+
model_name = data['model']
|
95
|
+
model = await LLM.get_model(access_token, user_id, model_name)
|
96
|
+
if model:
|
97
|
+
agent_dict['model_id'] = model.id
|
98
|
+
del agent_dict['model']
|
99
|
+
print('Saving agent', agent_dict)
|
100
|
+
agent = await Agent.create_agent_in_db(access_token, agent_dict, user_id)
|
101
|
+
return agent
|
102
|
+
|
103
|
+
@staticmethod
|
104
|
+
async def get_agent_tools(access_token: str, agent_id: str) -> list:
|
105
|
+
if not agent_id:
|
106
|
+
raise ValueError('Agent ID is required')
|
107
|
+
supabase = get_supabase(access_token)
|
108
|
+
result = supabase.table('agent_mcp_tools').select('*').eq('agent_id', agent_id).execute()
|
109
|
+
tool_ids = [item['mcp_tool_id'] for item in result.data if 'mcp_tool_id' in item]
|
110
|
+
result = []
|
111
|
+
for tool_id in tool_ids:
|
112
|
+
tool = supabase.table('mcp_tools').select('*').eq('id', tool_id).limit(1).execute()
|
113
|
+
if tool and tool.data:
|
114
|
+
tool_dict = tool.data[0]
|
115
|
+
tool_dict['id'] = str(tool_dict['id'])
|
116
|
+
result.append(tool_dict)
|
117
|
+
return result
|
118
|
+
|
119
|
+
@staticmethod
|
120
|
+
async def assign_agent_tools(access_token: str, agent_id: str, tool_ids: list[ToolModel]) -> list:
|
121
|
+
if not tool_ids:
|
122
|
+
raise ValueError('Agent IDs are required')
|
123
|
+
supabase = get_supabase(access_token)
|
124
|
+
result = []
|
125
|
+
for tool_id in tool_ids:
|
126
|
+
# Check if tool is valid and exists in the database
|
127
|
+
tool_result = supabase.table('mcp_tools').select('*').eq('id', tool_id).limit(1).execute()
|
128
|
+
if not tool_result.data:
|
129
|
+
print(f"Tool with ID {tool_id} does not exist.")
|
130
|
+
continue
|
131
|
+
supabase.table('agent_mcp_tools').insert({'mcp_tool_id': tool_id, 'agent_id': agent_id}).execute()
|
132
|
+
print('Inserted tool', tool_id, 'for agent', agent_id)
|
133
|
+
result.append(tool_id)
|
134
|
+
return result
|
135
|
+
|
136
|
+
@staticmethod
|
137
|
+
async def delete_agent_tool_connection(access_token: str, agent_id: str, tool_id: str) -> list:
|
138
|
+
if not agent_id:
|
139
|
+
raise ValueError('Agent ID is required')
|
140
|
+
if not tool_id:
|
141
|
+
raise ValueError('Tool ID is required')
|
142
|
+
try:
|
143
|
+
supabase = get_supabase(access_token)
|
144
|
+
result = supabase.table('agent_mcp_tools').delete().eq('agent_id', agent_id).eq('mcp_tool_id', tool_id).execute()
|
145
|
+
return True
|
146
|
+
except Exception as e:
|
147
|
+
print('Error deleting agent tool', str(e))
|
148
|
+
raise e
|
@@ -1,12 +1,13 @@
|
|
1
1
|
from datetime import datetime
|
2
2
|
from supabase import Client
|
3
3
|
from fyodorov_utils.config.supabase import get_supabase
|
4
|
-
from .agent import Agent
|
5
|
-
from .providers.provider_service import Provider
|
6
4
|
|
7
|
-
from fyodorov_llm_agents.
|
5
|
+
from fyodorov_llm_agents.providers.provider_service import Provider
|
6
|
+
from fyodorov_llm_agents.agents.agent_model import Agent as AgentModel
|
8
7
|
from fyodorov_llm_agents.models.llm_model import LLMModel
|
9
8
|
from fyodorov_llm_agents.models.llm_service import LLM
|
9
|
+
from fyodorov_llm_agents.agents.agent_service import Agent
|
10
|
+
|
10
11
|
from .instance_model import InstanceModel
|
11
12
|
|
12
13
|
supabase: Client = get_supabase()
|
@@ -1,7 +1,8 @@
|
|
1
|
-
fyodorov_llm_agents/agents/
|
1
|
+
fyodorov_llm_agents/agents/agent_model.py,sha256=vVBCEBpG11m4ae11Mr94rF5TJpuBluI_loQPDTw734w,5044
|
2
|
+
fyodorov_llm_agents/agents/agent_service.py,sha256=-55RDait3eZGFfYWGNLGoa06WMcdiBnkzpa7BnWW10Q,6016
|
2
3
|
fyodorov_llm_agents/agents/openai.py,sha256=FA5RS7yn3JwvFA8PXju60XSYC_2oUZFNgBUzeIYtGv0,1154
|
3
4
|
fyodorov_llm_agents/instances/instance_model.py,sha256=PQaoVSH9H4qp_wcLvyT_QgvNtwf9oehOxZaGI6mv1bA,1206
|
4
|
-
fyodorov_llm_agents/instances/instance_service.py,sha256=
|
5
|
+
fyodorov_llm_agents/instances/instance_service.py,sha256=8tXWimECQd0Ks5Q9j2S2wvfJd7j9CPvLG6tLmdzGqXg,8281
|
5
6
|
fyodorov_llm_agents/models/llm_model.py,sha256=aQtXtB7kRpnVdbPu-nmTGAaflbtKz3DPkgcckf1srsg,1645
|
6
7
|
fyodorov_llm_agents/models/llm_service.py,sha256=613PLLGiDzkCfkVbt0XDlRwTQRL06QPyr9bfsbwQtPk,3989
|
7
8
|
fyodorov_llm_agents/providers/provider_model.py,sha256=OyCK6WMRhyElsp88gILg0wso-OPHI7f55gEeypsJ7O0,957
|
@@ -9,7 +10,7 @@ fyodorov_llm_agents/providers/provider_service.py,sha256=GST-NLV8aLPsvapQEvgT_qH
|
|
9
10
|
fyodorov_llm_agents/tools/mcp_tool_model.py,sha256=i7oFZReVGZsHN2K8T7mCAGF4t92wMMIR9mCkRHUgKsI,4413
|
10
11
|
fyodorov_llm_agents/tools/mcp_tool_service.py,sha256=9tDvSdKpEAOKKU5MHImUqTOc6MZyk1hEjs3GpzgQUsk,5542
|
11
12
|
fyodorov_llm_agents/tools/tool.py,sha256=HyOk0X_3XE23sa8J-8UZx657tJ0sxwZWMbA4OPxXU6E,7940
|
12
|
-
fyodorov_llm_agents-0.4.
|
13
|
-
fyodorov_llm_agents-0.4.
|
14
|
-
fyodorov_llm_agents-0.4.
|
15
|
-
fyodorov_llm_agents-0.4.
|
13
|
+
fyodorov_llm_agents-0.4.3.dist-info/METADATA,sha256=MlHKLuddV5d6uMEBC6RPUYZ7OeW_yb6uG4jH12lJGNM,550
|
14
|
+
fyodorov_llm_agents-0.4.3.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
15
|
+
fyodorov_llm_agents-0.4.3.dist-info/top_level.txt,sha256=4QOslsBp8Gh7ng25DceA7fHp4KguTIdAxwURz97gH-g,20
|
16
|
+
fyodorov_llm_agents-0.4.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|