- OpenAI Agents SDK
- OpenAI Agents Sales Email
Let’s now follow along with Ed Donner and do a fairly common AI Agents project. We’ll ask agents to write sales emails.
Building a Sales Development Agent with the OpenAI Agents SDK
In this lesson from Ed Donner’s Udemy course, we dive into building our first practical project with the OpenAI Agents SDK — a simulated sales development representative (SDR). The goal is to explore three key layers of agentic architecture by moving step by step from simple workflows to multi-agent collaboration, using both tools and handoffs.
Three Layers of Agentic Architecture
Donner outlines a structured progression:
- 1. Basic Workflow: Start with simple agent calls, orchestrated manually within Python code.
- 2. Agents with Tools: Add functionality so an agent can call external tools — for example, sending emails.
- 3. Agents Calling Agents: Introduce collaboration, where one agent can delegate to another either by treating agents as tools or by using handoffs, a concept built into the Agents SDK. Keep this construct in mind.
This layered approach builds intuition for how autonomous systems can evolve from simple logic to coordinated, multi-agent ecosystems.
Using SendGrid as a Tool
Before diving into the code, Donner sets up a third-party tool: SendGrid, a service for sending transactional emails (owned by Twilio). It’s free to use and integrates easily with the project.
- Create a free SendGrid account and verify your sender email under Sender Authentication.
- Generate an API key in the API Keys section and copy it to your clipboard.
- Add it to your project’s
.envfile asSENDGRID_API_KEY=your_key_here.
Although the example only sends emails back to yourself for testing, the setup mirrors what a real-world agent might do — automating personalized outreach safely and securely.
Defining the Agents
The project simulates three sales agents for a fictional company called Comply.ai, which helps businesses achieve SOC 2 compliance. Each agent represents a different personality or communication tone, illustrating how prompts define agent behavior.
- Agent 1: Professional and serious — writes polished, corporate-style outreach emails.
- Agent 2: Humorous and engaging — uses wit to encourage responses.
- Agent 3: Busy and concise — keeps messages short and to the point.
Each agent’s “instructions” effectively act as system prompts, defining its persona and tone. The project uses the gpt-4-mini model throughout to keep performance high and costs low.
Running an Agent Workflow
Once the agents are defined, Donner demonstrates a simple workflow using the streaming API. Instead of waiting for a full response, the agent streams its output token by token, allowing for more responsive interaction — a key part of modern LLM application design.
Using runner.run_streamed(), the Python script receives and displays partial results as they’re generated. The asynchronous async for loop processes each chunk, printing it in real time. This mirrors the “live typing” experience familiar from OpenAI’s playground or ChatGPT interface.
Observations and Takeaways
The resulting output is a clean, professional outreach email promoting Comply.ai’s SOC 2 compliance solutions. As Donner notes, LLMs are remarkably effective at producing realistic, well-structured sales copy — an ideal use case for AI-assisted communication tasks.
- Streaming APIs create smoother, more interactive workflows.
- Prompt design directly controls tone, clarity, and brand consistency.
- Agents SDK simplifies coordination between multiple specialized agents.
Final Thoughts
This exercise marks the transition from theoretical agent design to practical, tool-enabled implementation. By combining the OpenAI Agents SDK with services like SendGrid, you can begin constructing realistic, multi-agent systems that mirror professional workflows — in this case, an intelligent, automated sales development representative capable of generating, personalizing, and even sending outreach emails.
It’s a hands-on introduction to building agentic systems that think, act, and collaborate — one small but powerful step toward the future of AI-driven automation.
The Code
Below is come Visual Studio code that can serve as an exmple of how to do this project. Don’t forget to select your kernel.
from dotenv import load_dotenv from agents import Agent, Runner, trace, function_tool from openai.types.responses import ResponseTextDeltaEvent from typing import Dict import sendgrid import os from sendgrid.helpers.mail import Mail, Email, To, Content import asyncio
load_dotenv(override=True)
Don’t forget to change the two emails below to your verified sender and a recipient.
# Let's just check emails are working for you
def send_test_email():
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("bob@gmail.com") # Change to your verified sender
to_email = To("mike@gmail.com") # Change to your recipient
content = Content("text/plain", "This is an important test email")
mail = Mail(from_email, to_email, "Test email", content).get()
response = sg.client.mail.send.post(request_body=mail)
print(response.status_code)
send_test_email()
Did You Get a Test Email?
If you did not get the test then Ed’s course has some things to try to get that working. Have a look on Udemy to find the course and sign up, as I did. Udemy, as you probably already know, has periodic sales where the prices are very reasonable.