fyodorov-llm-agents 0.4.41__py3-none-any.whl → 0.4.43__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.
@@ -1,8 +1,6 @@
1
- import os
2
1
  import re
3
2
  from pydantic import BaseModel, HttpUrl
4
3
  from typing import Optional
5
- import litellm
6
4
  from fyodorov_llm_agents.tools.mcp_tool_service import MCPTool as ToolService
7
5
  from datetime import datetime
8
6
 
@@ -23,6 +21,7 @@ class Agent(BaseModel):
23
21
  description: str = "My Agent Description"
24
22
  prompt: str = "My Prompt"
25
23
  prompt_size: int = 10000
24
+ public: bool | None = False
26
25
 
27
26
  class Config:
28
27
  arbitrary_types_allowed = True
@@ -81,89 +80,6 @@ class Agent(BaseModel):
81
80
  # }
82
81
 
83
82
 
84
- async def call_with_fn_calling(self, input: str = "", history = [], user_id: str = "") -> dict:
85
- litellm.set_verbose = True
86
- model = self.model
87
- # Set environmental variable
88
- if self.api_key.startswith('sk-'):
89
- model = 'openai/'+self.model
90
- os.environ["OPENAI_API_KEY"] = self.api_key
91
- self.api_url = "https://api.openai.com/v1"
92
- elif self.api_key and self.api_key != '':
93
- model = 'mistral/'+self.model
94
- os.environ["MISTRAL_API_KEY"] = self.api_key
95
- self.api_url = "https://api.mistral.ai/v1"
96
- else:
97
- print("Provider Ollama")
98
- model = 'ollama/'+self.model
99
- if self.api_url is None:
100
- self.api_url = "https://api.ollama.ai/v1"
101
-
102
- base_url = str(self.api_url.rstrip('/'))
103
- messages: list[dict] = [
104
- {"content": self.prompt, "role": "system"},
105
- *history,
106
- { "content": input, "role": "user"},
107
- ]
108
- # tools
109
- print(f"Tools: {self.tools}")
110
- mcp_tools = []
111
- for tool in self.tools:
112
- try:
113
- tool_instance = await ToolService.get_by_name_and_user_id(tool, user_id)
114
- mcp_tools.append(tool_instance)
115
- except Exception as e:
116
- print(f"Error fetching tool {tool}: {e}")
117
-
118
- tool_schemas = [tool.get_function() for tool in mcp_tools]
119
- print(f"Tool schemas: {tool_schemas}")
120
- if tool_schemas:
121
- print(f"calling litellm with model {model}, messages: {messages}, max_retries: 0, history: {history}, base_url: {base_url}, tools: {tool_schemas}")
122
- response = litellm.completion(model=model, messages=messages, max_retries=0, base_url=base_url)
123
- else:
124
- print(f"calling litellm with model {model}, messages: {messages}, max_retries: 0, history: {history}, base_url: {base_url}")
125
- response = litellm.completion(model=model, messages=messages, max_retries=0, base_url=base_url)
126
- print(f"Response: {response}")
127
-
128
- message = response.choices[0].message
129
-
130
- if hasattr(message, "tool_calls") and message.tool_calls:
131
- tool_call = message.tool_calls[0]
132
- fn_name = tool_call.function.name
133
- args = tool_call.function.arguments
134
-
135
- mcp_tool = mcp_tools.get(fn_name)
136
- if not mcp_tool:
137
- raise ValueError(f"Tool '{fn_name}' not found in loaded MCP tools")
138
-
139
- tool_output = mcp_tool.call(args)
140
-
141
- messages.append({
142
- "role": "assistant",
143
- "content": None,
144
- "tool_calls": [tool_call],
145
- })
146
- messages.append({
147
- "role": "tool",
148
- "tool_call_id": tool_call.id,
149
- "content": tool_output,
150
- })
151
-
152
- followup = litellm.completion(
153
- model=model,
154
- messages=messages,
155
- max_retries=0,
156
- base_url=base_url,
157
- )
158
- return {"answer": followup.choices[0].message.content}
159
-
160
- answer = message.content
161
- print(f"Answer: {answer}")
162
- return {
163
- "answer": answer,
164
-
165
- }
166
-
167
83
  @staticmethod
168
84
  def call_api(url: str = "", method: str = "GET", body: dict = {}) -> dict:
169
85
  if not url:
@@ -1,9 +1,12 @@
1
1
  from datetime import datetime
