mail-swarms 1.3.2__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.
Files changed (137) hide show
  1. mail/__init__.py +35 -0
  2. mail/api.py +1964 -0
  3. mail/cli.py +432 -0
  4. mail/client.py +1657 -0
  5. mail/config/__init__.py +8 -0
  6. mail/config/client.py +87 -0
  7. mail/config/server.py +165 -0
  8. mail/core/__init__.py +72 -0
  9. mail/core/actions.py +69 -0
  10. mail/core/agents.py +73 -0
  11. mail/core/message.py +366 -0
  12. mail/core/runtime.py +3537 -0
  13. mail/core/tasks.py +311 -0
  14. mail/core/tools.py +1206 -0
  15. mail/db/__init__.py +0 -0
  16. mail/db/init.py +182 -0
  17. mail/db/types.py +65 -0
  18. mail/db/utils.py +523 -0
  19. mail/examples/__init__.py +27 -0
  20. mail/examples/analyst_dummy/__init__.py +15 -0
  21. mail/examples/analyst_dummy/agent.py +136 -0
  22. mail/examples/analyst_dummy/prompts.py +44 -0
  23. mail/examples/consultant_dummy/__init__.py +15 -0
  24. mail/examples/consultant_dummy/agent.py +136 -0
  25. mail/examples/consultant_dummy/prompts.py +42 -0
  26. mail/examples/data_analysis/__init__.py +40 -0
  27. mail/examples/data_analysis/analyst/__init__.py +9 -0
  28. mail/examples/data_analysis/analyst/agent.py +67 -0
  29. mail/examples/data_analysis/analyst/prompts.py +53 -0
  30. mail/examples/data_analysis/processor/__init__.py +13 -0
  31. mail/examples/data_analysis/processor/actions.py +293 -0
  32. mail/examples/data_analysis/processor/agent.py +67 -0
  33. mail/examples/data_analysis/processor/prompts.py +48 -0
  34. mail/examples/data_analysis/reporter/__init__.py +10 -0
  35. mail/examples/data_analysis/reporter/actions.py +187 -0
  36. mail/examples/data_analysis/reporter/agent.py +67 -0
  37. mail/examples/data_analysis/reporter/prompts.py +49 -0
  38. mail/examples/data_analysis/statistics/__init__.py +18 -0
  39. mail/examples/data_analysis/statistics/actions.py +343 -0
  40. mail/examples/data_analysis/statistics/agent.py +67 -0
  41. mail/examples/data_analysis/statistics/prompts.py +60 -0
  42. mail/examples/mafia/__init__.py +0 -0
  43. mail/examples/mafia/game.py +1537 -0
  44. mail/examples/mafia/narrator_tools.py +396 -0
  45. mail/examples/mafia/personas.py +240 -0
  46. mail/examples/mafia/prompts.py +489 -0
  47. mail/examples/mafia/roles.py +147 -0
  48. mail/examples/mafia/spec.md +350 -0
  49. mail/examples/math_dummy/__init__.py +23 -0
  50. mail/examples/math_dummy/actions.py +252 -0
  51. mail/examples/math_dummy/agent.py +136 -0
  52. mail/examples/math_dummy/prompts.py +46 -0
  53. mail/examples/math_dummy/types.py +5 -0
  54. mail/examples/research/__init__.py +39 -0
  55. mail/examples/research/researcher/__init__.py +9 -0
  56. mail/examples/research/researcher/agent.py +67 -0
  57. mail/examples/research/researcher/prompts.py +54 -0
  58. mail/examples/research/searcher/__init__.py +10 -0
  59. mail/examples/research/searcher/actions.py +324 -0
  60. mail/examples/research/searcher/agent.py +67 -0
  61. mail/examples/research/searcher/prompts.py +53 -0
  62. mail/examples/research/summarizer/__init__.py +18 -0
  63. mail/examples/research/summarizer/actions.py +255 -0
  64. mail/examples/research/summarizer/agent.py +67 -0
  65. mail/examples/research/summarizer/prompts.py +55 -0
  66. mail/examples/research/verifier/__init__.py +10 -0
  67. mail/examples/research/verifier/actions.py +337 -0
  68. mail/examples/research/verifier/agent.py +67 -0
  69. mail/examples/research/verifier/prompts.py +52 -0
  70. mail/examples/supervisor/__init__.py +11 -0
  71. mail/examples/supervisor/agent.py +4 -0
  72. mail/examples/supervisor/prompts.py +93 -0
  73. mail/examples/support/__init__.py +33 -0
  74. mail/examples/support/classifier/__init__.py +10 -0
  75. mail/examples/support/classifier/actions.py +307 -0
  76. mail/examples/support/classifier/agent.py +68 -0
  77. mail/examples/support/classifier/prompts.py +56 -0
  78. mail/examples/support/coordinator/__init__.py +9 -0
  79. mail/examples/support/coordinator/agent.py +67 -0
  80. mail/examples/support/coordinator/prompts.py +48 -0
  81. mail/examples/support/faq/__init__.py +10 -0
  82. mail/examples/support/faq/actions.py +182 -0
  83. mail/examples/support/faq/agent.py +67 -0
  84. mail/examples/support/faq/prompts.py +42 -0
  85. mail/examples/support/sentiment/__init__.py +15 -0
  86. mail/examples/support/sentiment/actions.py +341 -0
  87. mail/examples/support/sentiment/agent.py +67 -0
  88. mail/examples/support/sentiment/prompts.py +54 -0
  89. mail/examples/weather_dummy/__init__.py +23 -0
  90. mail/examples/weather_dummy/actions.py +75 -0
  91. mail/examples/weather_dummy/agent.py +136 -0
  92. mail/examples/weather_dummy/prompts.py +35 -0
  93. mail/examples/weather_dummy/types.py +5 -0
  94. mail/factories/__init__.py +27 -0
  95. mail/factories/action.py +223 -0
  96. mail/factories/base.py +1531 -0
  97. mail/factories/supervisor.py +241 -0
  98. mail/net/__init__.py +7 -0
  99. mail/net/registry.py +712 -0
  100. mail/net/router.py +728 -0
  101. mail/net/server_utils.py +114 -0
  102. mail/net/types.py +247 -0
  103. mail/server.py +1605 -0
  104. mail/stdlib/__init__.py +0 -0
  105. mail/stdlib/anthropic/__init__.py +0 -0
  106. mail/stdlib/fs/__init__.py +15 -0
  107. mail/stdlib/fs/actions.py +209 -0
  108. mail/stdlib/http/__init__.py +19 -0
  109. mail/stdlib/http/actions.py +333 -0
  110. mail/stdlib/interswarm/__init__.py +11 -0
  111. mail/stdlib/interswarm/actions.py +208 -0
  112. mail/stdlib/mcp/__init__.py +19 -0
  113. mail/stdlib/mcp/actions.py +294 -0
  114. mail/stdlib/openai/__init__.py +13 -0
  115. mail/stdlib/openai/agents.py +451 -0
  116. mail/summarizer.py +234 -0
  117. mail/swarms_json/__init__.py +27 -0
  118. mail/swarms_json/types.py +87 -0
  119. mail/swarms_json/utils.py +255 -0
  120. mail/url_scheme.py +51 -0
  121. mail/utils/__init__.py +53 -0
  122. mail/utils/auth.py +194 -0
  123. mail/utils/context.py +17 -0
  124. mail/utils/logger.py +73 -0
  125. mail/utils/openai.py +212 -0
  126. mail/utils/parsing.py +89 -0
  127. mail/utils/serialize.py +292 -0
  128. mail/utils/store.py +49 -0
  129. mail/utils/string_builder.py +119 -0
  130. mail/utils/version.py +20 -0
  131. mail_swarms-1.3.2.dist-info/METADATA +237 -0
  132. mail_swarms-1.3.2.dist-info/RECORD +137 -0
  133. mail_swarms-1.3.2.dist-info/WHEEL +4 -0
  134. mail_swarms-1.3.2.dist-info/entry_points.txt +2 -0
  135. mail_swarms-1.3.2.dist-info/licenses/LICENSE +202 -0
  136. mail_swarms-1.3.2.dist-info/licenses/NOTICE +10 -0
  137. mail_swarms-1.3.2.dist-info/licenses/THIRD_PARTY_NOTICES.md +12334 -0
