Skip to content

Commit a503287

Browse files
authored
Merge pull request #348 from Haakam21/agentmail-tool
Add AgentMail tool
2 parents 437db17 + e9dd89a commit a503287

File tree

4 files changed

+242
-0
lines changed

4 files changed

+242
-0
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
from agentmail import AgentMail
2+
from typing import Optional, List
3+
4+
5+
client = AgentMail()
6+
7+
8+
def list_inboxes(limit: Optional[int] = None, last_key: Optional[str] = None):
9+
"""
10+
List inboxes.
11+
12+
Args:
13+
limit: The maximum number of inboxes to return.
14+
last_key: The last key returned from the previous page.
15+
16+
Returns:
17+
A list of inboxes.
18+
"""
19+
return client.inboxes.list(limit=limit, last_key=last_key)
20+
21+
22+
def get_inbox(inbox_id: str):
23+
"""
24+
Get an inbox by ID.
25+
26+
Args:
27+
inbox_id: The ID of the inbox to get.
28+
29+
Returns:
30+
An inbox.
31+
"""
32+
return client.inboxes.get(inbox_id)
33+
34+
35+
def create_inbox(
36+
username: Optional[str] = None,
37+
domain: Optional[str] = None,
38+
display_name: Optional[str] = None,
39+
):
40+
"""
41+
Create an inbox.
42+
43+
Args:
44+
username: The username of the inbox.
45+
domain: The domain of the inbox.
46+
display_name: The display name of the inbox.
47+
48+
Returns:
49+
An inbox.
50+
"""
51+
return client.inboxes.create(
52+
username=username, domain=domain, display_name=display_name
53+
)
54+
55+
56+
def list_threads(
57+
inbox_id: str, limit: Optional[int] = None, last_key: Optional[str] = None
58+
):
59+
"""
60+
List threads in an inbox.
61+
62+
Args:
63+
inbox_id: The ID of the inbox to list threads for.
64+
limit: The maximum number of threads to return.
65+
last_key: The last key returned from the previous page.
66+
67+
Returns:
68+
A list of threads.
69+
"""
70+
return client.threads.list(inbox_id=inbox_id, limit=limit, last_key=last_key)
71+
72+
73+
def get_thread(inbox_id: str, thread_id: str):
74+
"""
75+
Get a thread by ID.
76+
77+
Args:
78+
inbox_id: The ID of the inbox to get the thread for.
79+
thread_id: The ID of the thread to get.
80+
81+
Returns:
82+
A thread.
83+
"""
84+
return client.threads.get(inbox_id=inbox_id, thread_id=thread_id)
85+
86+
87+
def list_messages(
88+
inbox_id: str, limit: Optional[int] = None, last_key: Optional[str] = None
89+
):
90+
"""
91+
List messages in an inbox.
92+
93+
Args:
94+
inbox_id: The ID of the inbox to list messages for.
95+
limit: The maximum number of messages to return.
96+
last_key: The last key returned from the previous page.
97+
98+
Returns:
99+
A list of messages.
100+
"""
101+
return client.messages.list(inbox_id=inbox_id, limit=limit, last_key=last_key)
102+
103+
104+
def get_message(inbox_id: str, message_id: str):
105+
"""
106+
Get a message by ID.
107+
108+
Args:
109+
inbox_id: The ID of the inbox to get the message for.
110+
message_id: The ID of the message to get.
111+
112+
Returns:
113+
A message.
114+
"""
115+
return client.messages.get(inbox_id=inbox_id, message_id=message_id)
116+
117+
118+
def get_attachment(inbox_id: str, message_id: str, attachment_id: str):
119+
"""
120+
Get an attachment by message ID and attachment ID.
121+
122+
Args:
123+
inbox_id: The ID of the inbox to get the attachment for.
124+
message_id: The ID of the message to get the attachment for.
125+
attachment_id: The ID of the attachment to get.
126+
127+
Returns:
128+
An attachment.
129+
"""
130+
return client.messages.get_attachment(
131+
inbox_id=inbox_id, message_id=message_id, attachment_id=attachment_id
132+
)
133+
134+
135+
def send_message(
136+
inbox_id: str,
137+
to: List[str],
138+
cc: Optional[List[str]] = None,
139+
bcc: Optional[List[str]] = None,
140+
subject: Optional[str] = None,
141+
text: Optional[str] = None,
142+
html: Optional[str] = None,
143+
):
144+
"""
145+
Send a message.
146+
147+
Args:
148+
inbox_id: The ID of the inbox to send the message from.
149+
to: The list of recipients.
150+
cc: The list of CC recipients.
151+
bcc: The list of BCC recipients.
152+
subject: The subject of the message.
153+
text: The plain text body of the message.
154+
html: The HTML body of the message.
155+
156+
Returns:
157+
A message.
158+
"""
159+
return client.messages.send(
160+
inbox_id=inbox_id, to=to, cc=cc, bcc=bcc, subject=subject, text=text, html=html
161+
)
162+
163+
164+
def reply_to_message(
165+
inbox_id: str,
166+
message_id: str,
167+
text: Optional[str] = None,
168+
html: Optional[str] = None,
169+
):
170+
"""
171+
Reply to a message.
172+
173+
Args:
174+
inbox_id: The ID of the inbox to reply to the message in.
175+
message_id: The ID of the message to reply to.
176+
text: The plain text body of the reply.
177+
html: The HTML body of the reply.
178+
179+
Returns:
180+
A message.
181+
"""
182+
return client.messages.reply(
183+
inbox_id=inbox_id, message_id=message_id, text=text, html=html
184+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "agentmail",
3+
"category": "email",
4+
"tools": ["list_inboxes", "get_inbox", "create_inbox", "list_threads", "get_thread", "list_messages", "get_message", "get_attachment", "send_message", "reply_to_message"],
5+
"url": "https://agentmail.to",
6+
"cta": "Get your AgentMail API key at https://agentmail.to",
7+
"env": {
8+
"AGENTMAIL_API_KEY": null
9+
},
10+
"dependencies": [
11+
"agentmail>=0.0.19"
12+
]
13+
}

docs/tools/community.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ title: 'Community Tools'
33
description: 'AgentStack tools from community contributors'
44
---
55

6+
## Email
7+
- [AgentMail](/tools/tool/agentmail)
8+
69
## Web Retrieval
710
- [AgentQL](/tools/tool/agentql)
811

docs/tools/tool/agentmail.mdx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: AgentMail
3+
description: Email for agents
4+
icon: email
5+
---
6+
7+
[AgentMail](https://agentmail.to) is an API-first email provider designed to give agents their own inboxes for sending, receiving, and managing email.
8+
9+
## Tools
10+
11+
- List inboxes
12+
- Get inbox
13+
- Create inbox
14+
- List threads
15+
- Get thread
16+
- List messages
17+
- Get message
18+
- Get attachment
19+
- Send message
20+
- Reply to message
21+
22+
## Installation
23+
24+
Add the AgentMail tool to your project
25+
26+
```sh
27+
agentstack tools add agentmail
28+
```
29+
30+
Get your [AgentMail API key](https://agentmail.to) and set the environment variable
31+
32+
```env
33+
AGENTMAIL_API_KEY=your-agentmail-api-key
34+
```
35+
36+
## Usage
37+
38+
Use the AgentMail API to create an inbox for your agent. Then prompt your agent to handle any email related tasks.
39+
40+
## Examples
41+
42+
Coming soon...

0 commit comments

Comments
 (0)