AI agents are revolutionizing the way we interact with technology, automating complex workflows, and making everyday tasks more manageable. If you’ve ever wanted to build a smart system that can understand natural language and perform actions based on user input, this guide is for you.
In this article, we’ll walk through how to create an AI-powered reminder system using tools like ReActAgent
from llama_index
, Azure OpenAI, and Python libraries. This system allows users to create reminders through natural language commands and sends desktop notifications for scheduled tasks in real time.
ReActAgent
to process user inputs and execute actions.Before you start, ensure you have the following:
llama_index
, notifypy
, and threading
.The first step is to configure Azure OpenAI as the engine behind your AI agent. This model processes user queries and generates meaningful responses. In our case, we are using a deployment of the gpt4o
model.
from llama_index.llms.azure_openai import AzureOpenAI
import os
llm = AzureOpenAI(
model="gpt-4o",
deployment_name="gpt-4o",
api_key=os.environ["AZURE_OPENAI_API_KEY"],
engine="gpt-4o",
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
api_version="2024-10-01-preview",
)
Make sure to export your environment variables accordingly:
export AZURE_OPENAI_API_KEY=<your-azure-open-ai-deployment-key>
export AZURE_OPENAI_ENDPOINT=<your-azure-open-ai-deployment-endpoint>
Define a function to handle reminders. This function accepts a task name and a scheduled date, storing them in a list.
from datetime import datetime
reminders = []
def add_reminder(task_name: str, date: datetime):
"""Add a reminder with a task name and scheduled date."""
reminders.append({"task_name": task_name, "date": date})
return {"task_name": task_name, "date": date}
This function serves as a building block for storing and retrieving reminder data.
ReActAgent
The ReActAgent
is the core AI agent that processes user inputs and calls the add_reminder
function when needed. Using FunctionTool
, you can bind the reminder function to the agent.
from llama_index.core.agent import ReActAgent
from llama_index.core.tools import FunctionTool
remind_tool = FunctionTool.from_defaults(fn=add_reminder)
agent = ReActAgent.from_tools(
[remind_tool],
llm=llm,
verbose=True,
)
This setup allows the agent to interpret commands in natural languages (e.g., "Set a reminder to call John at 5 PM") and execute the appropriate function.
Using the notifypy
library, build a notification system to alert users when reminders are due. A background thread constantly checks for reminders and sends notifications.
from notifypy import Notify
import time
import threading
def notify_reminders():
while True:
for reminder in reminders:
if reminder["date"] <= datetime.now():
notification = Notify()
notification.title = "Reminder!"
notification.message = reminder["task_name"]
notification.send()
reminders.remove(reminder)
time.sleep(1)
notification_thread = threading.Thread(target=notify_reminders, daemon=True)
notification_thread.start()
This thread runs continuously in the background, ensuring timely notifications.
Finally, create a simple interface for interacting with the AI agent. Users can type commands to set reminders or exit the system.
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
print("Goodbye!")
break
response = agent.chat(user_input)
print(f"Agent: {response}")
The agent processes the user’s input, determines the intent, and executes the appropriate action, such as adding a reminder.
Here are some ideas to improve this system:
By combining the power of ReActAgent
, Azure OpenAI, and Python libraries, you can build an intelligent and fully functional reminder system. This tutorial demonstrates how AI agents can be used to solve practical problems and automate routine tasks efficiently.
Want to learn more about how AI agents can transform your workflows? Explore our AI solutions and consulting services.