swarms 7.7.9__py3-none-any.whl → 7.8.0__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.
- swarms/agents/self_agent_builder.py +40 -0
- swarms/prompts/agent_self_builder_prompt.py +103 -0
- swarms/schemas/__init__.py +6 -1
- swarms/schemas/agent_class_schema.py +91 -0
- swarms/schemas/agent_mcp_errors.py +18 -0
- swarms/schemas/agent_tool_schema.py +13 -0
- swarms/schemas/llm_agent_schema.py +92 -0
- swarms/schemas/mcp_schemas.py +43 -0
- swarms/structs/__init__.py +4 -0
- swarms/structs/agent.py +305 -262
- swarms/structs/aop.py +3 -1
- swarms/structs/batch_agent_execution.py +64 -0
- swarms/structs/conversation.py +33 -19
- swarms/structs/council_judge.py +179 -93
- swarms/structs/long_agent.py +424 -0
- swarms/structs/ma_utils.py +11 -8
- swarms/structs/malt.py +1 -1
- swarms/structs/swarm_router.py +68 -13
- swarms/tools/__init__.py +12 -0
- swarms/tools/base_tool.py +2840 -264
- swarms/tools/create_agent_tool.py +104 -0
- swarms/tools/mcp_client_call.py +504 -0
- swarms/tools/py_func_to_openai_func_str.py +43 -5
- swarms/tools/pydantic_to_json.py +10 -27
- swarms/utils/audio_processing.py +343 -0
- swarms/utils/index.py +226 -0
- swarms/utils/litellm_wrapper.py +65 -67
- {swarms-7.7.9.dist-info → swarms-7.8.0.dist-info}/METADATA +2 -2
- {swarms-7.7.9.dist-info → swarms-7.8.0.dist-info}/RECORD +32 -21
- swarms/tools/mcp_client.py +0 -246
- swarms/tools/mcp_integration.py +0 -340
- {swarms-7.7.9.dist-info → swarms-7.8.0.dist-info}/LICENSE +0 -0
- {swarms-7.7.9.dist-info → swarms-7.8.0.dist-info}/WHEEL +0 -0
- {swarms-7.7.9.dist-info → swarms-7.8.0.dist-info}/entry_points.txt +0 -0
swarms/utils/litellm_wrapper.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
from typing import Optional
|
1
2
|
import base64
|
2
3
|
import requests
|
3
4
|
|
@@ -6,25 +7,13 @@ from typing import List
|
|
6
7
|
|
7
8
|
from loguru import logger
|
8
9
|
import litellm
|
10
|
+
from pydantic import BaseModel
|
9
11
|
|
10
|
-
|
11
|
-
from litellm import completion, acompletion
|
12
|
-
except ImportError:
|
13
|
-
import subprocess
|
14
|
-
import sys
|
15
|
-
import litellm
|
12
|
+
from litellm import completion, acompletion
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
[sys.executable, "-m", "pip", "install", "-U", "litellm"]
|
21
|
-
)
|
22
|
-
print("litellm installed")
|
23
|
-
|
24
|
-
from litellm import completion
|
25
|
-
|
26
|
-
litellm.set_verbose = True
|
27
|
-
litellm.ssl_verify = False
|
14
|
+
litellm.set_verbose = True
|
15
|
+
litellm.ssl_verify = False
|
16
|
+
# litellm._turn_on_debug()
|
28
17
|
|
29
18
|
|
30
19
|
class LiteLLMException(Exception):
|
@@ -86,6 +75,9 @@ class LiteLLM:
|
|
86
75
|
retries: int = 3,
|
87
76
|
verbose: bool = False,
|
88
77
|
caching: bool = False,
|
78
|
+
mcp_call: bool = False,
|
79
|
+
top_p: float = 1.0,
|
80
|
+
functions: List[dict] = None,
|
89
81
|
*args,
|
90
82
|
**kwargs,
|
91
83
|
):
|
@@ -110,6 +102,9 @@ class LiteLLM:
|
|
110
102
|
self.tool_choice = tool_choice
|
111
103
|
self.parallel_tool_calls = parallel_tool_calls
|
112
104
|
self.caching = caching
|
105
|
+
self.mcp_call = mcp_call
|
106
|
+
self.top_p = top_p
|
107
|
+
self.functions = functions
|
113
108
|
self.modalities = []
|
114
109
|
self._cached_messages = {} # Cache for prepared messages
|
115
110
|
self.messages = [] # Initialize messages list
|
@@ -123,6 +118,23 @@ class LiteLLM:
|
|
123
118
|
retries # Add retries for better reliability
|
124
119
|
)
|
125
120
|
|
121
|
+
def output_for_tools(self, response: any):
|
122
|
+
if self.mcp_call is True:
|
123
|
+
out = response.choices[0].message.tool_calls[0].function
|
124
|
+
output = {
|
125
|
+
"function": {
|
126
|
+
"name": out.name,
|
127
|
+
"arguments": out.arguments,
|
128
|
+
}
|
129
|
+
}
|
130
|
+
return output
|
131
|
+
else:
|
132
|
+
out = response.choices[0].message.tool_calls
|
133
|
+
|
134
|
+
if isinstance(out, BaseModel):
|
135
|
+
out = out.model_dump()
|
136
|
+
return out
|
137
|
+
|
126
138
|
def _prepare_messages(self, task: str) -> list:
|
127
139
|
"""
|
128
140
|
Prepare the messages for the given task.
|
@@ -222,8 +234,8 @@ class LiteLLM:
|
|
222
234
|
def run(
|
223
235
|
self,
|
224
236
|
task: str,
|
225
|
-
audio: str = None,
|
226
|
-
img: str = None,
|
237
|
+
audio: Optional[str] = None,
|
238
|
+
img: Optional[str] = None,
|
227
239
|
*args,
|
228
240
|
**kwargs,
|
229
241
|
):
|
@@ -250,38 +262,28 @@ class LiteLLM:
|
|
250
262
|
self.handle_modalities(
|
251
263
|
task=task, audio=audio, img=img
|
252
264
|
)
|
253
|
-
messages =
|
254
|
-
self.messages
|
255
|
-
) # Use modality-processed messages
|
256
|
-
|
257
|
-
if (
|
258
|
-
self.model_name == "openai/o4-mini"
|
259
|
-
or self.model_name == "openai/o3-2025-04-16"
|
260
|
-
):
|
261
|
-
# Prepare common completion parameters
|
262
|
-
completion_params = {
|
263
|
-
"model": self.model_name,
|
264
|
-
"messages": messages,
|
265
|
-
"stream": self.stream,
|
266
|
-
# "temperature": self.temperature,
|
267
|
-
"max_completion_tokens": self.max_tokens,
|
268
|
-
"caching": self.caching,
|
269
|
-
**kwargs,
|
270
|
-
}
|
265
|
+
messages = self.messages
|
271
266
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
267
|
+
# Base completion parameters
|
268
|
+
completion_params = {
|
269
|
+
"model": self.model_name,
|
270
|
+
"messages": messages,
|
271
|
+
"stream": self.stream,
|
272
|
+
"max_tokens": self.max_tokens,
|
273
|
+
"caching": self.caching,
|
274
|
+
"temperature": self.temperature,
|
275
|
+
"top_p": self.top_p,
|
276
|
+
**kwargs,
|
277
|
+
}
|
283
278
|
|
284
|
-
#
|
279
|
+
# Add temperature for non-o4/o3 models
|
280
|
+
if self.model_name not in [
|
281
|
+
"openai/o4-mini",
|
282
|
+
"openai/o3-2025-04-16",
|
283
|
+
]:
|
284
|
+
completion_params["temperature"] = self.temperature
|
285
|
+
|
286
|
+
# Add tools if specified
|
285
287
|
if self.tools_list_dictionary is not None:
|
286
288
|
completion_params.update(
|
287
289
|
{
|
@@ -290,28 +292,24 @@ class LiteLLM:
|
|
290
292
|
"parallel_tool_calls": self.parallel_tool_calls,
|
291
293
|
}
|
292
294
|
)
|
293
|
-
response = completion(**completion_params)
|
294
|
-
return (
|
295
|
-
response.choices[0]
|
296
|
-
.message.tool_calls[0]
|
297
|
-
.function.arguments
|
298
|
-
)
|
299
295
|
|
300
|
-
|
301
|
-
if (
|
302
|
-
self.modalities and len(self.modalities) > 1
|
303
|
-
): # More than just text
|
296
|
+
if self.functions is not None:
|
304
297
|
completion_params.update(
|
305
|
-
{"
|
298
|
+
{"functions": self.functions}
|
306
299
|
)
|
307
|
-
response = completion(**completion_params)
|
308
|
-
return response.choices[0].message.content
|
309
300
|
|
310
|
-
#
|
311
|
-
if self.
|
312
|
-
|
301
|
+
# Add modalities if needed
|
302
|
+
if self.modalities and len(self.modalities) >= 2:
|
303
|
+
completion_params["modalities"] = self.modalities
|
304
|
+
|
305
|
+
# Make the completion call
|
306
|
+
response = completion(**completion_params)
|
307
|
+
|
308
|
+
# Handle tool-based response
|
309
|
+
if self.tools_list_dictionary is not None:
|
310
|
+
return self.output_for_tools(response)
|
313
311
|
else:
|
314
|
-
response
|
312
|
+
# Return standard response content
|
315
313
|
return response.choices[0].message.content
|
316
314
|
|
317
315
|
except LiteLLMException as error:
|
@@ -322,7 +320,7 @@ class LiteLLM:
|
|
322
320
|
)
|
323
321
|
import time
|
324
322
|
|
325
|
-
time.sleep(2)
|
323
|
+
time.sleep(2)
|
326
324
|
return self.run(task, audio, img, *args, **kwargs)
|
327
325
|
raise error
|
328
326
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: swarms
|
3
|
-
Version: 7.
|
3
|
+
Version: 7.8.0
|
4
4
|
Summary: Swarms - TGSC
|
5
5
|
License: MIT
|
6
6
|
Keywords: artificial intelligence,deep learning,optimizers,Prompt Engineering,swarms,agents,llms,transformers,multi-agent,swarms of agents,Enterprise-Grade Agents,Production-Grade Agents,Agents,Multi-Grade-Agents,Swarms,Transformers,LLMs,Prompt Engineering,Agents,Generative Agents,Generative AI,Agent Marketplace,Agent Store,quant,finance,algorithmic trading,portfolio optimization,risk management,financial modeling,machine learning for finance,natural language processing for finance
|
@@ -21,13 +21,13 @@ Requires-Dist: aiofiles
|
|
21
21
|
Requires-Dist: aiohttp
|
22
22
|
Requires-Dist: asyncio (>=3.4.3,<4.0)
|
23
23
|
Requires-Dist: docstring_parser (==0.16)
|
24
|
-
Requires-Dist: fastmcp
|
25
24
|
Requires-Dist: httpx
|
26
25
|
Requires-Dist: litellm
|
27
26
|
Requires-Dist: loguru
|
28
27
|
Requires-Dist: mcp
|
29
28
|
Requires-Dist: networkx
|
30
29
|
Requires-Dist: numpy
|
30
|
+
Requires-Dist: numpydoc
|
31
31
|
Requires-Dist: psutil
|
32
32
|
Requires-Dist: pydantic
|
33
33
|
Requires-Dist: pypdf (==5.1.0)
|
@@ -14,6 +14,7 @@ swarms/agents/openai_assistant.py,sha256=mTSEtj26J0mc5pCeWrmMY0EXzTRYQfyfw_BtOqt
|
|
14
14
|
swarms/agents/react_agent.py,sha256=yM8lQoRsqJZicqtmgBrC7RHv0aKEb5oZHh4q5aAA_xs,5804
|
15
15
|
swarms/agents/reasoning_agents.py,sha256=tF7K710lj-VZQVc2VjqxMWGLNGMsEWRarXcJnXz1wkc,5741
|
16
16
|
swarms/agents/reasoning_duo.py,sha256=s9SnXoproQaBrShLtiruGJituy8sJlZJATc5Vy_FdwI,3875
|
17
|
+
swarms/agents/self_agent_builder.py,sha256=bX7xSwak6HiyK901VdeE8OlT4yqE0n7jyHcWJrkMeew,1104
|
17
18
|
swarms/agents/tool_agent.py,sha256=G7rhBACsHsGUMT4H9eF5aY7e3Gx-5jOmJkhCF1jm9mU,5087
|
18
19
|
swarms/artifacts/__init__.py,sha256=M111xTw7IVVt8gLDwW7Kau5n1YdwkL3vbCJPVeEWktI,83
|
19
20
|
swarms/artifacts/main_artifact.py,sha256=bu2TcsTR81ttJEjVJ3NzT7D4x7uuM57okC92QuigV9I,11139
|
@@ -34,6 +35,7 @@ swarms/prompts/aga.py,sha256=4rRG7r9LF9JBrGOLN4Hy_6cSe0z5YOeKFbGnOmRfFJ0,9156
|
|
34
35
|
swarms/prompts/agent_judge_prompt.py,sha256=-2q5mWLRyO7pj7j512ZNYRm-uEZttPgDGaxZo3oM_QQ,2235
|
35
36
|
swarms/prompts/agent_prompt.py,sha256=6SXkMWcFIIAY02N9P6kMdzo4wtPwzg1Bl9R2qsIdicM,2705
|
36
37
|
swarms/prompts/agent_prompts.py,sha256=63ZqAO1jfH3TKtl9ibLLagSG5kAPlbq4xtCGgGEuuoA,6886
|
38
|
+
swarms/prompts/agent_self_builder_prompt.py,sha256=cpO6VgtKaZAZ0aD3spzkzsMgdwEKo1_UALfLgczkFdU,6167
|
37
39
|
swarms/prompts/agent_system_prompts.py,sha256=3Ae6bSZjyRtV1nlkHkm8pYgWoZjzzVR1_amaNQ-Z9Do,7796
|
38
40
|
swarms/prompts/ai_research_team.py,sha256=6j8eqKih4PKSwYoS1BSBSEhZEGPiZCbTVX6aBUVNRIw,5233
|
39
41
|
swarms/prompts/aot_prompt.py,sha256=c1CBRixF2ucKZ0erwAjSOTSNHo_qO2jwUR-D3dxpfXw,1148
|
@@ -87,24 +89,30 @@ swarms/prompts/urban_planning.py,sha256=z483ehEuZwKuddbxS2s7fteDlb_iQ_Cj8DMCM_QC
|
|
87
89
|
swarms/prompts/visual_cot.py,sha256=PKePf57hu5sjaG5IvMFAxPzbLuPYrmnWEQG1MOq3TIg,3675
|
88
90
|
swarms/prompts/worker_prompt.py,sha256=f6qPN24vEciGRTHyYjNDguhzCFPZqa2u05rEHIPcJto,5554
|
89
91
|
swarms/prompts/xray_swarm_prompt.py,sha256=AfV_y8GVuEodznOGQ9Q8QlInoLE5Px3Nl9GS_EpsDxg,2349
|
90
|
-
swarms/schemas/__init__.py,sha256=
|
92
|
+
swarms/schemas/__init__.py,sha256=G2PKMJONzT3x6_edNqNjTgCgpTyul4UKhpC5cSe8Zjw,247
|
93
|
+
swarms/schemas/agent_class_schema.py,sha256=SG04rPZEHE4XWwC402qvfRMRJpyhQ0AvsHF-_B-e2Cg,4581
|
94
|
+
swarms/schemas/agent_mcp_errors.py,sha256=2BDsZAt9Pgmfh_D5DKY5vc9psw4Wl0FevL60yfiQvKk,266
|
91
95
|
swarms/schemas/agent_step_schemas.py,sha256=a14gb58vR0xOwB_fwSJQbN6yb9HddEaT30E6hUrzEQA,2573
|
96
|
+
swarms/schemas/agent_tool_schema.py,sha256=XdaKie6R0WhNXlnEl9f5T3hHmMedFbVwG17fdHP_U3E,385
|
92
97
|
swarms/schemas/base_schemas.py,sha256=UvBLVWg2qRen4tK5GJz50v42SiX95EQ5qK7hfyAHTEU,3267
|
93
|
-
swarms/
|
94
|
-
swarms/
|
98
|
+
swarms/schemas/llm_agent_schema.py,sha256=om3tPSjwbkIj2Hr38mKMLJvWs0E2BaE1jw2kzzd0Www,3020
|
99
|
+
swarms/schemas/mcp_schemas.py,sha256=XZJ4HyiY_cv8Gvj-53ddjzXuqT9hBU2f0cHbhIKs_jY,1330
|
100
|
+
swarms/structs/__init__.py,sha256=VEHVLHULQDqpCKGhBQ-oxiQAwP_9dI9K1mRF8WSYRvg,4231
|
101
|
+
swarms/structs/agent.py,sha256=MsPTIbIeOCa43eU6hIIp1pd8VSm07SjWB0he19msoyQ,100435
|
95
102
|
swarms/structs/agent_builder.py,sha256=tYNpfO4_8cgfMHfgA5DAOWffHnt70p6CLt59esqfVCY,12133
|
96
103
|
swarms/structs/agent_registry.py,sha256=il507cO1NF-d4ChyANVLuWrN8bXsEAi8_7bLJ_sTU6A,12112
|
97
104
|
swarms/structs/agent_roles.py,sha256=8XEw6RjOOZelaZaWt4gXaYQm5WMLEhSO7W6Z8sQjmFg,582
|
98
105
|
swarms/structs/agent_router.py,sha256=YZw5AaK2yTvxkOA7ouED_4MoYgn0XZggvo1wrglp-4E,13017
|
99
|
-
swarms/structs/aop.py,sha256
|
106
|
+
swarms/structs/aop.py,sha256=VQS1oDtg4cXVBxRaxMSYSM5X4nzVFy7u7mLmiOqDWZo,17408
|
100
107
|
swarms/structs/auto_swarm_builder.py,sha256=79hd-3GpEyCGgS6tj4FvGFyM8768McQZJQXbGGj9XMk,12973
|
101
108
|
swarms/structs/base_structure.py,sha256=GDu4QJQQmhU7IyuFJHIh9UVThACCva-L7uoMbVD9l4s,15901
|
102
109
|
swarms/structs/base_swarm.py,sha256=LSGJDPJdyUCcK6698mNtjxoC1OU3s_J2NxC2k_ccGUs,23779
|
103
110
|
swarms/structs/base_workflow.py,sha256=DTfFwX3AdFYxACDYwUDqhsbcDZnITlg5TeEYyxmJBCc,11414
|
111
|
+
swarms/structs/batch_agent_execution.py,sha256=d85DzeCq4uTbbPqLhAXFqFx_cxXUS5yRnJ1-gJkwU5w,1871
|
104
112
|
swarms/structs/concat.py,sha256=utezSxNyh1mIwXgdf8-dJ803NDPyEy79WE8zJHuooGk,732
|
105
113
|
swarms/structs/concurrent_workflow.py,sha256=OqXI-X-9a0hG2a7aLzobwd7CVF2ez0rgLj3ZHqri5bg,12952
|
106
|
-
swarms/structs/conversation.py,sha256=
|
107
|
-
swarms/structs/council_judge.py,sha256=
|
114
|
+
swarms/structs/conversation.py,sha256=88FgnM5tHOjC_F0TGRT04gkiPnE3tiept4ipnCO4iw8,27501
|
115
|
+
swarms/structs/council_judge.py,sha256=siYDKiHMvFmShUTXxdo4R6vXiQhKt7bEBI205oC3kU4,19639
|
108
116
|
swarms/structs/csv_to_agent.py,sha256=ug9JqQFPguXeU9JQpSUXuVtOpHYdJhlpKJUJBovo694,9443
|
109
117
|
swarms/structs/de_hallucination_swarm.py,sha256=9cC0rSSXGwYu6SRDwpeMbCcQ40C1WI1RE9SNapKRLOQ,10309
|
110
118
|
swarms/structs/deep_research_swarm.py,sha256=3f8T_t-gIg5wbfU2JrMmZ9Ob4Qn153zXdzt5ZpydmXk,16777
|
@@ -113,9 +121,10 @@ swarms/structs/graph_workflow.py,sha256=TAaUG_J3898hhghPOp0WEAV3Zf0in6s48ZSVbSTX
|
|
113
121
|
swarms/structs/groupchat.py,sha256=jjH0BqU9Nrd_3jl9QzrcvbSce527SFpUaepawaRiw2o,15391
|
114
122
|
swarms/structs/hiearchical_swarm.py,sha256=2x3InS4HJg4T9Y195l_ANTGu6DYcllqCdJcR3v5Xuro,33402
|
115
123
|
swarms/structs/hybrid_hiearchical_peer_swarm.py,sha256=D1iBtNNee_mxPoOWS5WGTqcci5FQKtt38mW-J42GvfM,9494
|
116
|
-
swarms/structs/
|
124
|
+
swarms/structs/long_agent.py,sha256=KFjE2uUI8ONTkeJO43Sh3y5-Ec0kga28BECGklic-S4,15049
|
125
|
+
swarms/structs/ma_utils.py,sha256=s8uTCplQtiFvxyqyTTTUCnJDMwNLJEuxbdGZyOURjLg,3244
|
117
126
|
swarms/structs/majority_voting.py,sha256=F_t_MOC3YCRyMw5N6qKdFThpaXZxwixRw592Ku5Uhto,10122
|
118
|
-
swarms/structs/malt.py,sha256=
|
127
|
+
swarms/structs/malt.py,sha256=uLofKBWHkP3uNhyCkkgEyE4Z7qnOHTtcg-OTiR19x_Y,19572
|
119
128
|
swarms/structs/matrix_swarm.py,sha256=qHuhOYrTyOv6ujHMe8PrQT-h-WmaCPCfX4ghv5L8UFI,9765
|
120
129
|
swarms/structs/meme_agent_persona_generator.py,sha256=b3kKlumhsV4KV88-GS3CUnGO1UfKTU3fT8SAMj0ZlwQ,10645
|
121
130
|
swarms/structs/mixture_of_agents.py,sha256=Ix2YTdrzISPQJLrQ5vrZtYOpZwIYDx0vUaNmvBwDDVM,7762
|
@@ -137,7 +146,7 @@ swarms/structs/swarm_eval.py,sha256=148E2R2zaCmt_LZYx15nmdFjybXHiQ2CZbl6pk77jNs,
|
|
137
146
|
swarms/structs/swarm_id_generator.py,sha256=Wly7AtGM9e6VgzhYmfg8_gSOdxAdsOvWHJFK81cpQNQ,68
|
138
147
|
swarms/structs/swarm_matcher.py,sha256=E2KwHHEJxmW-UfTeMPWZ6VCmYdQ_I9_fwrfJbxD02GY,23322
|
139
148
|
swarms/structs/swarm_registry.py,sha256=P0XRrqp1qBNyt0BycqPQljUzKv9jClaQMhtaBMinhYg,5578
|
140
|
-
swarms/structs/swarm_router.py,sha256=
|
149
|
+
swarms/structs/swarm_router.py,sha256=oj5QumyxutVawthcTFUsY8DcHbn3iWOxAi7xpkoDRQg,30457
|
141
150
|
swarms/structs/swarming_architectures.py,sha256=q2XrY2lOqFhVckA8oin65Dz1VPUe-lfbEJHlP1Z8aTE,28278
|
142
151
|
swarms/structs/tree_swarm.py,sha256=AnIxrt0KhWxAQN8uGjfCcOq-XCmsuTJiH8Ex4mXy8V8,12500
|
143
152
|
swarms/structs/utils.py,sha256=Mo6wHQYOB8baWZUKnAJN5Dsgubpo81umNwJIEDitb2A,1873
|
@@ -145,27 +154,28 @@ swarms/structs/various_alt_swarms.py,sha256=qdBuOF31UjatlKRu-9bxwyRQzIjohRhTv_63
|
|
145
154
|
swarms/telemetry/__init__.py,sha256=yibtkHEbQRPUv6ir1FhDHlAO_3nwKJPQH4LjzBC2AuQ,661
|
146
155
|
swarms/telemetry/bootup.py,sha256=0leCNCy5rhzL19EsOsqHWSDI85KVcWO6_5hLDS0h4sY,1155
|
147
156
|
swarms/telemetry/main.py,sha256=8FxivorvclSvhgfU03cHFktaRgRNV1UXCMi0VV8-U60,11248
|
148
|
-
swarms/tools/__init__.py,sha256=
|
149
|
-
swarms/tools/base_tool.py,sha256=
|
157
|
+
swarms/tools/__init__.py,sha256=tyGQpcfrosMx06fdV9h_8_9WB-1vfT-aAjZufiTXyPQ,1838
|
158
|
+
swarms/tools/base_tool.py,sha256=LMGfH2o9nrCdsuVxI2mfxtkIMcXTs2oO_jAF1ebU-YY,107065
|
150
159
|
swarms/tools/cohere_func_call_schema.py,sha256=XJ6_yBMXCrV9KjN7v9Bk1iFj69TRlGIWYKsUTA1oGiQ,600
|
160
|
+
swarms/tools/create_agent_tool.py,sha256=YsiBgrR9gkn2Jenu_mIFXOMJCWb_Hdw4gBYPQN5HEQk,3467
|
151
161
|
swarms/tools/func_calling_utils.py,sha256=PhHHZRHN-vRHA_h21ELRjXIhSRIrsT4UhU5-1Bhy-iU,3542
|
152
162
|
swarms/tools/func_to_str.py,sha256=J_E3ejEYxl_u7Te9xvHWGE83EW0-CRBRqafiXMUvto8,1129
|
153
163
|
swarms/tools/function_util.py,sha256=DAnAPO0Ik__TAqL7IJzFmkukHnhpsW_QtALl3yj837g,1158
|
154
164
|
swarms/tools/json_former.py,sha256=4ugLQ_EZpghhuhFsVKsy-ehin9K64pqVE2gLU7BTO_M,14376
|
155
165
|
swarms/tools/json_utils.py,sha256=WKMZjcJ0Vt6lgIjiTBenslcfjgRSLX4UWs4uDkKFMQI,1316
|
156
166
|
swarms/tools/logits_processor.py,sha256=NifZZ5w9yemWGJAJ5nHFrphtZVX1XlyesgvYZTxK1GM,2965
|
157
|
-
swarms/tools/
|
158
|
-
swarms/tools/mcp_integration.py,sha256=ZxVj5T6qBy9K9YTpXmDn2LiA4Q-Wj0TTuF3SnI_Jiu0,11725
|
167
|
+
swarms/tools/mcp_client_call.py,sha256=4iYDpMT_v0Kk_RTgL0bfQruxJJJuXNPmZQalHL1vm6c,15287
|
159
168
|
swarms/tools/openai_func_calling_schema_pydantic.py,sha256=6BAH9kuaVTvJIbjgSSJ5XvHhWvWszPxgarkfUuE5Ads,978
|
160
169
|
swarms/tools/openai_tool_creator_decorator.py,sha256=SYZjHnARjWvnH9cBdj7Kc_Yy1muvNxMT3RQz8KkA2SE,2578
|
161
|
-
swarms/tools/py_func_to_openai_func_str.py,sha256=
|
162
|
-
swarms/tools/pydantic_to_json.py,sha256
|
170
|
+
swarms/tools/py_func_to_openai_func_str.py,sha256=sjoNutRZ11-0kYFDalUTxZxQ0TEDyn5R8EXMdS4gsgw,17091
|
171
|
+
swarms/tools/pydantic_to_json.py,sha256=sd5uWwjSHsu7M8wCBrPv0uje05-K4xcfbvKQ_zOaww8,3399
|
163
172
|
swarms/tools/tool_parse_exec.py,sha256=FW5XzkuNEs2YrroybjKChbCzDvaCs7ypknSDpYhfkd4,8717
|
164
173
|
swarms/tools/tool_registry.py,sha256=ULZmIKBTx9XRCJRD9hwXfY3iQw9v94arw-VV6jcuftY,7992
|
165
174
|
swarms/tools/tool_schema_base_model.py,sha256=0biTGIoibsPPP3fOrkC6WvNU5vXaalyccVKC1fpO_eg,1409
|
166
175
|
swarms/tools/tool_utils.py,sha256=yXzzqG7Ytd8ybB8bsjNUNLaXIuIp9JbbpUKCiHxQqo8,2816
|
167
176
|
swarms/utils/__init__.py,sha256=9qKE_11pxom74j3qExSm6Z_LwR5lrpC5YG17v22eLlo,975
|
168
177
|
swarms/utils/any_to_str.py,sha256=Qi4N9ed6LYnCs2AeFYo1zwEfYhOKUesGVFUmVUz54KI,2936
|
178
|
+
swarms/utils/audio_processing.py,sha256=Y3KaWG9WJrgquWCeaty20HWPIXfeuPAhcJFzoSBIQjE,9893
|
169
179
|
swarms/utils/auto_download_check_packages.py,sha256=mqx3jCetfkTuxTdeGLx-gGMB1xWOU5vata8lTKXLatk,4580
|
170
180
|
swarms/utils/calculate_func_metrics.py,sha256=Nb5r7rWf809m5F7mWIYXZ0H_WeyGr78A2UZD2GHtJkM,5007
|
171
181
|
swarms/utils/data_to_text.py,sha256=1PUoWokylp7MOrGNk1cmO3cJlfskdAIiImGk9ECwsKU,3427
|
@@ -175,8 +185,9 @@ swarms/utils/formatter.py,sha256=e15FsyTIIkyRreMUApkkZCzJC1Sm67w5Zd6EQcUkMwA,453
|
|
175
185
|
swarms/utils/function_caller_model.py,sha256=ZfgCMzOizNnuZipYLclTziECNHszH9p8RQcUq7VNr4Q,4156
|
176
186
|
swarms/utils/generate_keys.py,sha256=i0Ewm1LCTLaqp7qm7B7MgNolaI9IZyJcxNVRLUZklt4,1700
|
177
187
|
swarms/utils/history_output_formatter.py,sha256=d4J-TF63ENCjsQXU36MGR2pvx59y0qBFuBlOrJt_K8M,1487
|
188
|
+
swarms/utils/index.py,sha256=iYVlMiuSpBuKHF34uSrxDUuSYmS26bbYoAqyz_VIyvY,6902
|
178
189
|
swarms/utils/litellm_tokenizer.py,sha256=0AAj4NffBe2eHii_3_5SpQAhSiBbunJR8MzaBTIm7hg,484
|
179
|
-
swarms/utils/litellm_wrapper.py,sha256=
|
190
|
+
swarms/utils/litellm_wrapper.py,sha256=dZ9KCR_Rxlm3VZWWVfhpTb4Y6KM_xHipynueJUeU_Jc,15023
|
180
191
|
swarms/utils/loguru_logger.py,sha256=hIoSK3NHLpe7eAmjHRURrEYzNXYC2gbR7_Vv63Yaydk,685
|
181
192
|
swarms/utils/markdown_message.py,sha256=RThHNnMf6ZLTlYK4vKn3yuewChaxWAYAWb0Xm_pTyIU,652
|
182
193
|
swarms/utils/parse_code.py,sha256=XFOLymbdP3HzMZuqsj7pwUyisvUmTm0ev9iThR_ambI,1987
|
@@ -187,8 +198,8 @@ swarms/utils/visualizer.py,sha256=0ylohEk62MAS6iPRaDOV03m9qo2k5J56tWlKJk_46p4,16
|
|
187
198
|
swarms/utils/vllm_wrapper.py,sha256=OIGnU9Vf81vE_hul1FK-xEhChFK8fxqZX6-fhQeW22c,4987
|
188
199
|
swarms/utils/wrapper_clusterop.py,sha256=PMSCVM7ZT1vgj1D_MYAe835RR3SMLYxA-si2JS02yNQ,4220
|
189
200
|
swarms/utils/xml_utils.py,sha256=j8byUa56VT7V4e18pL8UBftLdyWKsUHbid1KDxnAWBo,1416
|
190
|
-
swarms-7.
|
191
|
-
swarms-7.
|
192
|
-
swarms-7.
|
193
|
-
swarms-7.
|
194
|
-
swarms-7.
|
201
|
+
swarms-7.8.0.dist-info/LICENSE,sha256=jwRtEmTWjLrEsvFB6QFdYs2cEeZPRMdj-UMOFkPF8_0,11363
|
202
|
+
swarms-7.8.0.dist-info/METADATA,sha256=6Npfe5U1IoF9Rty5vbt4vp-17U5psURrMEIFPdqCDXw,94969
|
203
|
+
swarms-7.8.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
204
|
+
swarms-7.8.0.dist-info/entry_points.txt,sha256=2K0rTtfO1X1WaO-waJlXIKw5Voa_EpAL_yU0HXE2Jgc,47
|
205
|
+
swarms-7.8.0.dist-info/RECORD,,
|
swarms/tools/mcp_client.py
DELETED
@@ -1,246 +0,0 @@
|
|
1
|
-
import asyncio
|
2
|
-
import json
|
3
|
-
from typing import List, Literal, Dict, Any, Union
|
4
|
-
from fastmcp import Client
|
5
|
-
from swarms.utils.str_to_dict import str_to_dict
|
6
|
-
from loguru import logger
|
7
|
-
|
8
|
-
|
9
|
-
def parse_agent_output(
|
10
|
-
dictionary: Union[str, Dict[Any, Any]],
|
11
|
-
) -> tuple[str, Dict[Any, Any]]:
|
12
|
-
"""
|
13
|
-
Parse agent output into tool name and parameters.
|
14
|
-
|
15
|
-
Args:
|
16
|
-
dictionary: Either a string or dictionary containing tool information.
|
17
|
-
If string, it will be converted to a dictionary.
|
18
|
-
Must contain a 'name' key for the tool name.
|
19
|
-
|
20
|
-
Returns:
|
21
|
-
tuple[str, Dict[Any, Any]]: A tuple containing the tool name and its parameters.
|
22
|
-
|
23
|
-
Raises:
|
24
|
-
ValueError: If the input is invalid or missing required 'name' key.
|
25
|
-
"""
|
26
|
-
try:
|
27
|
-
if isinstance(dictionary, str):
|
28
|
-
dictionary = str_to_dict(dictionary)
|
29
|
-
|
30
|
-
elif not isinstance(dictionary, dict):
|
31
|
-
raise ValueError("Invalid dictionary")
|
32
|
-
|
33
|
-
# Handle regular dictionary format
|
34
|
-
if "name" in dictionary:
|
35
|
-
name = dictionary["name"]
|
36
|
-
# Remove the name key and use remaining key-value pairs as parameters
|
37
|
-
params = dict(dictionary)
|
38
|
-
params.pop("name")
|
39
|
-
return name, params
|
40
|
-
|
41
|
-
raise ValueError("Invalid function call format")
|
42
|
-
except Exception as e:
|
43
|
-
raise ValueError(f"Error parsing agent output: {str(e)}")
|
44
|
-
|
45
|
-
|
46
|
-
async def _list_all(url: str):
|
47
|
-
"""
|
48
|
-
Asynchronously list all tools available on a given MCP server.
|
49
|
-
|
50
|
-
Args:
|
51
|
-
url: The URL of the MCP server to query.
|
52
|
-
|
53
|
-
Returns:
|
54
|
-
List of available tools.
|
55
|
-
|
56
|
-
Raises:
|
57
|
-
ValueError: If there's an error connecting to or querying the server.
|
58
|
-
"""
|
59
|
-
try:
|
60
|
-
async with Client(url) as client:
|
61
|
-
return await client.list_tools()
|
62
|
-
except Exception as e:
|
63
|
-
raise ValueError(f"Error listing tools: {str(e)}")
|
64
|
-
|
65
|
-
|
66
|
-
def list_all(url: str, output_type: Literal["str", "json"] = "json"):
|
67
|
-
"""
|
68
|
-
Synchronously list all tools available on a given MCP server.
|
69
|
-
|
70
|
-
Args:
|
71
|
-
url: The URL of the MCP server to query.
|
72
|
-
|
73
|
-
Returns:
|
74
|
-
List of dictionaries containing tool information.
|
75
|
-
|
76
|
-
Raises:
|
77
|
-
ValueError: If there's an error connecting to or querying the server.
|
78
|
-
"""
|
79
|
-
try:
|
80
|
-
out = asyncio.run(_list_all(url))
|
81
|
-
|
82
|
-
outputs = []
|
83
|
-
for tool in out:
|
84
|
-
outputs.append(tool.model_dump())
|
85
|
-
|
86
|
-
if output_type == "json":
|
87
|
-
return json.dumps(outputs, indent=4)
|
88
|
-
else:
|
89
|
-
return outputs
|
90
|
-
except Exception as e:
|
91
|
-
raise ValueError(f"Error in list_all: {str(e)}")
|
92
|
-
|
93
|
-
|
94
|
-
def list_tools_for_multiple_urls(
|
95
|
-
urls: List[str], output_type: Literal["str", "json"] = "json"
|
96
|
-
):
|
97
|
-
"""
|
98
|
-
List tools available across multiple MCP servers.
|
99
|
-
|
100
|
-
Args:
|
101
|
-
urls: List of MCP server URLs to query.
|
102
|
-
output_type: Format of the output, either "json" (string) or "str" (list).
|
103
|
-
|
104
|
-
Returns:
|
105
|
-
If output_type is "json": JSON string containing all tools with server URLs.
|
106
|
-
If output_type is "str": List of tools with server URLs.
|
107
|
-
|
108
|
-
Raises:
|
109
|
-
ValueError: If there's an error querying any of the servers.
|
110
|
-
"""
|
111
|
-
try:
|
112
|
-
out = []
|
113
|
-
for url in urls:
|
114
|
-
tools = list_all(url)
|
115
|
-
# Add server URL to each tool's data
|
116
|
-
for tool in tools:
|
117
|
-
tool["server_url"] = url
|
118
|
-
out.append(tools)
|
119
|
-
|
120
|
-
if output_type == "json":
|
121
|
-
return json.dumps(out, indent=4)
|
122
|
-
else:
|
123
|
-
return out
|
124
|
-
except Exception as e:
|
125
|
-
raise ValueError(
|
126
|
-
f"Error listing tools for multiple URLs: {str(e)}"
|
127
|
-
)
|
128
|
-
|
129
|
-
|
130
|
-
async def _execute_mcp_tool(
|
131
|
-
url: str,
|
132
|
-
parameters: Dict[Any, Any] = None,
|
133
|
-
*args,
|
134
|
-
**kwargs,
|
135
|
-
) -> Dict[Any, Any]:
|
136
|
-
"""
|
137
|
-
Asynchronously execute a tool on an MCP server.
|
138
|
-
|
139
|
-
Args:
|
140
|
-
url: The URL of the MCP server.
|
141
|
-
parameters: Dictionary containing tool name and parameters.
|
142
|
-
*args: Additional positional arguments for the Client.
|
143
|
-
**kwargs: Additional keyword arguments for the Client.
|
144
|
-
|
145
|
-
Returns:
|
146
|
-
Dictionary containing the tool execution results.
|
147
|
-
|
148
|
-
Raises:
|
149
|
-
ValueError: If the URL is invalid or tool execution fails.
|
150
|
-
"""
|
151
|
-
try:
|
152
|
-
|
153
|
-
name, params = parse_agent_output(parameters)
|
154
|
-
|
155
|
-
outputs = []
|
156
|
-
|
157
|
-
async with Client(url, *args, **kwargs) as client:
|
158
|
-
out = await client.call_tool(
|
159
|
-
name=name,
|
160
|
-
arguments=params,
|
161
|
-
)
|
162
|
-
|
163
|
-
for output in out:
|
164
|
-
outputs.append(output.model_dump())
|
165
|
-
|
166
|
-
# convert outputs to string
|
167
|
-
return json.dumps(outputs, indent=4)
|
168
|
-
except Exception as e:
|
169
|
-
raise ValueError(f"Error executing MCP tool: {str(e)}")
|
170
|
-
|
171
|
-
|
172
|
-
def execute_mcp_tool(
|
173
|
-
url: str,
|
174
|
-
parameters: Dict[Any, Any] = None,
|
175
|
-
) -> Dict[Any, Any]:
|
176
|
-
"""
|
177
|
-
Synchronously execute a tool on an MCP server.
|
178
|
-
|
179
|
-
Args:
|
180
|
-
url: The URL of the MCP server.
|
181
|
-
parameters: Dictionary containing tool name and parameters.
|
182
|
-
|
183
|
-
Returns:
|
184
|
-
Dictionary containing the tool execution results.
|
185
|
-
|
186
|
-
Raises:
|
187
|
-
ValueError: If tool execution fails.
|
188
|
-
"""
|
189
|
-
try:
|
190
|
-
logger.info(f"Executing MCP tool with URL: {url}")
|
191
|
-
logger.debug(f"Tool parameters: {parameters}")
|
192
|
-
|
193
|
-
result = asyncio.run(
|
194
|
-
_execute_mcp_tool(
|
195
|
-
url=url,
|
196
|
-
parameters=parameters,
|
197
|
-
)
|
198
|
-
)
|
199
|
-
|
200
|
-
logger.info("MCP tool execution completed successfully")
|
201
|
-
logger.debug(f"Tool execution result: {result}")
|
202
|
-
return result
|
203
|
-
except Exception as e:
|
204
|
-
logger.error(f"Error in execute_mcp_tool: {str(e)}")
|
205
|
-
raise ValueError(f"Error in execute_mcp_tool: {str(e)}")
|
206
|
-
|
207
|
-
|
208
|
-
def find_and_execute_tool(
|
209
|
-
urls: List[str], tool_name: str, parameters: Dict[Any, Any]
|
210
|
-
) -> Dict[Any, Any]:
|
211
|
-
"""
|
212
|
-
Find a tool across multiple servers and execute it with the given parameters.
|
213
|
-
|
214
|
-
Args:
|
215
|
-
urls: List of server URLs to search through.
|
216
|
-
tool_name: Name of the tool to find and execute.
|
217
|
-
parameters: Parameters to pass to the tool.
|
218
|
-
|
219
|
-
Returns:
|
220
|
-
Dict containing the tool execution results.
|
221
|
-
|
222
|
-
Raises:
|
223
|
-
ValueError: If tool is not found on any server or execution fails.
|
224
|
-
"""
|
225
|
-
try:
|
226
|
-
# Search for tool across all servers
|
227
|
-
for url in urls:
|
228
|
-
try:
|
229
|
-
tools = list_all(url)
|
230
|
-
# Check if tool exists on this server
|
231
|
-
if any(tool["name"] == tool_name for tool in tools):
|
232
|
-
# Prepare parameters in correct format
|
233
|
-
tool_params = {"name": tool_name, **parameters}
|
234
|
-
# Execute tool on this server
|
235
|
-
return execute_mcp_tool(
|
236
|
-
url=url, parameters=tool_params
|
237
|
-
)
|
238
|
-
except Exception:
|
239
|
-
# Skip servers that fail and continue searching
|
240
|
-
continue
|
241
|
-
|
242
|
-
raise ValueError(
|
243
|
-
f"Tool '{tool_name}' not found on any provided servers"
|
244
|
-
)
|
245
|
-
except Exception as e:
|
246
|
-
raise ValueError(f"Error in find_and_execute_tool: {str(e)}")
|