Gmail Formatting
Case Study: Email Formatting
Installation
uv init --bare
uv add glaip-sdk[local] gllm-tools-binarySource Code
import asyncio
import os
from glaip_sdk import Agent
from gllm_tools.mcp.client.langchain import LangchainMCPClient
DESIRED_TOOLS = {"google_mail_send_email"}
client = LangchainMCPClient({
"google_mail": {
"url": "https://connector.gdplabs.id/google_mail/mcp",
"headers": {"Authorization": f"Bearer {os.getenv('GL_CONNECTORS_USER_TOKEN')}"},
}
})
EMAIL_FORMAT = """
THIS IS A TEST EMAIL. PLEASE IGNORE.
<div style="font-family: Helvetica, Arial, sans-serif; max-width: 600px; margin: 0 auto; color: #333;">
<h2 style="border-bottom: 2px solid #0066cc; padding-bottom: 10px;">📅 Today's Schedule</h2>
<!-- REPEAT FOR EACH MEETING -->
<div style="padding: 15px 0; border-bottom: 1px solid #eee;">
<div style="font-size: 14px; font-weight: bold; color: #0066cc; margin-bottom: 4px;">
[START_TIME] - [END_TIME]
</div>
<div style="font-size: 18px; font-weight: bold; margin-bottom: 4px;">
[MEETING_TITLE]
</div>
<div style="font-size: 14px; color: #666;">
📍 [LOCATION_OR_LINK] <br>
📝 [DESCRIPTION]
</div>
</div>
<!-- END REPEAT -->
<p style="margin-top: 20px; font-size: 14px; color: #888;">
Have a productive day!
</p>
</div>
"""
def extract_content(chunk) -> str | None:
if isinstance(chunk, str):
return chunk
if isinstance(chunk, dict):
return chunk.get("content")
return getattr(chunk, "content", None)
async def main():
all_tools = await client.get_tools("google_mail")
tools = [t for t in all_tools if t.name in DESIRED_TOOLS]
agent = Agent(
name="gmail_agent",
instruction="You are a helpful assistant.",
tools=tools,
model="gpt-4.1",
)
prompt = (
"Send an email to myself about my schedule for today. "
"Use the following HTML format for the body, filling in the blanks "
f"with the schedule (make it up if needed): {EMAIL_FORMAT}"
)
async for chunk in agent.arun(prompt):
if content := extract_content(chunk):
print(content)
asyncio.run(main())How It Works
Prerequisites
Last updated
Was this helpful?