swarms 7.7.8__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/__init__.py +0 -1
- swarms/agents/cort_agent.py +206 -0
- swarms/agents/react_agent.py +173 -0
- swarms/agents/self_agent_builder.py +40 -0
- swarms/communication/base_communication.py +290 -0
- swarms/communication/duckdb_wrap.py +369 -72
- swarms/communication/pulsar_struct.py +691 -0
- swarms/communication/redis_wrap.py +1362 -0
- swarms/communication/sqlite_wrap.py +547 -44
- swarms/prompts/agent_self_builder_prompt.py +103 -0
- swarms/prompts/safety_prompt.py +50 -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 +315 -267
- swarms/structs/aop.py +3 -1
- swarms/structs/batch_agent_execution.py +64 -0
- swarms/structs/conversation.py +261 -57
- swarms/structs/council_judge.py +542 -0
- swarms/structs/deep_research_swarm.py +19 -22
- swarms/structs/long_agent.py +424 -0
- swarms/structs/ma_utils.py +11 -8
- swarms/structs/malt.py +30 -28
- swarms/structs/multi_model_gpu_manager.py +1 -1
- swarms/structs/output_types.py +1 -1
- swarms/structs/swarm_router.py +70 -15
- 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 +45 -7
- swarms/tools/pydantic_to_json.py +10 -27
- swarms/utils/audio_processing.py +343 -0
- swarms/utils/history_output_formatter.py +5 -5
- swarms/utils/index.py +226 -0
- swarms/utils/litellm_wrapper.py +65 -67
- swarms/utils/try_except_wrapper.py +2 -2
- swarms/utils/xml_utils.py +42 -0
- {swarms-7.7.8.dist-info → swarms-7.8.0.dist-info}/METADATA +5 -4
- {swarms-7.7.8.dist-info → swarms-7.8.0.dist-info}/RECORD +47 -30
- {swarms-7.7.8.dist-info → swarms-7.8.0.dist-info}/WHEEL +1 -1
- swarms/client/__init__.py +0 -15
- swarms/client/main.py +0 -407
- swarms/tools/mcp_client.py +0 -246
- swarms/tools/mcp_integration.py +0 -340
- {swarms-7.7.8.dist-info → swarms-7.8.0.dist-info}/LICENSE +0 -0
- {swarms-7.7.8.dist-info → swarms-7.8.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,290 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from typing import List, Optional, Union, Dict, Any
|
3
|
+
from enum import Enum
|
4
|
+
from dataclasses import dataclass
|
5
|
+
from pathlib import Path
|
6
|
+
|
7
|
+
|
8
|
+
class MessageType(Enum):
|
9
|
+
"""Enum for different types of messages in the conversation."""
|
10
|
+
|
11
|
+
SYSTEM = "system"
|
12
|
+
USER = "user"
|
13
|
+
ASSISTANT = "assistant"
|
14
|
+
FUNCTION = "function"
|
15
|
+
TOOL = "tool"
|
16
|
+
|
17
|
+
|
18
|
+
@dataclass
|
19
|
+
class Message:
|
20
|
+
"""Data class representing a message in the conversation."""
|
21
|
+
|
22
|
+
role: str
|
23
|
+
content: Union[str, dict, list]
|
24
|
+
timestamp: Optional[str] = None
|
25
|
+
message_type: Optional[MessageType] = None
|
26
|
+
metadata: Optional[Dict] = None
|
27
|
+
token_count: Optional[int] = None
|
28
|
+
|
29
|
+
|
30
|
+
class BaseCommunication(ABC):
|
31
|
+
"""
|
32
|
+
Abstract base class defining the interface for conversation implementations.
|
33
|
+
This class provides the contract that all conversation implementations must follow.
|
34
|
+
|
35
|
+
Attributes:
|
36
|
+
system_prompt (Optional[str]): The system prompt for the conversation.
|
37
|
+
time_enabled (bool): Flag to enable time tracking for messages.
|
38
|
+
autosave (bool): Flag to enable automatic saving of conversation history.
|
39
|
+
save_filepath (str): File path for saving the conversation history.
|
40
|
+
tokenizer (Any): Tokenizer for counting tokens in messages.
|
41
|
+
context_length (int): Maximum number of tokens allowed in the conversation history.
|
42
|
+
rules (str): Rules for the conversation.
|
43
|
+
custom_rules_prompt (str): Custom prompt for rules.
|
44
|
+
user (str): The user identifier for messages.
|
45
|
+
auto_save (bool): Flag to enable auto-saving of conversation history.
|
46
|
+
save_as_yaml (bool): Flag to save conversation history as YAML.
|
47
|
+
save_as_json_bool (bool): Flag to save conversation history as JSON.
|
48
|
+
token_count (bool): Flag to enable token counting for messages.
|
49
|
+
cache_enabled (bool): Flag to enable prompt caching.
|
50
|
+
"""
|
51
|
+
|
52
|
+
@staticmethod
|
53
|
+
def get_default_db_path(db_name: str) -> Path:
|
54
|
+
"""Calculate the default database path in user's home directory.
|
55
|
+
|
56
|
+
Args:
|
57
|
+
db_name (str): Name of the database file (e.g. 'conversations.db')
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
Path: Path object pointing to the database location
|
61
|
+
"""
|
62
|
+
# Get user's home directory
|
63
|
+
home = Path.home()
|
64
|
+
|
65
|
+
# Create .swarms directory if it doesn't exist
|
66
|
+
swarms_dir = home / ".swarms" / "db"
|
67
|
+
swarms_dir.mkdir(parents=True, exist_ok=True)
|
68
|
+
|
69
|
+
return swarms_dir / db_name
|
70
|
+
|
71
|
+
@abstractmethod
|
72
|
+
def __init__(
|
73
|
+
self,
|
74
|
+
system_prompt: Optional[str] = None,
|
75
|
+
time_enabled: bool = False,
|
76
|
+
autosave: bool = False,
|
77
|
+
save_filepath: str = None,
|
78
|
+
tokenizer: Any = None,
|
79
|
+
context_length: int = 8192,
|
80
|
+
rules: str = None,
|
81
|
+
custom_rules_prompt: str = None,
|
82
|
+
user: str = "User:",
|
83
|
+
auto_save: bool = True,
|
84
|
+
save_as_yaml: bool = True,
|
85
|
+
save_as_json_bool: bool = False,
|
86
|
+
token_count: bool = True,
|
87
|
+
cache_enabled: bool = True,
|
88
|
+
*args,
|
89
|
+
**kwargs,
|
90
|
+
):
|
91
|
+
"""Initialize the communication interface."""
|
92
|
+
pass
|
93
|
+
|
94
|
+
@abstractmethod
|
95
|
+
def add(
|
96
|
+
self,
|
97
|
+
role: str,
|
98
|
+
content: Union[str, dict, list],
|
99
|
+
message_type: Optional[MessageType] = None,
|
100
|
+
metadata: Optional[Dict] = None,
|
101
|
+
token_count: Optional[int] = None,
|
102
|
+
) -> int:
|
103
|
+
"""Add a message to the conversation history."""
|
104
|
+
pass
|
105
|
+
|
106
|
+
@abstractmethod
|
107
|
+
def batch_add(self, messages: List[Message]) -> List[int]:
|
108
|
+
"""Add multiple messages to the conversation history."""
|
109
|
+
pass
|
110
|
+
|
111
|
+
@abstractmethod
|
112
|
+
def delete(self, index: str):
|
113
|
+
"""Delete a message from the conversation history."""
|
114
|
+
pass
|
115
|
+
|
116
|
+
@abstractmethod
|
117
|
+
def update(
|
118
|
+
self, index: str, role: str, content: Union[str, dict]
|
119
|
+
):
|
120
|
+
"""Update a message in the conversation history."""
|
121
|
+
pass
|
122
|
+
|
123
|
+
@abstractmethod
|
124
|
+
def query(self, index: str) -> Dict:
|
125
|
+
"""Query a message in the conversation history."""
|
126
|
+
pass
|
127
|
+
|
128
|
+
@abstractmethod
|
129
|
+
def search(self, keyword: str) -> List[Dict]:
|
130
|
+
"""Search for messages containing a keyword."""
|
131
|
+
pass
|
132
|
+
|
133
|
+
@abstractmethod
|
134
|
+
def get_str(self) -> str:
|
135
|
+
"""Get the conversation history as a string."""
|
136
|
+
pass
|
137
|
+
|
138
|
+
@abstractmethod
|
139
|
+
def display_conversation(self, detailed: bool = False):
|
140
|
+
"""Display the conversation history."""
|
141
|
+
pass
|
142
|
+
|
143
|
+
@abstractmethod
|
144
|
+
def export_conversation(self, filename: str):
|
145
|
+
"""Export the conversation history to a file."""
|
146
|
+
pass
|
147
|
+
|
148
|
+
@abstractmethod
|
149
|
+
def import_conversation(self, filename: str):
|
150
|
+
"""Import a conversation history from a file."""
|
151
|
+
pass
|
152
|
+
|
153
|
+
@abstractmethod
|
154
|
+
def count_messages_by_role(self) -> Dict[str, int]:
|
155
|
+
"""Count messages by role."""
|
156
|
+
pass
|
157
|
+
|
158
|
+
@abstractmethod
|
159
|
+
def return_history_as_string(self) -> str:
|
160
|
+
"""Return the conversation history as a string."""
|
161
|
+
pass
|
162
|
+
|
163
|
+
@abstractmethod
|
164
|
+
def get_messages(
|
165
|
+
self,
|
166
|
+
limit: Optional[int] = None,
|
167
|
+
offset: Optional[int] = None,
|
168
|
+
) -> List[Dict]:
|
169
|
+
"""Get messages with optional pagination."""
|
170
|
+
pass
|
171
|
+
|
172
|
+
@abstractmethod
|
173
|
+
def clear(self):
|
174
|
+
"""Clear the conversation history."""
|
175
|
+
pass
|
176
|
+
|
177
|
+
@abstractmethod
|
178
|
+
def to_dict(self) -> List[Dict]:
|
179
|
+
"""Convert the conversation history to a dictionary."""
|
180
|
+
pass
|
181
|
+
|
182
|
+
@abstractmethod
|
183
|
+
def to_json(self) -> str:
|
184
|
+
"""Convert the conversation history to a JSON string."""
|
185
|
+
pass
|
186
|
+
|
187
|
+
@abstractmethod
|
188
|
+
def to_yaml(self) -> str:
|
189
|
+
"""Convert the conversation history to a YAML string."""
|
190
|
+
pass
|
191
|
+
|
192
|
+
@abstractmethod
|
193
|
+
def save_as_json(self, filename: str):
|
194
|
+
"""Save the conversation history as a JSON file."""
|
195
|
+
pass
|
196
|
+
|
197
|
+
@abstractmethod
|
198
|
+
def load_from_json(self, filename: str):
|
199
|
+
"""Load the conversation history from a JSON file."""
|
200
|
+
pass
|
201
|
+
|
202
|
+
@abstractmethod
|
203
|
+
def save_as_yaml(self, filename: str):
|
204
|
+
"""Save the conversation history as a YAML file."""
|
205
|
+
pass
|
206
|
+
|
207
|
+
@abstractmethod
|
208
|
+
def load_from_yaml(self, filename: str):
|
209
|
+
"""Load the conversation history from a YAML file."""
|
210
|
+
pass
|
211
|
+
|
212
|
+
@abstractmethod
|
213
|
+
def get_last_message(self) -> Optional[Dict]:
|
214
|
+
"""Get the last message from the conversation history."""
|
215
|
+
pass
|
216
|
+
|
217
|
+
@abstractmethod
|
218
|
+
def get_last_message_as_string(self) -> str:
|
219
|
+
"""Get the last message as a formatted string."""
|
220
|
+
pass
|
221
|
+
|
222
|
+
@abstractmethod
|
223
|
+
def get_messages_by_role(self, role: str) -> List[Dict]:
|
224
|
+
"""Get all messages from a specific role."""
|
225
|
+
pass
|
226
|
+
|
227
|
+
@abstractmethod
|
228
|
+
def get_conversation_summary(self) -> Dict:
|
229
|
+
"""Get a summary of the conversation."""
|
230
|
+
pass
|
231
|
+
|
232
|
+
@abstractmethod
|
233
|
+
def get_statistics(self) -> Dict:
|
234
|
+
"""Get statistics about the conversation."""
|
235
|
+
pass
|
236
|
+
|
237
|
+
@abstractmethod
|
238
|
+
def get_conversation_id(self) -> str:
|
239
|
+
"""Get the current conversation ID."""
|
240
|
+
pass
|
241
|
+
|
242
|
+
@abstractmethod
|
243
|
+
def start_new_conversation(self) -> str:
|
244
|
+
"""Start a new conversation and return its ID."""
|
245
|
+
pass
|
246
|
+
|
247
|
+
@abstractmethod
|
248
|
+
def delete_current_conversation(self) -> bool:
|
249
|
+
"""Delete the current conversation."""
|
250
|
+
pass
|
251
|
+
|
252
|
+
@abstractmethod
|
253
|
+
def search_messages(self, query: str) -> List[Dict]:
|
254
|
+
"""Search for messages containing specific text."""
|
255
|
+
pass
|
256
|
+
|
257
|
+
@abstractmethod
|
258
|
+
def update_message(
|
259
|
+
self,
|
260
|
+
message_id: int,
|
261
|
+
content: Union[str, dict, list],
|
262
|
+
metadata: Optional[Dict] = None,
|
263
|
+
) -> bool:
|
264
|
+
"""Update an existing message."""
|
265
|
+
pass
|
266
|
+
|
267
|
+
@abstractmethod
|
268
|
+
def get_conversation_metadata_dict(self) -> Dict:
|
269
|
+
"""Get detailed metadata about the conversation."""
|
270
|
+
pass
|
271
|
+
|
272
|
+
@abstractmethod
|
273
|
+
def get_conversation_timeline_dict(self) -> Dict[str, List[Dict]]:
|
274
|
+
"""Get the conversation organized by timestamps."""
|
275
|
+
pass
|
276
|
+
|
277
|
+
@abstractmethod
|
278
|
+
def get_conversation_by_role_dict(self) -> Dict[str, List[Dict]]:
|
279
|
+
"""Get the conversation organized by roles."""
|
280
|
+
pass
|
281
|
+
|
282
|
+
@abstractmethod
|
283
|
+
def get_conversation_as_dict(self) -> Dict:
|
284
|
+
"""Get the entire conversation as a dictionary with messages and metadata."""
|
285
|
+
pass
|
286
|
+
|
287
|
+
@abstractmethod
|
288
|
+
def truncate_memory_with_tokenizer(self):
|
289
|
+
"""Truncate the conversation history based on token count."""
|
290
|
+
pass
|