langchain-sendmux 0.2.0__tar.gz

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.
@@ -0,0 +1,22 @@
1
+ node_modules/
2
+ .venv/
3
+ .pytest_cache/
4
+ dist/
5
+ .tmp/
6
+ coverage/
7
+ .DS_Store
8
+ *.log
9
+ *.snap
10
+ snapcraft-*.txt
11
+ *.codegen.json
12
+ .codegen/
13
+ .codegraph/
14
+ *.tsbuildinfo
15
+ packages/ts/cli/oclif.manifest.json
16
+ packages/ts/cli/tmp/
17
+ .phpunit.result.cache
18
+ __pycache__/
19
+ *.py[cod]
20
+ vendor/
21
+ .bundle/
22
+ target/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sendmux
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: langchain-sendmux
3
+ Version: 0.2.0
4
+ Summary: LangChain toolkit for the Sendmux email API for AI agents.
5
+ Project-URL: Repository, https://github.com/Sendmux/sendmux-sdk
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: langchain-core<2,>=1.0.0
16
+ Requires-Dist: sendmux-mailbox<2.0.0,>=1.2.0
17
+ Requires-Dist: sendmux-sending<2.0.0,>=1.3.0
18
+ Description-Content-Type: text/markdown
19
+
20
+ # langchain-sendmux
21
+
22
+ [LangChain](https://docs.langchain.com) toolkit for [Sendmux](https://sendmux.ai), the email API for AI agents. Give a LangChain agent tools to send email and read its own inbox.
23
+
24
+ ## Installation
25
+
26
+ ```sh
27
+ pip install langchain-sendmux
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```python
33
+ import os
34
+
35
+ from langchain.agents import create_agent
36
+ from langchain_sendmux import SendmuxToolkit
37
+
38
+ smx = SendmuxToolkit(api_key=os.environ["SENDMUX_API_KEY"])
39
+
40
+ agent = create_agent(
41
+ model="gpt-4o",
42
+ tools=smx.get_tools(),
43
+ system_prompt="You triage the support inbox.",
44
+ )
45
+
46
+ agent.invoke({"messages": [{"role": "user", "content": "Reply to Sarah."}]})
47
+ ```
48
+
49
+ ## Tools
50
+
51
+ `SendmuxToolkit(api_key=...).get_tools()` returns three tools:
52
+
53
+ - `send_email` - send an email to any recipient through Sendmux.
54
+ - `list_messages` - list recent messages in the agent's mailbox.
55
+ - `reply` - send a message from the agent's own mailbox.
56
+
57
+ ## Configuration
58
+
59
+ - `api_key` (required) - a send + receive capable mailbox API key (`smx_mbx_*`) or a scoped agent token.
60
+ - `default_from` (optional) - default From address for `send_email` when a call omits `var_from`.
61
+
62
+ ## Licence
63
+
64
+ MIT. See the [licence file](https://github.com/Sendmux/sendmux-sdk/blob/main/LICENSE).
@@ -0,0 +1,45 @@
1
+ # langchain-sendmux
2
+
3
+ [LangChain](https://docs.langchain.com) toolkit for [Sendmux](https://sendmux.ai), the email API for AI agents. Give a LangChain agent tools to send email and read its own inbox.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pip install langchain-sendmux
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ import os
15
+
16
+ from langchain.agents import create_agent
17
+ from langchain_sendmux import SendmuxToolkit
18
+
19
+ smx = SendmuxToolkit(api_key=os.environ["SENDMUX_API_KEY"])
20
+
21
+ agent = create_agent(
22
+ model="gpt-4o",
23
+ tools=smx.get_tools(),
24
+ system_prompt="You triage the support inbox.",
25
+ )
26
+
27
+ agent.invoke({"messages": [{"role": "user", "content": "Reply to Sarah."}]})
28
+ ```
29
+
30
+ ## Tools
31
+
32
+ `SendmuxToolkit(api_key=...).get_tools()` returns three tools:
33
+
34
+ - `send_email` - send an email to any recipient through Sendmux.
35
+ - `list_messages` - list recent messages in the agent's mailbox.
36
+ - `reply` - send a message from the agent's own mailbox.
37
+
38
+ ## Configuration
39
+
40
+ - `api_key` (required) - a send + receive capable mailbox API key (`smx_mbx_*`) or a scoped agent token.
41
+ - `default_from` (optional) - default From address for `send_email` when a call omits `var_from`.
42
+
43
+ ## Licence
44
+
45
+ MIT. See the [licence file](https://github.com/Sendmux/sendmux-sdk/blob/main/LICENSE).
@@ -0,0 +1,7 @@
1
+ """LangChain toolkit for the Sendmux email API for AI agents."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from langchain_sendmux.toolkit import SendmuxToolkit
6
+
7
+ __all__ = ["SendmuxToolkit"]
File without changes
@@ -0,0 +1,146 @@
1
+ """LangChain toolkit for the Sendmux email API for AI agents."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from langchain_core.tools import BaseTool, BaseToolkit, tool
8
+ from pydantic import Field
9
+
10
+ from sendmux_mailbox import MailboxAPIApi, create_mailbox_client
11
+ from sendmux_mailbox.models.send_mailbox_message_body import SendMailboxMessageBody
12
+ from sendmux_sending import EmailSendRequest, EmailsApi, create_sending_client
13
+
14
+
15
+ def _html_from_text(text: str) -> str:
16
+ escaped = (
17
+ text.replace("&", "&amp;")
18
+ .replace("<", "&lt;")
19
+ .replace(">", "&gt;")
20
+ .replace("\n", "<br>")
21
+ )
22
+ return f"<p>{escaped}</p>"
23
+
24
+
25
+ class SendmuxToolkit(BaseToolkit):
26
+ """LangChain toolkit exposing Sendmux tools to an agent.
27
+
28
+ ``get_tools()`` returns three tools: ``send_email``, ``list_messages`` and
29
+ ``reply``.
30
+
31
+ Example:
32
+ >>> from langchain.agents import create_agent
33
+ >>> from langchain_sendmux import SendmuxToolkit
34
+ >>> smx = SendmuxToolkit(api_key="smx_mbx_...")
35
+ >>> agent = create_agent(model="gpt-4o", tools=smx.get_tools())
36
+ """
37
+
38
+ api_key: str = Field(
39
+ description=(
40
+ "A send + receive capable mailbox API key (smx_mbx_*) or a scoped "
41
+ "agent token. Read it from your environment; never hard-code it."
42
+ ),
43
+ )
44
+ default_from: Optional[str] = Field(
45
+ default=None,
46
+ description=(
47
+ "Default From address for send_email when a call omits `from`. "
48
+ "If unset, the model must supply a sender per call."
49
+ ),
50
+ )
51
+
52
+ def get_tools(self) -> list[BaseTool]:
53
+ sending_client = create_sending_client(api_key=self.api_key)
54
+ mailbox_client = create_mailbox_client(api_key=self.api_key)
55
+ emails = EmailsApi(sending_client)
56
+ mailbox = MailboxAPIApi(mailbox_client)
57
+ default_from = self.default_from
58
+
59
+ @tool
60
+ def send_email(
61
+ to: str,
62
+ subject: str,
63
+ text: str,
64
+ html: Optional[str] = None,
65
+ var_from: Optional[str] = None,
66
+ idempotency_key: Optional[str] = None,
67
+ ) -> Any:
68
+ """Send an email through Sendmux to any recipient.
69
+
70
+ Args:
71
+ to: Recipient email address.
72
+ subject: Email subject line.
73
+ text: Plain-text body of the email.
74
+ html: Optional HTML body.
75
+ var_from: Sender email address; defaults to the configured sender.
76
+ idempotency_key: Optional key that makes a retried send idempotent
77
+ for 24 hours.
78
+ """
79
+ sender = var_from if var_from is not None else default_from
80
+ if sender is None:
81
+ raise ValueError(
82
+ "No sender address: pass `var_from` in the tool call, or set "
83
+ "default_from on SendmuxToolkit."
84
+ )
85
+ # EmailSendRequest.var_from carries alias "from" (a Python keyword),
86
+ # so build from a dict via model_validate rather than keyword args.
87
+ response = emails.sending_send_email(
88
+ EmailSendRequest.model_validate(
89
+ {
90
+ "from": {"email": sender},
91
+ "to": {"email": to},
92
+ "subject": subject,
93
+ "text_body": text,
94
+ "html_body": (
95
+ html if html is not None else _html_from_text(text)
96
+ ),
97
+ }
98
+ ),
99
+ idempotency_key=idempotency_key,
100
+ )
101
+ return response.data
102
+
103
+ @tool
104
+ def list_messages(limit: int = 25) -> Any:
105
+ """List recent messages in the agent's mailbox, newest first.
106
+
107
+ Args:
108
+ limit: Maximum number of messages to return (1-100).
109
+ """
110
+ response = mailbox.mailbox_list_messages(limit=limit)
111
+ return response.data
112
+
113
+ @tool
114
+ def reply(
115
+ to: str,
116
+ subject: str,
117
+ text: str,
118
+ html: Optional[str] = None,
119
+ idempotency_key: Optional[str] = None,
120
+ ) -> Any:
121
+ """Send a message from the agent's own mailbox, e.g. to reply to a sender.
122
+
123
+ Args:
124
+ to: Recipient email address.
125
+ subject: Subject line.
126
+ text: Plain-text body.
127
+ html: Optional HTML body.
128
+ idempotency_key: Optional key that makes a retried send idempotent
129
+ for 24 hours.
130
+ """
131
+ response = mailbox.mailbox_send_message(
132
+ idempotency_key=idempotency_key,
133
+ send_mailbox_message_body=SendMailboxMessageBody.model_validate(
134
+ {
135
+ "to": [{"email": to, "name": None}],
136
+ "subject": subject,
137
+ "text_body": text,
138
+ "html_body": (
139
+ html if html is not None else _html_from_text(text)
140
+ ),
141
+ }
142
+ ),
143
+ )
144
+ return response.data
145
+
146
+ return [send_email, list_messages, reply]
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "langchain-sendmux"
7
+ version = "0.2.0"
8
+ description = "LangChain toolkit for the Sendmux email API for AI agents."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ classifiers = [
13
+ "License :: OSI Approved :: MIT License",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.10",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ ]
20
+ dependencies = [
21
+ "langchain-core>=1.0.0,<2",
22
+ "sendmux-sending>=1.3.0,<2.0.0",
23
+ "sendmux-mailbox>=1.2.0,<2.0.0",
24
+ ]
25
+
26
+ [project.urls]
27
+ Repository = "https://github.com/Sendmux/sendmux-sdk"
28
+
29
+ [tool.hatch.build.targets.sdist]
30
+ core-metadata-version = "2.4"
31
+ include = [
32
+ "LICENSE",
33
+ "README.md",
34
+ "langchain_sendmux",
35
+ ]
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ core-metadata-version = "2.4"
39
+ packages = ["langchain_sendmux"]
40
+ artifacts = ["langchain_sendmux/py.typed"]