2
+ import os
2
3
  from supabase import Client
3
- from fyodorov_llm_agents.agents.agent_model import Agent as AgentModel
4
+ import litellm
4
5
  from fyodorov_utils.config.supabase import get_supabase
6
+ from fyodorov_llm_agents.agents.agent_model import Agent as AgentModel
5
7
  from fyodorov_llm_agents.tools.tool import Tool as ToolModel
6
8
  from fyodorov_llm_agents.models.llm_service import LLM
9
+ from fyodorov_llm_agents.providers.provider_service import Provider
7
10
 
8
11
  supabase: Client = get_supabase()
9
12
 
@@ -86,6 +89,7 @@ class Agent(AgentModel):
86
89
  else:
87
90
  result = supabase.from_('agents') \
88
91
  .select("*") \
92
+ .eq('public', True) \
89
93
  .limit(limit) \
90
94
  .lt('created_at', created_at_lt) \
91
95
  .order('created_at', desc=True) \
@@ -158,3 +162,98 @@ class Agent(AgentModel):
158
162
  except Exception as e:
159
163
  print('Error deleting agent tool', str(e))
160
164
  raise e
165
+
166
+ async def call_with_fn_calling(self, input: str = "", history = [], user_id: str = "") -> dict:
167
+ litellm.set_verbose = True
168
+ model = self.model
169
+ # Set environmental variable
170
+ if self.model_id:
171
+ model_instance = await LLM.get_model(self.access_token, user_id, id = self.model_id)
172
+ model = model_instance.base_model
173
+ provider = await Provider.get_provider_by_id(model.provider_id)
174
+ else:
175
+ print(f"Model ID not set on Agent {self.id}, using assumptions")
176
+ if provider:
177
+ self.api_key = provider.api_key
178
+ self.api_url = provider.api_url
179
+ if provider.name == "gemini":
180
+ model = 'gemini/'+self.model
181
+ os.environ["GEMINI_API_KEY"] = self.api_key
182
+ elif self.api_key.startswith('sk-'):
183
+ model = 'openai/'+self.model
184
+ os.environ["OPENAI_API_KEY"] = self.api_key
185
+ self.api_url = "https://api.openai.com/v1"
186
+ elif self.api_key and self.api_key != '':
187
+ model = 'mistral/'+self.model
188
+ os.environ["MISTRAL_API_KEY"] = self.api_key
189
+ self.api_url = "https://api.mistral.ai/v1"
190
+ else:
191
+ print("Provider Ollama")
192
+ model = 'ollama/'+self.model
193
+ if self.api_url is None:
194
+ self.api_url = "https://api.ollama.ai/v1"
195
+
196
+ base_url = str(self.api_url.rstrip('/'))
197
+ messages: list[dict] = [
198
+ {"content": self.prompt, "role": "system"},
199
+ *history,
200
+ { "content": input, "role": "user"},
201
+ ]
202
+ # tools
203
+ print(f"Tools: {self.tools}")
204
+ mcp_tools = []
205
+ for tool in self.tools:
206
+ try:
207
+ tool_instance = await ToolService.get_by_name_and_user_id(tool, user_id)
208
+ mcp_tools.append(tool_instance)
209
+ except Exception as e:
210
+ print(f"Error fetching tool {tool}: {e}")
211
+
212
+ tool_schemas = [tool.get_function() for tool in mcp_tools]
213
+ print(f"Tool schemas: {tool_schemas}")
214
+ if tool_schemas:
215
+ print(f"calling litellm with model {model}, messages: {messages}, max_retries: 0, history: {history}, base_url: {base_url}, tools: {tool_schemas}")
216
+ response = litellm.completion(model=model, messages=messages, max_retries=0, base_url=base_url)
217
+ else:
218
+ print(f"calling litellm with model {model}, messages: {messages}, max_retries: 0, history: {history}, base_url: {base_url}")
219
+ response = litellm.completion(model=model, messages=messages, max_retries=0, base_url=base_url)
220
+ print(f"Response: {response}")
221
+
222
+ message = response.choices[0].message
223
+
224
+ if hasattr(message, "tool_calls") and message.tool_calls:
225
+ tool_call = message.tool_calls[0]
226
+ fn_name = tool_call.function.name
227
+ args = tool_call.function.arguments
228
+
229
+ mcp_tool = mcp_tools.get(fn_name)
230
+ if not mcp_tool:
231
+ raise ValueError(f"Tool '{fn_name}' not found in loaded MCP tools")
232
+
233
+ tool_output = mcp_tool.call(args)
234
+
235
+ messages.append({
236
+ "role": "assistant",
237
+ "content": None,
238
+ "tool_calls": [tool_call],
239
+ })
240
+ messages.append({
241
+ "role": "tool",
242
+ "tool_call_id": tool_call.id,
243
+ "content": tool_output,
244
+ })
245
+
246
+ followup = litellm.completion(
247
+ model=model,
248
+ messages=messages,
249
+ max_retries=0,
250
+ base_url=base_url,
251
+ )
252
+ return {"answer": followup.choices[0].message.content}
253
+
254
+ answer = message.content
255
+ print(f"Answer: {answer}")
256
+ return {
257
+ "answer": answer,
258
+
259
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fyodorov_llm_agents
3
- Version: 0.4.41
3
+ Version: 0.4.43
4
4
  Summary: LLM agents for the Fyodorov AI suite
5
5
  Author-email: Daniel Ransom <02masseur.alibis@icloud.com>
6
6
  Project-URL: Homepage, https://github.com/FyodorovAI/fyodorov-llm-agents
@@ -1,6 +1,6 @@
1
1
  fyodorov_llm_agents/base_model.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- fyodorov_llm_agents/agents/agent_model.py,sha256=EA3SiUSUGn1kBmUE4wgwds3CI-ghYSoR8N0J0oCUCpk,7052
3
- fyodorov_llm_agents/agents/agent_service.py,sha256=qm3oGtgrbTV3LfmVYTIrZDs4GwmghdRAxxb3gkrS2i4,6553
2
+ fyodorov_llm_agents/agents/agent_model.py,sha256=OpsnLenPfro_nTvp_oatey8BPsb5kGX1K-ctdGkGqwU,3805
3
+ fyodorov_llm_agents/agents/agent_service.py,sha256=C2Md4igdoJSCPvS52uPxaWqeBWPma8avAT1enl7AkpM,10535
4
4
  fyodorov_llm_agents/agents/openai.py,sha256=FA5RS7yn3JwvFA8PXju60XSYC_2oUZFNgBUzeIYtGv0,1154
5
5
  fyodorov_llm_agents/instances/instance_model.py,sha256=swRzCXeUk2FFKzGMEjeToklBJRK7GdAJl1ZIoQALuxs,1368
6
6
  fyodorov_llm_agents/instances/instance_service.py,sha256=Vonsz4wQZA-KOkS-q1Hd8DH0obBj7O19Xzovdv0stNY,8857
@@ -11,7 +11,7 @@ fyodorov_llm_agents/providers/provider_service.py,sha256=2DiInqVnaxL5iG6cPX5uxQq
11
11
  fyodorov_llm_agents/tools/mcp_tool_model.py,sha256=aCJGW1WZoeTX5UVD8K-ljUTf0dxPLpPZphIKZTIuipM,5278
12
12
  fyodorov_llm_agents/tools/mcp_tool_service.py,sha256=ijgR74pLcH9Bk-b-yAo9I8ZcXHJcrZOrgoWYGljxGhA,7697
13
13
  fyodorov_llm_agents/tools/tool.py,sha256=HyOk0X_3XE23sa8J-8UZx657tJ0sxwZWMbA4OPxXU6E,7940
14
- fyodorov_llm_agents-0.4.41.dist-info/METADATA,sha256=q6BQq9B1ZzJxIqdfdG6PZ3ELTopLaMT32UydyStY6eg,551
15
- fyodorov_llm_agents-0.4.41.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
16
- fyodorov_llm_agents-0.4.41.dist-info/top_level.txt,sha256=4QOslsBp8Gh7ng25DceA7fHp4KguTIdAxwURz97gH-g,20
17
- fyodorov_llm_agents-0.4.41.dist-info/RECORD,,
14
+ fyodorov_llm_agents-0.4.43.dist-info/METADATA,sha256=IUCwzifSf6WuFCyadsy62lwUqE54u8rg1KunaCMn28A,551
15
+ fyodorov_llm_agents-0.4.43.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
16
+ fyodorov_llm_agents-0.4.43.dist-info/top_level.txt,sha256=4QOslsBp8Gh7ng25DceA7fHp4KguTIdAxwURz97gH-g,20
17
+ fyodorov_llm_agents-0.4.43.dist-info/RECORD,,