@@ -0,0 +1,241 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2025 Addison Kline, Ryan Heaton
3
+
4
+ import warnings
5
+ from abc import abstractmethod
6
+ from collections.abc import Awaitable
7
+ from typing import Any, Literal
8
+
9
+ from openai.resources.responses.responses import _make_tools
10
+
11
+ from mail.core.agents import AgentFunction, AgentOutput
12
+ from mail.core.tools import (
13
+ create_supervisor_tools,
14
+ pydantic_function_tool,
15
+ )
16
+ from mail.factories.base import (
17
+ LiteLLMAgentFunction,
18
+ MAILAgentFunction,
19
+ )
20
+
21
+
22
+ def supervisor_factory(
23
+ # REQUIRED
24
+ # top-level params
25
+ comm_targets: list[str],
26
+ tools: list[dict[str, Any]],
27
+ # instance params
28
+ user_token: str,
29
+ # internal params
30
+ llm: str,
31
+ system: str,
32
+ # OPTIONAL
33
+ # top-level params
34
+ name: str = "supervisor",
35
+ enable_entrypoint: bool = True,
36
+ enable_interswarm: bool = False,
37
+ can_complete_tasks: bool = True,
38
+ tool_format: Literal["completions", "responses"] = "responses",
39
+ exclude_tools: list[str] = [],
40
+ # instance params
41
+ # ...
42
+ # internal params
43
+ reasoning_effort: Literal["low", "medium", "high"] | None = None,
44
+ thinking_budget: int | None = None,
45
+ max_tokens: int | None = None,
46
+ memory: bool = True,
47
+ use_proxy: bool = True,
48
+ stream_tokens: bool = False,
49
+ default_tool_choice: str | dict[str, str] | None = None,
50
+ ) -> AgentFunction:
51
+ """
52
+ Create a `supervisor` agent function.
53
+ """
54
+ warnings.warn(
55
+ "`mail.factories.supervisor:supervisor_factory` is deprecated and will be removed in a future version. "
56
+ "Use `mail.factories.supervisor:LiteLLMSupervisorFunction` instead.",
57
+ DeprecationWarning,
58
+ stacklevel=2,
59
+ )
60
+
61
+ litellm_supervisor = LiteLLMSupervisorFunction(
62
+ name=name,
63
+ comm_targets=comm_targets,
64
+ tools=tools,
65
+ llm=llm,
66
+ system=system,
67
+ user_token=user_token,
68
+ enable_entrypoint=enable_entrypoint,
69
+ enable_interswarm=enable_interswarm,
70
+ can_complete_tasks=True, # supervisor can always complete tasks; param kept for compatibility
71
+ reasoning_effort=reasoning_effort,
72
+ thinking_budget=thinking_budget,
73
+ max_tokens=max_tokens,
74
+ memory=memory,
75
+ use_proxy=use_proxy,
76
+ tool_format=tool_format,
77
+ exclude_tools=exclude_tools,
78
+ stream_tokens=stream_tokens,
79
+ default_tool_choice=default_tool_choice,
80
+ )
81
+
82
+ async def run(
83
+ messages: list[dict[str, Any]],
84
+ tool_choice: str | dict[str, str] = "required",
85
+ ) -> AgentOutput:
86
+ """
87
+ Execute the MAIL-compatible supervisor function.
88
+ """
89
+ return await litellm_supervisor(messages, tool_choice)
90
+
91
+ return run
92
+
93
+
94
+ class SupervisorFunction(MAILAgentFunction):
95
+ """
96
+ Class representing a MAIL-compatible supervisor function.
97
+ """
98
+
99
+ def __init__(
100
+ self,
101
+ name: str,
102
+ comm_targets: list[str],
103
+ tools: list[dict[str, Any]],
104
+ can_complete_tasks: bool = True,
105
+ enable_entrypoint: bool = False,
106
+ enable_interswarm: bool = False,
107
+ tool_format: Literal["completions", "responses"] = "responses",
108
+ exclude_tools: list[str] = [],
109
+ **kwargs: Any,
110
+ ) -> None:
111
+ _debug_include_intraswarm = True
112
+
113
+ if len(comm_targets) == 0:
114
+ _debug_include_intraswarm = False
115
+
116
+ # parse the user-provided tools
117
+ parsed_tools: list[dict[str, Any]] = []
118
+ if len(tools) == 0:
119
+ parsed_tools = []
120
+ elif not isinstance(tools[0], dict):
121
+ parsed_tools = [pydantic_function_tool(tool) for tool in tools]
122
+ if tool_format == "responses":
123
+ parsed_tools = _make_tools(parsed_tools)
124
+ else:
125
+ parsed_tools = tools
126
+
127
+ # add supervisor tools to user-provided tools
128
+ parsed_tools += create_supervisor_tools(
129
+ targets=comm_targets,
130
+ can_complete_tasks=True, # supervisor can always complete tasks; param kept for compatibility
131
+ enable_interswarm=enable_interswarm,
132
+ exclude_tools=exclude_tools,
133
+ style=tool_format,
134
+ _debug_include_intraswarm=_debug_include_intraswarm,
135
+ )
136
+
137
+ super().__init__(
138
+ name=name,
139
+ comm_targets=comm_targets,
140
+ tools=parsed_tools,
141
+ enable_entrypoint=enable_entrypoint,
142
+ enable_interswarm=enable_interswarm,
143
+ can_complete_tasks=True, # supervisor can always complete tasks; param kept for compatibility
144
+ tool_format=tool_format,
145
+ exclude_tools=exclude_tools,
146
+ **kwargs,
147
+ )
148
+
149
+ @abstractmethod
150
+ def __call__(
151
+ self,
152
+ messages: list[dict[str, Any]],
153
+ tool_choice: str | dict[str, str] = "required",
154
+ ) -> Awaitable[AgentOutput]:
155
+ """
156
+ Execute the MAIL-compatible supervisor function.
157
+ """
158
+ pass
159
+
160
+
161
+ class LiteLLMSupervisorFunction(SupervisorFunction):
162
+ """
163
+ Class representing a MAIL-compatible, LiteLLM-based supervisor function.
164
+ """
165
+
166
+ def __init__(
167
+ self,
168
+ name: str,
169
+ comm_targets: list[str],
170
+ tools: list[dict[str, Any]],
171
+ llm: str,
172
+ system: str,
173
+ user_token: str = "",
174
+ enable_entrypoint: bool = False,
175
+ enable_interswarm: bool = False,
176
+ can_complete_tasks: bool = True,
177
+ tool_format: Literal["completions", "responses"] = "responses",
178
+ exclude_tools: list[str] = [],
179
+ reasoning_effort: Literal["minimal", "low", "medium", "high"] | None = None,
180
+ thinking_budget: int | None = None,
181
+ max_tokens: int | None = None,
182
+ memory: bool = True,
183
+ use_proxy: bool = True,
184
+ _debug_include_mail_tools: bool = True,
185
+ stream_tokens: bool = False,
186
+ default_tool_choice: str | dict[str, str] | None = None,
187
+ ) -> None:
188
+ super().__init__(
189
+ name=name,
190
+ comm_targets=comm_targets,
191
+ tools=tools,
192
+ enable_entrypoint=enable_entrypoint,
193
+ enable_interswarm=enable_interswarm,
194
+ can_complete_tasks=True, # supervisor can always complete tasks; param kept for compatibility
195
+ tool_format=tool_format,
196
+ exclude_tools=exclude_tools,
197
+ )
198
+ self.llm = llm
199
+ self.system = system
200
+ self.user_token = user_token
201
+ self.reasoning_effort = reasoning_effort
202
+ self.thinking_budget = thinking_budget
203
+ self.max_tokens = max_tokens
204
+ self.memory = memory
205
+ self.use_proxy = use_proxy
206
+ self._debug_include_mail_tools = _debug_include_mail_tools
207
+ self.stream_tokens = stream_tokens
208
+ self.default_tool_choice = default_tool_choice
209
+ self.supervisor_fn = LiteLLMAgentFunction(
210
+ name=self.name,
211
+ comm_targets=self.comm_targets,
212
+ tools=self.tools,
213
+ llm=self.llm,
214
+ system=self.system,
215
+ enable_entrypoint=self.enable_entrypoint,
216
+ enable_interswarm=self.enable_interswarm,
217
+ can_complete_tasks=True,
218
+ tool_format=self.tool_format,
219
+ exclude_tools=self.exclude_tools,
220
+ reasoning_effort=self.reasoning_effort,
221
+ thinking_budget=self.thinking_budget,
222
+ max_tokens=self.max_tokens,
223
+ memory=self.memory,
224
+ use_proxy=self.use_proxy,
225
+ _debug_include_mail_tools=self._debug_include_mail_tools,
226
+ stream_tokens=self.stream_tokens,
227
+ default_tool_choice=self.default_tool_choice,
228
+ )
229
+
230
+ def __call__(
231
+ self,
232
+ messages: list[dict[str, Any]],
233
+ tool_choice: str | dict[str, str] = "required",
234
+ ) -> Awaitable[AgentOutput]:
235
+ """
236
+ Execute a LiteLLM-based supervisor function.
237
+ """
238
+ return self.supervisor_fn(
239
+ messages=messages,
240
+ tool_choice=tool_choice,
241
+ )
mail/net/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ from .registry import SwarmRegistry
2
+ from .router import InterswarmRouter
3
+
4
+ __all__ = [
5
+ "SwarmRegistry",
6
+ "InterswarmRouter",
7
+ ]