langchain-qubrics 1.0.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.
- langchain_qubrics-1.0.0/.gitignore +22 -0
- langchain_qubrics-1.0.0/LICENSE +21 -0
- langchain_qubrics-1.0.0/PKG-INFO +171 -0
- langchain_qubrics-1.0.0/README.md +148 -0
- langchain_qubrics-1.0.0/pyproject.toml +59 -0
- langchain_qubrics-1.0.0/qubrics/langchain/__init__.py +7 -0
- langchain_qubrics-1.0.0/qubrics/langchain/py.typed +0 -0
- langchain_qubrics-1.0.0/qubrics/langchain/toolkit.py +168 -0
|
@@ -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,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langchain-qubrics
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: LangChain toolkit for the Qubrics email API for AI agents.
|
|
5
|
+
Project-URL: Homepage, https://qubrics.com
|
|
6
|
+
Project-URL: Documentation, https://qubrics.com/docs/sdks
|
|
7
|
+
Project-URL: Repository, https://github.com/qubrics/qubrics-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/qubrics/qubrics-sdk/issues
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agent,agents,ai-agents,email,email-api,inbox,langchain,langchain-toolkit,llm,mailbox,send-email,sendmux,tools,transactional-email
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: langchain-core<2,>=1.0.0
|
|
20
|
+
Requires-Dist: qubrics-mailbox<4.0.0,>=3.0.0
|
|
21
|
+
Requires-Dist: qubrics-sending<3.0.0,>=2.0.0
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# langchain-qubrics
|
|
25
|
+
|
|
26
|
+
[LangChain](https://docs.langchain.com) toolkit for [Qubrics](https://qubrics.com), the email API for AI agents.
|
|
27
|
+
|
|
28
|
+
Gives an agent its own mailbox: it can send email, read what arrives, and reply from its own address.
|
|
29
|
+
|
|
30
|
+
## Requirements
|
|
31
|
+
|
|
32
|
+
- Python 3.10 or newer
|
|
33
|
+
- `langchain-core` v1
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
These commands target the Qubrics release of `langchain-qubrics`. Until it is published, install `langchain-sendmux` with its existing import names.
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
pip install langchain-qubrics
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Getting an API key
|
|
44
|
+
|
|
45
|
+
For API-key authentication, use a key that can both send and receive. Two ways to get one:
|
|
46
|
+
|
|
47
|
+
- **Dashboard** — create a mailbox and a mailbox-scoped key (`smx_mbx_*`). See [API keys](https://qubrics.com/docs/guides/api-keys).
|
|
48
|
+
- **Agent self-registration** — the agent claims its own `@myagent.mx` mailbox and gets an `smx_agent_*` token, with no human signup first. See [email for AI agents](https://qubrics.com/solutions/for-ai-agents/).
|
|
49
|
+
|
|
50
|
+
Note on agent tokens: a freshly self-registered `smx_agent_*` token can read and receive, but **cannot send** until a human owner has been invited and has approved it. Until then `send_email` and `reply` will fail. A dashboard `smx_mbx_*` key with send permission works immediately.
|
|
51
|
+
|
|
52
|
+
Read the key from the environment. Never hard-code it.
|
|
53
|
+
|
|
54
|
+
## OAuth access tokens
|
|
55
|
+
|
|
56
|
+
Set `access_token` to a bare REST OAuth token or callable instead of `api_key`:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import os
|
|
60
|
+
from qubrics.langchain import QubricsToolkit
|
|
61
|
+
|
|
62
|
+
toolkit = QubricsToolkit(
|
|
63
|
+
access_token=lambda: os.environ["QUBRICS_ACCESS_TOKEN"],
|
|
64
|
+
default_from="agent@yourdomain.dev",
|
|
65
|
+
)
|
|
66
|
+
tools = toolkit.get_tools()
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The provider runs before every tool request. Your application owns protected token storage, expiry checks, and refresh coordination. Request `mailbox.read` and `email.send` to use all three tools, and select one mailbox at consent; these tools do not supply a mailbox selector. Credentials are excluded from the toolkit's representation and model serialisation. See [REST OAuth](https://qubrics.com/docs/developer-tools/oauth).
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import os
|
|
75
|
+
|
|
76
|
+
from langchain.agents import create_agent
|
|
77
|
+
|
|
78
|
+
from qubrics.langchain import QubricsToolkit
|
|
79
|
+
|
|
80
|
+
smx = QubricsToolkit(
|
|
81
|
+
api_key=os.environ["QUBRICS_API_KEY"],
|
|
82
|
+
default_from="agent@yourdomain.dev",
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
agent = create_agent(
|
|
86
|
+
model="gpt-4o",
|
|
87
|
+
tools=smx.get_tools(),
|
|
88
|
+
system_prompt="You triage the support inbox.",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
agent.invoke(
|
|
92
|
+
{"messages": [{"role": "user", "content": "Reply to anyone asking about pricing."}]}
|
|
93
|
+
)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Tools
|
|
97
|
+
|
|
98
|
+
`QubricsToolkit(...).get_tools()` returns three tools.
|
|
99
|
+
|
|
100
|
+
### `send_email`
|
|
101
|
+
|
|
102
|
+
Sends through your configured sending providers, to any recipient.
|
|
103
|
+
|
|
104
|
+
| Parameter | Type | Required | Notes |
|
|
105
|
+
| --- | --- | --- | --- |
|
|
106
|
+
| `to` | str | yes | Recipient email address |
|
|
107
|
+
| `subject` | str | yes | Subject line |
|
|
108
|
+
| `text` | str | yes | Plain-text body |
|
|
109
|
+
| `html` | str | no | HTML body. Generated from `text` if omitted |
|
|
110
|
+
| `var_from` | str | no | Sender address. Falls back to `default_from` |
|
|
111
|
+
| `idempotency_key` | str | no | Makes a retried send idempotent for 24 hours |
|
|
112
|
+
| `delivery_group` | str or list[str] | no | One delivery group ID, or a list of IDs, that narrows the eligible provider pool for this send. Omit to keep the default routing |
|
|
113
|
+
|
|
114
|
+
`var_from` is spelt that way because `from` is a reserved word in Python.
|
|
115
|
+
|
|
116
|
+
### `list_messages`
|
|
117
|
+
|
|
118
|
+
Lists messages in the agent's own mailbox, newest first.
|
|
119
|
+
|
|
120
|
+
| Parameter | Type | Required | Notes |
|
|
121
|
+
| --- | --- | --- | --- |
|
|
122
|
+
| `limit` | int | no | How many to return, 1 to 100. Defaults to 25 |
|
|
123
|
+
|
|
124
|
+
### `reply`
|
|
125
|
+
|
|
126
|
+
Sends from the agent's own mailbox address, rather than through a sending provider. Use this to answer someone who wrote in.
|
|
127
|
+
|
|
128
|
+
| Parameter | Type | Required | Notes |
|
|
129
|
+
| --- | --- | --- | --- |
|
|
130
|
+
| `to` | str | yes | Recipient email address |
|
|
131
|
+
| `subject` | str | yes | Subject line |
|
|
132
|
+
| `text` | str | yes | Plain-text body |
|
|
133
|
+
| `html` | str | no | HTML body. Generated from `text` if omitted |
|
|
134
|
+
| `idempotency_key` | str | no | Makes a retried send idempotent for 24 hours |
|
|
135
|
+
|
|
136
|
+
## Configuration
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
QubricsToolkit(api_key=..., default_from=...)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
| Option | Required | Purpose |
|
|
143
|
+
| --- | --- | --- |
|
|
144
|
+
| `api_key` | Required unless `access_token` is set | A send + receive mailbox key (`smx_mbx_*`) or a scoped agent token (`smx_agent_*`) |
|
|
145
|
+
| `access_token` | Required unless `api_key` is set | A bare REST OAuth token or callable returning the current token; supply exactly one credential option |
|
|
146
|
+
| `default_from` | no | Default sender for `send_email`. Without it, the model has to supply `var_from` on every call |
|
|
147
|
+
|
|
148
|
+
## Retries and duplicate sends
|
|
149
|
+
|
|
150
|
+
Agents retry. Pass `idempotency_key` on `send_email` and `reply` and Qubrics will send once, even if the same call arrives several times inside 24 hours. Any stable string works — a task id, a thread id, a hash of the message.
|
|
151
|
+
|
|
152
|
+
Details: [idempotency](https://qubrics.com/docs/guides/idempotency).
|
|
153
|
+
|
|
154
|
+
## Common errors
|
|
155
|
+
|
|
156
|
+
| What you see | Why | Fix |
|
|
157
|
+
| --- | --- | --- |
|
|
158
|
+
| `ValueError: No sender address` | No `var_from` on the call and no `default_from` set | Set `default_from`, or have the model pass `var_from` |
|
|
159
|
+
| Send rejected on an agent token | The token is self-registered and not yet owner-approved | Complete the owner invite and approval |
|
|
160
|
+
| Auth failure | Key lacks send or receive permission | Check the key's scope in the dashboard |
|
|
161
|
+
|
|
162
|
+
## Related
|
|
163
|
+
|
|
164
|
+
- [Quickstart](https://qubrics.com/docs/guides/quickstart)
|
|
165
|
+
- [Mailboxes](https://qubrics.com/docs/guides/mailboxes)
|
|
166
|
+
- [All Qubrics SDKs](https://qubrics.com/docs/sdks)
|
|
167
|
+
- [Pricing](https://qubrics.com/pricing/) — usage-based, no per-seat or per-mailbox fees
|
|
168
|
+
|
|
169
|
+
## Licence
|
|
170
|
+
|
|
171
|
+
MIT. See the [licence file](https://github.com/qubrics/qubrics-sdk/blob/main/LICENSE).
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# langchain-qubrics
|
|
2
|
+
|
|
3
|
+
[LangChain](https://docs.langchain.com) toolkit for [Qubrics](https://qubrics.com), the email API for AI agents.
|
|
4
|
+
|
|
5
|
+
Gives an agent its own mailbox: it can send email, read what arrives, and reply from its own address.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Python 3.10 or newer
|
|
10
|
+
- `langchain-core` v1
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
These commands target the Qubrics release of `langchain-qubrics`. Until it is published, install `langchain-sendmux` with its existing import names.
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
pip install langchain-qubrics
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Getting an API key
|
|
21
|
+
|
|
22
|
+
For API-key authentication, use a key that can both send and receive. Two ways to get one:
|
|
23
|
+
|
|
24
|
+
- **Dashboard** — create a mailbox and a mailbox-scoped key (`smx_mbx_*`). See [API keys](https://qubrics.com/docs/guides/api-keys).
|
|
25
|
+
- **Agent self-registration** — the agent claims its own `@myagent.mx` mailbox and gets an `smx_agent_*` token, with no human signup first. See [email for AI agents](https://qubrics.com/solutions/for-ai-agents/).
|
|
26
|
+
|
|
27
|
+
Note on agent tokens: a freshly self-registered `smx_agent_*` token can read and receive, but **cannot send** until a human owner has been invited and has approved it. Until then `send_email` and `reply` will fail. A dashboard `smx_mbx_*` key with send permission works immediately.
|
|
28
|
+
|
|
29
|
+
Read the key from the environment. Never hard-code it.
|
|
30
|
+
|
|
31
|
+
## OAuth access tokens
|
|
32
|
+
|
|
33
|
+
Set `access_token` to a bare REST OAuth token or callable instead of `api_key`:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import os
|
|
37
|
+
from qubrics.langchain import QubricsToolkit
|
|
38
|
+
|
|
39
|
+
toolkit = QubricsToolkit(
|
|
40
|
+
access_token=lambda: os.environ["QUBRICS_ACCESS_TOKEN"],
|
|
41
|
+
default_from="agent@yourdomain.dev",
|
|
42
|
+
)
|
|
43
|
+
tools = toolkit.get_tools()
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The provider runs before every tool request. Your application owns protected token storage, expiry checks, and refresh coordination. Request `mailbox.read` and `email.send` to use all three tools, and select one mailbox at consent; these tools do not supply a mailbox selector. Credentials are excluded from the toolkit's representation and model serialisation. See [REST OAuth](https://qubrics.com/docs/developer-tools/oauth).
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import os
|
|
52
|
+
|
|
53
|
+
from langchain.agents import create_agent
|
|
54
|
+
|
|
55
|
+
from qubrics.langchain import QubricsToolkit
|
|
56
|
+
|
|
57
|
+
smx = QubricsToolkit(
|
|
58
|
+
api_key=os.environ["QUBRICS_API_KEY"],
|
|
59
|
+
default_from="agent@yourdomain.dev",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
agent = create_agent(
|
|
63
|
+
model="gpt-4o",
|
|
64
|
+
tools=smx.get_tools(),
|
|
65
|
+
system_prompt="You triage the support inbox.",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
agent.invoke(
|
|
69
|
+
{"messages": [{"role": "user", "content": "Reply to anyone asking about pricing."}]}
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Tools
|
|
74
|
+
|
|
75
|
+
`QubricsToolkit(...).get_tools()` returns three tools.
|
|
76
|
+
|
|
77
|
+
### `send_email`
|
|
78
|
+
|
|
79
|
+
Sends through your configured sending providers, to any recipient.
|
|
80
|
+
|
|
81
|
+
| Parameter | Type | Required | Notes |
|
|
82
|
+
| --- | --- | --- | --- |
|
|
83
|
+
| `to` | str | yes | Recipient email address |
|
|
84
|
+
| `subject` | str | yes | Subject line |
|
|
85
|
+
| `text` | str | yes | Plain-text body |
|
|
86
|
+
| `html` | str | no | HTML body. Generated from `text` if omitted |
|
|
87
|
+
| `var_from` | str | no | Sender address. Falls back to `default_from` |
|
|
88
|
+
| `idempotency_key` | str | no | Makes a retried send idempotent for 24 hours |
|
|
89
|
+
| `delivery_group` | str or list[str] | no | One delivery group ID, or a list of IDs, that narrows the eligible provider pool for this send. Omit to keep the default routing |
|
|
90
|
+
|
|
91
|
+
`var_from` is spelt that way because `from` is a reserved word in Python.
|
|
92
|
+
|
|
93
|
+
### `list_messages`
|
|
94
|
+
|
|
95
|
+
Lists messages in the agent's own mailbox, newest first.
|
|
96
|
+
|
|
97
|
+
| Parameter | Type | Required | Notes |
|
|
98
|
+
| --- | --- | --- | --- |
|
|
99
|
+
| `limit` | int | no | How many to return, 1 to 100. Defaults to 25 |
|
|
100
|
+
|
|
101
|
+
### `reply`
|
|
102
|
+
|
|
103
|
+
Sends from the agent's own mailbox address, rather than through a sending provider. Use this to answer someone who wrote in.
|
|
104
|
+
|
|
105
|
+
| Parameter | Type | Required | Notes |
|
|
106
|
+
| --- | --- | --- | --- |
|
|
107
|
+
| `to` | str | yes | Recipient email address |
|
|
108
|
+
| `subject` | str | yes | Subject line |
|
|
109
|
+
| `text` | str | yes | Plain-text body |
|
|
110
|
+
| `html` | str | no | HTML body. Generated from `text` if omitted |
|
|
111
|
+
| `idempotency_key` | str | no | Makes a retried send idempotent for 24 hours |
|
|
112
|
+
|
|
113
|
+
## Configuration
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
QubricsToolkit(api_key=..., default_from=...)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
| Option | Required | Purpose |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| `api_key` | Required unless `access_token` is set | A send + receive mailbox key (`smx_mbx_*`) or a scoped agent token (`smx_agent_*`) |
|
|
122
|
+
| `access_token` | Required unless `api_key` is set | A bare REST OAuth token or callable returning the current token; supply exactly one credential option |
|
|
123
|
+
| `default_from` | no | Default sender for `send_email`. Without it, the model has to supply `var_from` on every call |
|
|
124
|
+
|
|
125
|
+
## Retries and duplicate sends
|
|
126
|
+
|
|
127
|
+
Agents retry. Pass `idempotency_key` on `send_email` and `reply` and Qubrics will send once, even if the same call arrives several times inside 24 hours. Any stable string works — a task id, a thread id, a hash of the message.
|
|
128
|
+
|
|
129
|
+
Details: [idempotency](https://qubrics.com/docs/guides/idempotency).
|
|
130
|
+
|
|
131
|
+
## Common errors
|
|
132
|
+
|
|
133
|
+
| What you see | Why | Fix |
|
|
134
|
+
| --- | --- | --- |
|
|
135
|
+
| `ValueError: No sender address` | No `var_from` on the call and no `default_from` set | Set `default_from`, or have the model pass `var_from` |
|
|
136
|
+
| Send rejected on an agent token | The token is self-registered and not yet owner-approved | Complete the owner invite and approval |
|
|
137
|
+
| Auth failure | Key lacks send or receive permission | Check the key's scope in the dashboard |
|
|
138
|
+
|
|
139
|
+
## Related
|
|
140
|
+
|
|
141
|
+
- [Quickstart](https://qubrics.com/docs/guides/quickstart)
|
|
142
|
+
- [Mailboxes](https://qubrics.com/docs/guides/mailboxes)
|
|
143
|
+
- [All Qubrics SDKs](https://qubrics.com/docs/sdks)
|
|
144
|
+
- [Pricing](https://qubrics.com/pricing/) — usage-based, no per-seat or per-mailbox fees
|
|
145
|
+
|
|
146
|
+
## Licence
|
|
147
|
+
|
|
148
|
+
MIT. See the [licence file](https://github.com/qubrics/qubrics-sdk/blob/main/LICENSE).
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "langchain-qubrics"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "LangChain toolkit for the Qubrics email API for AI agents."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = [
|
|
13
|
+
"sendmux",
|
|
14
|
+
"email",
|
|
15
|
+
"email-api",
|
|
16
|
+
"ai-agents",
|
|
17
|
+
"agent",
|
|
18
|
+
"agents",
|
|
19
|
+
"langchain",
|
|
20
|
+
"langchain-toolkit",
|
|
21
|
+
"tools",
|
|
22
|
+
"inbox",
|
|
23
|
+
"mailbox",
|
|
24
|
+
"send-email",
|
|
25
|
+
"transactional-email",
|
|
26
|
+
"llm",
|
|
27
|
+
]
|
|
28
|
+
classifiers = [
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
]
|
|
36
|
+
dependencies = [
|
|
37
|
+
"langchain-core>=1.0.0,<2",
|
|
38
|
+
"qubrics-sending>=2.0.0,<3.0.0",
|
|
39
|
+
"qubrics-mailbox>=3.0.0,<4.0.0",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://qubrics.com"
|
|
44
|
+
Documentation = "https://qubrics.com/docs/sdks"
|
|
45
|
+
Repository = "https://github.com/qubrics/qubrics-sdk"
|
|
46
|
+
Issues = "https://github.com/qubrics/qubrics-sdk/issues"
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.sdist]
|
|
49
|
+
core-metadata-version = "2.4"
|
|
50
|
+
include = [
|
|
51
|
+
"LICENSE",
|
|
52
|
+
"README.md",
|
|
53
|
+
"qubrics",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build.targets.wheel]
|
|
57
|
+
core-metadata-version = "2.4"
|
|
58
|
+
packages = ["qubrics"]
|
|
59
|
+
artifacts = ["qubrics/langchain/py.typed"]
|
|
File without changes
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""LangChain toolkit for the Qubrics email API for AI agents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Callable, Optional, Union
|
|
6
|
+
|
|
7
|
+
from langchain_core.tools import BaseTool, BaseToolkit, tool
|
|
8
|
+
from pydantic import Field
|
|
9
|
+
|
|
10
|
+
from qubrics.mailbox import MailboxAPIApi, create_mailbox_client
|
|
11
|
+
from qubrics.mailbox.models.send_mailbox_message_body import SendMailboxMessageBody
|
|
12
|
+
from qubrics.sending import EmailSendRequest, EmailsApi, create_sending_client
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _html_from_text(text: str) -> str:
|
|
16
|
+
escaped = (
|
|
17
|
+
text.replace("&", "&")
|
|
18
|
+
.replace("<", "<")
|
|
19
|
+
.replace(">", ">")
|
|
20
|
+
.replace("\n", "<br>")
|
|
21
|
+
)
|
|
22
|
+
return f"<p>{escaped}</p>"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class QubricsToolkit(BaseToolkit):
|
|
26
|
+
"""LangChain toolkit exposing Qubrics 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 qubrics.langchain import QubricsToolkit
|
|
34
|
+
>>> smx = QubricsToolkit(api_key="smx_mbx_...")
|
|
35
|
+
>>> agent = create_agent(model="gpt-4o", tools=smx.get_tools())
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
api_key: Optional[str] = Field(
|
|
39
|
+
default=None,
|
|
40
|
+
repr=False,
|
|
41
|
+
exclude=True,
|
|
42
|
+
description=(
|
|
43
|
+
"A send + receive capable mailbox API key (smx_mbx_*) or a scoped "
|
|
44
|
+
"agent token. Read it from your environment; never hard-code it."
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
access_token: str | Callable[[], str] | None = Field(
|
|
48
|
+
default=None,
|
|
49
|
+
repr=False,
|
|
50
|
+
exclude=True,
|
|
51
|
+
description=(
|
|
52
|
+
"A REST OAuth access token or a callable returning the current token. "
|
|
53
|
+
"Supply this instead of api_key."
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
default_from: Optional[str] = Field(
|
|
57
|
+
default=None,
|
|
58
|
+
description=(
|
|
59
|
+
"Default From address for send_email when a call omits `from`. "
|
|
60
|
+
"If unset, the model must supply a sender per call."
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
def get_tools(self) -> list[BaseTool]:
|
|
65
|
+
sending_client = create_sending_client(api_key=self.api_key, access_token=self.access_token)
|
|
66
|
+
mailbox_client = create_mailbox_client(api_key=self.api_key, access_token=self.access_token)
|
|
67
|
+
emails = EmailsApi(sending_client)
|
|
68
|
+
mailbox = MailboxAPIApi(mailbox_client)
|
|
69
|
+
default_from = self.default_from
|
|
70
|
+
|
|
71
|
+
@tool
|
|
72
|
+
def send_email(
|
|
73
|
+
to: str,
|
|
74
|
+
subject: str,
|
|
75
|
+
text: str,
|
|
76
|
+
html: Optional[str] = None,
|
|
77
|
+
var_from: Optional[str] = None,
|
|
78
|
+
idempotency_key: Optional[str] = None,
|
|
79
|
+
delivery_group: Optional[Union[str, list[str]]] = None,
|
|
80
|
+
) -> Any:
|
|
81
|
+
"""Send an email through Qubrics to any recipient.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
to: Recipient email address.
|
|
85
|
+
subject: Email subject line.
|
|
86
|
+
text: Plain-text body of the email.
|
|
87
|
+
html: Optional HTML body.
|
|
88
|
+
var_from: Sender email address; defaults to the configured sender.
|
|
89
|
+
idempotency_key: Optional key that makes a retried send idempotent
|
|
90
|
+
for 24 hours.
|
|
91
|
+
delivery_group: Optional delivery group ID or list of group IDs that
|
|
92
|
+
narrows the eligible provider pool.
|
|
93
|
+
"""
|
|
94
|
+
sender = var_from if var_from is not None else default_from
|
|
95
|
+
if sender is None:
|
|
96
|
+
raise ValueError(
|
|
97
|
+
"No sender address: pass `var_from` in the tool call, or set "
|
|
98
|
+
"default_from on QubricsToolkit."
|
|
99
|
+
)
|
|
100
|
+
if delivery_group is not None:
|
|
101
|
+
from qubrics.sending.models.email_send_request_delivery_group import (
|
|
102
|
+
EmailSendRequestDeliveryGroup,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
delivery_group_value = EmailSendRequestDeliveryGroup(delivery_group)
|
|
106
|
+
else:
|
|
107
|
+
delivery_group_value = None
|
|
108
|
+
# EmailSendRequest.var_from carries alias "from" (a Python keyword),
|
|
109
|
+
# so build from a dict via model_validate rather than keyword args.
|
|
110
|
+
request: dict[str, Any] = {
|
|
111
|
+
"from": {"email": sender},
|
|
112
|
+
"to": {"email": to},
|
|
113
|
+
"subject": subject,
|
|
114
|
+
"text_body": text,
|
|
115
|
+
"html_body": html if html is not None else _html_from_text(text),
|
|
116
|
+
}
|
|
117
|
+
if delivery_group_value is not None:
|
|
118
|
+
request["delivery_group"] = delivery_group_value
|
|
119
|
+
response = emails.sending_send_email(
|
|
120
|
+
EmailSendRequest.model_validate(request),
|
|
121
|
+
idempotency_key=idempotency_key,
|
|
122
|
+
)
|
|
123
|
+
return response.data
|
|
124
|
+
|
|
125
|
+
@tool
|
|
126
|
+
def list_messages(limit: int = 25) -> Any:
|
|
127
|
+
"""List recent messages in the agent's mailbox, newest first.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
limit: Maximum number of messages to return (1-100).
|
|
131
|
+
"""
|
|
132
|
+
response = mailbox.mailbox_list_messages(limit=limit)
|
|
133
|
+
return response.data
|
|
134
|
+
|
|
135
|
+
@tool
|
|
136
|
+
def reply(
|
|
137
|
+
to: str,
|
|
138
|
+
subject: str,
|
|
139
|
+
text: str,
|
|
140
|
+
html: Optional[str] = None,
|
|
141
|
+
idempotency_key: Optional[str] = None,
|
|
142
|
+
) -> Any:
|
|
143
|
+
"""Send a message from the agent's own mailbox, e.g. to reply to a sender.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
to: Recipient email address.
|
|
147
|
+
subject: Subject line.
|
|
148
|
+
text: Plain-text body.
|
|
149
|
+
html: Optional HTML body.
|
|
150
|
+
idempotency_key: Optional key that makes a retried send idempotent
|
|
151
|
+
for 24 hours.
|
|
152
|
+
"""
|
|
153
|
+
response = mailbox.mailbox_send_message(
|
|
154
|
+
idempotency_key=idempotency_key,
|
|
155
|
+
send_mailbox_message_body=SendMailboxMessageBody.model_validate(
|
|
156
|
+
{
|
|
157
|
+
"to": [{"email": to, "name": None}],
|
|
158
|
+
"subject": subject,
|
|
159
|
+
"text_body": text,
|
|
160
|
+
"html_body": (
|
|
161
|
+
html if html is not None else _html_from_text(text)
|
|
162
|
+
),
|
|
163
|
+
}
|
|
164
|
+
),
|
|
165
|
+
)
|
|
166
|
+
return response.data
|
|
167
|
+
|
|
168
|
+
return [send_email, list_messages, reply]
|