Notebooks
T
Together
Agents Composio

Using Together AI with Composio to Send Emails

Open In Colab

This notebook demonstrates how to integrate Together AI's language models with Composio's tools to create an AI agent that can send emails. We'll show:

  1. Setting up the required packages and authentication
  2. Configuring the email tool with Composio
  3. Creating a basic email-sending agent
  4. Adding preprocessing to customize email behavior
  5. Executing and handling the email responses

Let's see how we can combine these powerful tools to automate email communication!

Prerequisites

[4]

Gmail Configuration

We need to connect our Gmail account to Composio. This will open a browser window for authentication.

[ ]

Basic Email Tool Call

Here we create a simple integration between Together AI's LLM and Composio's Gmail tool:

  1. Initialize Together AI client
  2. Create Composio toolset
  3. Configure email sending capability
  4. Make an LLM call with the email tool to see if everything is working
[1]
/opt/anaconda3/envs/cookbook/lib/python3.12/site-packages/composio/tools/toolset.py:543: UserWarning: Not verifying connected accounts for apps. Actions may fail when the Agent tries to use them.
  warnings.warn(
{'id': 'nnSQh4S-4yUbBN-925f455aa84c36d8',
, 'object': <ObjectType.ChatCompletion: 'chat.completion'>,
, 'created': 1742914753,
, 'model': 'Qwen/Qwen3-235B-A22B-Instruct-2507-tput',
, 'choices': [{'index': 0,
,   'logprobs': None,
,   'seed': 15668879311493286000,
,   'finish_reason': <FinishReason.ToolCalls: 'tool_calls'>,
,   'message': {'role': <MessageRole.ASSISTANT: 'assistant'>,
,    'content': None,
,    'tool_calls': [{'id': 'call_4rx0ntnagtqyrwml4fwvmhz9',
,      'type': 'function',
,      'function': {'name': 'GMAIL_SEND_EMAIL',
,       'arguments': '{"user_id":"me","recipient_email":"john@mlteam.com","subject":"Meeting Request: Review Upcoming Launch","body":"Hi John,\\n\\nI hope this message finds you well. Could you please let me know a good time for us to meet next week to review the upcoming launch? Your availability is much appreciated.\\n\\nBest regards,\\nAlex","is_html":false}'},
,      'index': 0}]}}],
, 'prompt': [],
, 'usage': {'prompt_tokens': 535,
,  'completion_tokens': 104,
,  'total_tokens': 639}}

Modify Gmail tool schema

We can customize the email behavior using preprocessors and schema processors:

  • Preprocessor: Modifies the input before sending (e.g., changing recipient email)
  • Schema Processor: Modifies the tool schema (e.g., removing fields from LLM's view)
[2]

Executing the Email Send

Now we'll execute the email send with our processed tool and handle the response

[3]
[4]
[{'data': {'response_data': {'id': '195cdd11b381f385',
,    'threadId': '195cdd11b381f385',
,    'labelIds': ['UNREAD', 'SENT', 'INBOX']}},
,  'error': None,
,  'successfull': True,
,  'successful': True}]