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,136 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2025 Addison Kline
3
+
4
+ import warnings
5
+ from collections.abc import Awaitable
6
+ from typing import Any, Literal
7
+
8
+ from mail.core.agents import AgentOutput
9
+ from mail.factories import AgentFunction
10
+ from mail.factories.base import LiteLLMAgentFunction
11
+
12
+ math_agent_params = {
13
+ "llm": "openai/gpt-5-mini",
14
+ "system": "mail.examples.math_dummy.prompts:SYSPROMPT",
15
+ }
16
+
17
+
18
+ def factory_math_dummy(
19
+ # REQUIRED
20
+ # top-level params
21
+ comm_targets: list[str],
22
+ tools: list[dict[str, Any]],
23
+ # instance params
24
+ user_token: str,
25
+ # internal params
26
+ llm: str,
27
+ system: str,
28
+ # OPTIONAL
29
+ # top-level params
30
+ name: str = "math",
31
+ enable_entrypoint: bool = False,
32
+ enable_interswarm: bool = False,
33
+ can_complete_tasks: bool = False,
34
+ tool_format: Literal["completions", "responses"] = "responses",
35
+ exclude_tools: list[str] = [],
36
+ # instance params
37
+ # ...
38
+ # internal params
39
+ reasoning_effort: Literal["low", "medium", "high"] | None = None,
40
+ thinking_budget: int | None = None,
41
+ max_tokens: int | None = None,
42
+ memory: bool = True,
43
+ use_proxy: bool = True,
44
+ ) -> AgentFunction:
45
+ warnings.warn(
46
+ "`mail.examples.math_dummy:factory_math_dummy` is deprecated and will be removed in a future version. "
47
+ "Use `mail.examples.math_dummy:LiteLLMMathFunction` instead.",
48
+ DeprecationWarning,
49
+ stacklevel=2,
50
+ )
51
+
52
+ litellm_math = LiteLLMMathFunction(
53
+ name=name,
54
+ comm_targets=comm_targets,
55
+ tools=tools,
56
+ llm=llm,
57
+ system=system,
58
+ user_token=user_token,
59
+ enable_entrypoint=enable_entrypoint,
60
+ enable_interswarm=enable_interswarm,
61
+ can_complete_tasks=can_complete_tasks,
62
+ reasoning_effort=reasoning_effort,
63
+ thinking_budget=thinking_budget,
64
+ max_tokens=max_tokens,
65
+ memory=memory,
66
+ use_proxy=use_proxy,
67
+ tool_format=tool_format,
68
+ exclude_tools=exclude_tools,
69
+ )
70
+
71
+ async def run(
72
+ messages: list[dict[str, Any]],
73
+ tool_choice: str | dict[str, str] = "required",
74
+ ) -> AgentOutput:
75
+ """
76
+ Execute the LiteLLM-based math agent function.
77
+ """
78
+ return await litellm_math(messages, tool_choice)
79
+
80
+ return run
81
+
82
+
83
+ class LiteLLMMathFunction(LiteLLMAgentFunction):
84
+ """
85
+ Class that represents a LiteLLM-based math agent function.
86
+ """
87
+
88
+ def __init__(
89
+ self,
90
+ name: str,
91
+ comm_targets: list[str],
92
+ tools: list[dict[str, Any]],
93
+ llm: str,
94
+ system: str,
95
+ user_token: str = "",
96
+ enable_entrypoint: bool = False,
97
+ enable_interswarm: bool = False,
98
+ can_complete_tasks: bool = False,
99
+ tool_format: Literal["completions", "responses"] = "responses",
100
+ exclude_tools: list[str] = [],
101
+ reasoning_effort: Literal["minimal", "low", "medium", "high"] | None = None,
102
+ thinking_budget: int | None = None,
103
+ max_tokens: int | None = None,
104
+ memory: bool = True,
105
+ use_proxy: bool = True,
106
+ _debug_include_mail_tools: bool = True,
107
+ ) -> None:
108
+ super().__init__(
109
+ name=name,
110
+ comm_targets=comm_targets,
111
+ tools=tools,
112
+ llm=llm,
113
+ system=system,
114
+ user_token=user_token,
115
+ enable_entrypoint=enable_entrypoint,
116
+ enable_interswarm=enable_interswarm,
117
+ can_complete_tasks=can_complete_tasks,
118
+ tool_format=tool_format,
119
+ exclude_tools=exclude_tools,
120
+ reasoning_effort=reasoning_effort,
121
+ thinking_budget=thinking_budget,
122
+ max_tokens=max_tokens,
123
+ memory=memory,
124
+ use_proxy=use_proxy,
125
+ _debug_include_mail_tools=_debug_include_mail_tools,
126
+ )
127
+
128
+ def __call__(
129
+ self,
130
+ messages: list[dict[str, Any]],
131
+ tool_choice: str | dict[str, str] = "required",
132
+ ) -> Awaitable[AgentOutput]:
133
+ """
134
+ Execute the LiteLLM-based math agent function.
135
+ """
136
+ return super().__call__(messages, tool_choice)
@@ -0,0 +1,46 @@
1
+ SYSPROMPT = """You are math@{swarm}, a specialist agent for mathematical calculations.
2
+
3
+ # Your Role
4
+ Solve mathematical problems using `calculate_expression` and report results back to your requestor.
5
+
6
+ # Critical Rule: Responding
7
+ You CANNOT talk to users directly or call `task_complete`. You MUST use `send_response` to reply to the agent who contacted you.
8
+ - When you receive a request, note the sender (usually "supervisor")
9
+ - After solving the problem, call `send_response(target=<sender>, subject="Re: ...", body=<your answer>)`
10
+ - Include your complete solution in the response body - the recipient cannot see tool results
11
+
12
+ # Tools
13
+
14
+ ## Math
15
+ - `calculate_expression(expression, precision?)`: Evaluate arithmetic expressions
16
+ - Supports: +, -, *, /, //, %, **, parentheses
17
+ - Constants: pi, e, tau
18
+ - Returns: result (exact), formatted_result (rounded), is_integer
19
+
20
+ ## Communication
21
+ - `send_response(target, subject, body)`: Reply to the agent who requested the calculation
22
+ - `send_request(target, subject, body)`: Ask another agent for information (rare)
23
+ - `acknowledge_broadcast(note)`: Acknowledge a broadcast message
24
+ - `ignore_broadcast(reason)`: Ignore an irrelevant broadcast
25
+
26
+ # Workflow
27
+
28
+ 1. Receive request from another agent (check the sender address)
29
+ 2. Parse the mathematical problem from the request
30
+ 3. Use `calculate_expression` for arithmetic, or solve algebraically
31
+ 4. Call `send_response` to the original sender with the solution
32
+
33
+ # Response Format
34
+
35
+ Include in your response body:
36
+ - Brief explanation of approach (if non-trivial)
37
+ - Key calculation steps
38
+ - Final answer clearly marked (e.g., "Result: 42")
39
+ - Units if applicable
40
+
41
+ # Guidelines
42
+
43
+ - Use `calculate_expression` for precise arithmetic
44
+ - State assumptions if the problem is ambiguous
45
+ - If a problem is outside your scope, explain the limitation
46
+ - Use "Re: <original subject>" as your response subject"""
@@ -0,0 +1,5 @@
1
+ from mail.examples.math_dummy.actions import calculate_expression
2
+
3
+ action_calculate_expression = calculate_expression
4
+
5
+ __all__ = ["action_calculate_expression"]
@@ -0,0 +1,39 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2025 Charon Labs
3
+
4
+ """Research Assistant example swarm.
5
+
6
+ This swarm demonstrates research workflows with information gathering,
7
+ fact verification, and summarization. It includes real HTTP integrations
8
+ where available with dummy fallbacks.
9
+
10
+ Agents:
11
+ - researcher: Entry point that coordinates research tasks
12
+ - searcher: Searches for information on topics
13
+ - verifier: Cross-references and verifies claims
14
+ - summarizer: Synthesizes and summarizes findings
15
+ """
16
+
17
+ from mail.examples.research.researcher.agent import LiteLLMResearcherFunction
18
+ from mail.examples.research.searcher.agent import LiteLLMSearcherFunction
19
+ from mail.examples.research.searcher.actions import search_topic, extract_facts
20
+ from mail.examples.research.verifier.agent import LiteLLMVerifierFunction
21
+ from mail.examples.research.verifier.actions import verify_claim, rate_confidence
22
+ from mail.examples.research.summarizer.agent import LiteLLMSummarizerFunction
23
+ from mail.examples.research.summarizer.actions import (
24
+ summarize_text,
25
+ create_bibliography,
26
+ )
27
+
28
+ __all__ = [
29
+ "LiteLLMResearcherFunction",
30
+ "LiteLLMSearcherFunction",
31
+ "LiteLLMVerifierFunction",
32
+ "LiteLLMSummarizerFunction",
33
+ "search_topic",
34
+ "extract_facts",
35
+ "verify_claim",
36
+ "rate_confidence",
37
+ "summarize_text",
38
+ "create_bibliography",
39
+ ]
@@ -0,0 +1,9 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2025 Charon Labs
3
+
4
+ """Researcher agent for the Research Assistant swarm."""
5
+
6
+ from mail.examples.research.researcher.agent import LiteLLMResearcherFunction
7
+ from mail.examples.research.researcher.prompts import SYSPROMPT
8
+
9
+ __all__ = ["LiteLLMResearcherFunction", "SYSPROMPT"]
@@ -0,0 +1,67 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2025 Charon Labs
3
+
4
+ """Researcher agent for the Research Assistant swarm."""
5
+
6
+ from collections.abc import Awaitable
7
+ from typing import Any, Literal
8
+
9
+ from mail.core.agents import AgentOutput
10
+ from mail.factories.base import LiteLLMAgentFunction
11
+
12
+
13
+ class LiteLLMResearcherFunction(LiteLLMAgentFunction):
14
+ """
15
+ Lead researcher agent that orchestrates research workflows.
16
+
17
+ This agent serves as the entry point for research requests and
18
+ coordinates searcher, verifier, and summarizer agents.
19
+ """
20
+
21
+ def __init__(
22
+ self,
23
+ name: str,
24
+ comm_targets: list[str],
25
+ tools: list[dict[str, Any]],
26
+ llm: str,
27
+ system: str,
28
+ user_token: str = "",
29
+ enable_entrypoint: bool = True,
30
+ enable_interswarm: bool = False,
31
+ can_complete_tasks: bool = True,
32
+ tool_format: Literal["completions", "responses"] = "responses",
33
+ exclude_tools: list[str] = [],
34
+ reasoning_effort: Literal["minimal", "low", "medium", "high"] | None = None,
35
+ thinking_budget: int | None = None,
36
+ max_tokens: int | None = None,
37
+ memory: bool = True,
38
+ use_proxy: bool = True,
39
+ _debug_include_mail_tools: bool = True,
40
+ ) -> None:
41
+ super().__init__(
42
+ name=name,
43
+ comm_targets=comm_targets,
44
+ tools=tools,
45
+ llm=llm,
46
+ system=system,
47
+ user_token=user_token,
48
+ enable_entrypoint=enable_entrypoint,
49
+ enable_interswarm=enable_interswarm,
50
+ can_complete_tasks=can_complete_tasks,
51
+ tool_format=tool_format,
52
+ exclude_tools=exclude_tools,
53
+ reasoning_effort=reasoning_effort,
54
+ thinking_budget=thinking_budget,
55
+ max_tokens=max_tokens,
56
+ memory=memory,
57
+ use_proxy=use_proxy,
58
+ _debug_include_mail_tools=_debug_include_mail_tools,
59
+ )
60
+
61
+ def __call__(
62
+ self,
63
+ messages: list[dict[str, Any]],
64
+ tool_choice: str | dict[str, str] = "required",
65
+ ) -> Awaitable[AgentOutput]:
66
+ """Execute the researcher agent function."""
67
+ return super().__call__(messages, tool_choice)
@@ -0,0 +1,54 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2025 Charon Labs
3
+
4
+ SYSPROMPT = """You are researcher@{swarm}, the lead researcher for this research assistant swarm.
5
+
6
+ # Your Role
7
+ Orchestrate research workflows by coordinating specialist agents to gather information, verify facts, and synthesize findings into clear summaries.
8
+
9
+ # Critical Rules
10
+
11
+ 1. **You MUST call task_complete to end every task** - this is how the user receives their research results
12
+ 2. Delegate work to specialist agents based on research needs:
13
+ - `searcher` - For finding information and extracting facts
14
+ - `verifier` - For cross-referencing and verifying claims
15
+ - `summarizer` - For synthesizing and formatting results
16
+
17
+ # Available Agents
18
+
19
+ - **searcher**: Searches for information on topics using various sources (Wikipedia, academic, news, general). Can also extract key facts from text.
20
+ - **verifier**: Cross-references claims against sources and rates confidence levels based on evidence quality.
21
+ - **summarizer**: Synthesizes information into clear summaries and creates formatted bibliographies.
22
+
23
+ # Communication Tools
24
+
25
+ - `send_request(target, subject, body)`: Delegate a task to another agent
26
+ - `send_broadcast(subject, body, targets)`: Notify multiple agents simultaneously
27
+ - `await_message(reason)`: Wait for responses from delegated tasks
28
+ - `task_complete(finish_message)`: Return your final answer to the user
29
+
30
+ # Workflow
31
+
32
+ 1. Receive research request from user
33
+ 2. Break down the research question into searchable topics
34
+ 3. Send search requests to searcher agent for each topic
35
+ 4. Have verifier check important claims
36
+ 5. Send all findings to summarizer for synthesis
37
+ 6. Review the summary and ensure it answers the original question
38
+ 7. Call `task_complete` with the final research summary
39
+
40
+ # Research Quality Guidelines
41
+
42
+ - Always verify important factual claims
43
+ - Note when information is uncertain or conflicting
44
+ - Include source references in final output
45
+ - Be transparent about limitations of the research
46
+ - Present balanced perspectives on controversial topics
47
+
48
+ # Guidelines
49
+
50
+ - Start with broad searches, then narrow down
51
+ - Verify statistics and specific claims
52
+ - Include confidence levels in final output
53
+ - Always provide source attribution
54
+ - If a topic is too broad, ask for clarification"""
@@ -0,0 +1,10 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2025 Charon Labs
3
+
4
+ """Searcher agent for the Research Assistant swarm."""
5
+
6
+ from mail.examples.research.searcher.agent import LiteLLMSearcherFunction
7
+ from mail.examples.research.searcher.actions import search_topic, extract_facts
8
+ from mail.examples.research.searcher.prompts import SYSPROMPT
9
+
10
+ __all__ = ["LiteLLMSearcherFunction", "search_topic", "extract_facts", "SYSPROMPT"]