Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 08:30 UTC
docs: use session tool discovery in Gmail attachment FAQ
Brendan O'Leary committed
Oct 20, 2026 at 21:16 UTC
e8db8de1e617fddf08a10b2cea5e03a81e030a47
1 file changed
+33
-11
docs/content/toolkits/faq/gmail.md
+33
-11
@@ -34,22 +34,44 @@ Google enforces per-minute and daily request quotas. If you're using Composio's
34
35
## How do I send an email with an attachment?
36
37
-When using the Composio SDK, pass a local file path or a public URL directly as a string to the `attachment` field. The SDK's auto-upload feature (enabled by default) handles uploading the file and converting it to the required format. You do not need to construct the `{ s3key, name, mimetype }` object manually.
37
+Use a [session](/docs/quickstart) so your agent discovers the email tool at runtime instead of hard-coding an action slug. Upload the attachment to the session's sandbox, then pass its sandbox path in the request.
38
+
39
+Install `composio`, `composio-openai-agents`, and `openai-agents`, and set `COMPOSIO_API_KEY` and `OPENAI_API_KEY`. [Connect Gmail for your user](/docs/authentication/manually-authenticating), and replace `./report.pdf` and the recipient below with your own values.
40
41
```python
40
-result = composio.tools.execute(
41
- slug="GMAIL_SEND_EMAIL",
42
- user_id="user-123",
43
- arguments={
44
- "recipient_email": "recipient@example.com",
45
- "subject": "Report attached",
46
- "body": "See attached.",
47
- "attachment": "https://example.com/report.pdf",
48
- },
42
+from agents import Agent, Runner
43
+from composio import Composio
44
+from composio_openai_agents import OpenAIAgentsProvider
45
+
46
+composio = Composio(provider=OpenAIAgentsProvider())
47
+session = composio.create(user_id="user-123", toolkits=["gmail"])
48
+
49
+uploaded = session.experimental.files.upload("./report.pdf")
50
+attachment_path = (
51
+ f"{uploaded.sandbox_mount_prefix.rstrip('/')}/"
52
+ f"{uploaded.mount_relative_path.lstrip('/')}"
53
+)
54
+
55
+agent = Agent(
56
+ name="Email assistant",
57
+ instructions=(
58
+ "Discover the appropriate tools to send the requested email. "
59
+ "Use the remote sandbox's get_mount_file_s3_key helper to get the "
60
+ "attachment's storage key. Pass it to the email tool in a file object "
61
+ "with name, mimetype, and s3key, not as a sandbox path. "
62
+ "If a tool fails, report the error instead of claiming the email was sent."
63
+ ),
64
+ tools=session.tools(),
65
+)
66
+result = Runner.run_sync(
67
+ agent,
68
+ "Send an email to recipient@example.com with subject 'Report attached' "
69
+ f"and body 'See attached.', attaching {attachment_path}.",
70
)
71
+print(result.final_output)
72
```
73
52
-This approach works for any tool whose parameters accept file uploads. See [Automatic File Handling](/docs/tools-direct/executing-tools#automatic-file-handling) for more details.
74
+The agent can read the uploaded file in the remote sandbox, not from your application's local filesystem. This uses an explicit upload and does not require automatic file handling. The files API is experimental. See [sandbox files and mounts](/docs/sandbox/remote#files-and-mounts) for upload options and limits.
75
76
## Why can Gmail filter setup show an app-blocked error?
77