Skip to content

Commit a35a7a4

Browse files
Merge pull request #7 from indeedeng/ai-agent
Build ai agent using iWF
2 parents a4ef197 + 03cb26d commit a35a7a4

17 files changed

+3593
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
ai-agent-email/node_modules/*
12
### Python template
23

34
.DS_Store

ai-agent-email/README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Table of Contents
2+
3+
1. [What it is](#what-it-is)
4+
2. [How to Run](#how-to-run)
5+
2.1. [Prerequisites](#prerequisites)
6+
2.2. [Environment Variables](#environment-variables)
7+
2.3. [Backend Setup](#backend-setup)
8+
2.4. [Frontend Setup](#frontend-setup)
9+
2.5. [Run the Application](#run-the-application)
10+
3. [Using the Application](#using-the-application)
11+
12+
## What it is
13+
14+
The AI Agent Email is a feature-rich application that leverages AI to streamline email composition
15+
and management. It combines a React frontend with a Flask backend powered by iWF (Indeed Workflow Framework) to
16+
provide a durable, scalable email assistant.
17+
18+
### Why iWF?
19+
20+
iWF (Indeed Workflow Framework) was chosen for this application due to its ability to provide extreme **simplicity** in
21+
software design and implementation. By leveraging iWF, developers can focus on building business logic without worrying
22+
about the complexities of distributed systems, state management, or scalability.
23+
24+
For more details on building reliable AI agents with iWF on Temporal, check out the following
25+
article: [Build Reliable AI Agents with iWF on Temporal](https://medium.com/@qlong/build-reliable-ai-agents-with-iwf-on-temporal-7f1a101e000b)
26+
27+
### Functional Features
28+
29+
- **AI-Powered Email Composition**: Generate professionally written emails based on simple user requests and inputs
30+
- **Email Translation**: Translate emails into different languages upon request
31+
- **Smart Scheduling**: Schedule emails to be sent at specific times, supporting both absolute and relative time
32+
expressions (e.g., "tomorrow", "in 2 hours")
33+
- **Auto-Save Draft**: Automatically saves draft inputs every 5 seconds to prevent work loss
34+
- **Cancel Operation**: Ability to cancel scheduled emails before they're sent
35+
36+
### Technical Features
37+
38+
- **Workflow Checkpointing**: Uses iWF to maintain workflow state, enabling resumption from previous points after any
39+
instance restart
40+
- **Scalable Architecture**: Capable of handling **billions** of concurrent workflows
41+
- **Durable Timers**: Schedule-based operations use server-side durable timers that persist across system restarts
42+
- **Server-Side Backoff Retry**: Built-in retry mechanism orchestrated on the server side as distributed system, not
43+
dependent on a single machine.
44+
- **Stateful API Integration**: Seamless integration with OpenAI's GPT models with context retention
45+
- **Durable Drafting System**: Preserves user input across page refreshes and browser sessions
46+
47+
### Demo Videos
48+
49+
#### AI Agent Email Demo(happy case)
50+
51+
[![AI Agent Email Demo](https://img.youtube.com/vi/2dvIetECHWg/0.jpg)](https://www.youtube.com/watch?v=2dvIetECHWg "AI Agent Email Demo")
52+
53+
#### iWF Framework Overview(cancel a scheduled email)
54+
55+
[![iWF Framework Overview](https://img.youtube.com/vi/EEHSLYkbREU/0.jpg)](https://www.youtube.com/watch?v=EEHSLYkbREU "iWF Framework Overview")
56+
57+
## How to Run
58+
59+
### Prerequisites
60+
61+
Make sure you have the following installed and set up:
62+
63+
1. Run iWF server
64+
* The simplest way is to run
65+
`docker pull iworkflowio/iwf-server-lite:latest && docker run -p 8801:8801 -p 7233:7233 -p 8233:8233 -e AUTO_FIX_WORKER_URL=host.docker.internal --add-host host.docker.internal:host-gateway -it iworkflowio/iwf-server-lite:latest`
66+
* Or check out [iWF documentation](https://github.com/indeedeng/iwf?tab=readme-ov-file#how-to-use)
67+
2. [Python 3.13.2](https://www.python.org/downloads/)
68+
2. [Poetry](https://python-poetry.org/docs/) for dependency management and virtual environments.
69+
3. [Node.js and npm](https://nodejs.org/) for building the frontend.
70+
4. All required environment variables.
71+
72+
### Environment Variables
73+
74+
Before running the script, ensure the following environment variables are properly configured in your system:
75+
76+
- `OPENAI_API_KEY`: Your OpenAI API key.
77+
- `GOOGLE_EMAIL_ADDRESS`: The email address you'll use for sending emails. E.g. [email protected]
78+
- `GOOGLE_EMAIL_APP_PASSWORD`: The application password for your Google account. You can go
79+
to [Google app password](security.google.com/settings/security/apppasswords) to create a password for your account.
80+
81+
You can set these variables in your shell profile file (e.g., `.bashrc`, `.zshrc`, etc.) or export them before running
82+
the script:
83+
84+
```bash
85+
export OPENAI_API_KEY="your-openai-api-key"
86+
export GOOGLE_EMAIL_ADDRESS="your-email-address"
87+
export GOOGLE_EMAIL_APP_PASSWORD="your-app-password"
88+
```
89+
90+
### Backend Setup
91+
92+
Once Poetry is installed, navigate to the project directory and install the required dependencies by running:
93+
94+
```bash
95+
poetry install
96+
```
97+
98+
This will create a virtual environment and install all necessary packages listed in the `pyproject.toml` file.
99+
100+
### Frontend Setup
101+
102+
To set up the React TypeScript frontend:
103+
104+
1. Install the required npm packages:
105+
106+
```bash
107+
cd ai-agent-email
108+
npm install
109+
```
110+
111+
2. Build the frontend:
112+
113+
```bash
114+
npm run build
115+
```
116+
117+
For development, you can use the watch mode:
118+
119+
```bash
120+
npm start
121+
```
122+
123+
### Run the Application
124+
125+
To start the application, execute the following command:
126+
127+
```bash
128+
poetry run python ai-agent-email/main.py
129+
```
130+
131+
This will launch the Flask application at http://localhost:8802. Open your browser and navigate to this URL to access
132+
the AI Agent Email interface.
133+
134+
## Using the Application
135+
136+
1. When you first open the application, you'll see a text box and a "Talk to Agent" button.
137+
2. Enter your request in the text box (e.g., "Help me write an email to thank John for his help on the project").
138+
3. Click the "Talk to Agent" button to send your request to the AI agent.
139+
4. The agent will process your request and provide a response that will be displayed on the page.

0 commit comments

Comments
 (0)