✓ Verified 💻 Development ✓ Enhanced Data

Langchain Email Agent

The `EmailAgent` class provides an AI-powered email composition and sending capability using LangCha

Rating
4.6 (289 reviews)
Downloads
518 downloads
Version
1.0.0

Overview

The `EmailAgent` class provides an AI-powered email composition and sending capability using LangChain.

Complete Documentation

View Source →

EmailAgent README

Overview

The EmailAgent class provides an AI-powered email composition and sending capability using LangChain with OpenAI's GPT model. It includes human-in-the-loop middleware that requires approval before emails are sent.

Configuration

Environment Variables

VariableDefaultDescription
OPENAI_MODELgpt-4o-miniOpenAI model to use

Usage

typescript
import { EmailAgent } from './email.agent';
import { SendEmailDto } from '../dto/send-email.dto';

const agent = new EmailAgent();

const dto: SendEmailDto = {
  email: '[email protected]',
  name: 'John Doe',
  subject: 'Meeting Request',      // optional
  body: 'Initial email content',   // optional
  instructions: 'Keep it formal'   // optional
};

const result = await agent.sendEmail(dto);

Human-in-the-Loop Middleware

The agent uses humanInTheLoopMiddleware which interrupts execution on the EmailTool before sending emails. This allows for:

  • approve - Send the email as composed
  • edit - Modify the email before sending
  • reject - Cancel the email operation
The readEmailTool is excluded from interruption (false), allowing read operations to proceed without approval.

Parameters

ParameterTypeRequiredDescription
emailstringYesRecipient email address
namestringYesRecipient name
subjectstringNoEmail subject line
bodystringNoInitial email body content
instructionsstringNoAI instructions for composing the email

Return Value

Returns the final message content from the agent as a string.

Installation

Terminal bash

openclaw install langchain-email-agent
    
Copied!

💻Code Examples

example.ts
import { EmailAgent } from './email.agent';
import { SendEmailDto } from '../dto/send-email.dto';

const agent = new EmailAgent();

const dto: SendEmailDto = {
  email: '[email protected]',
  name: 'John Doe',
  subject: 'Meeting Request',      // optional
  body: 'Initial email content',   // optional
  instructions: 'Keep it formal'   // optional
};

const result = await agent.sendEmail(dto);

Tags

#coding_agents-and-ides

Quick Info

Category Development
Model Claude 3.5
Complexity Multi-Agent
Author jawadsadiq01
Last Updated 3/10/2026
🚀
Optimized for
Claude 3.5
🧠

Ready to Install?

Get started with this skill in seconds

openclaw install langchain-email-agent