Member-only story

Creating a basic Agentic AI assistant in 5 minutes using ChatGPT’s API

Imran Khan
2 min readJan 24, 2025

--

Here’s a simplified guide to creating a basic Agentic AI assistant in 5 minutes using ChatGPT’s API (e.g., GPT-4) and your custom functions. This agent will use natural language to decide which tools/functions to call based on user input:

Photo by Mike Hindle on Unsplash

Step 1: Install Dependencies

pip install openai python-dotenv

Step 2: Define Your Custom Functions

Create a Python script (agent.py) and add your own functions. For example:

import openai
from dotenv import load_dotenv
import os

# Load OpenAI API key from .env file
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")

# Define your custom tools/functions
def get_weather(location: str) -> str:
"""Fetch weather for a given location (mock example)."""
return f"Weather in {location}: Sunny, 25°C"

def send_email(recipient: str, message: str) -> str:
"""Send an email (mock example)."""
return f"Email sent to {recipient}: '{message}'"

# Map function names to actual functions
TOOLS = {
"get_weather": get_weather,
"send_email": send_email
}

Step 3: Create the Agent Logic

Add code to let ChatGPT decide which function to use:

--

--

Imran Khan
Imran Khan

No responses yet