Introduction
In this tutorial, you'll learn how to create and interact with a basic AI assistant similar to Salesforce's Agentforce Coworker. This tutorial will guide you through building a simple conversational AI system that can answer common workplace questions. We'll use Python and a free AI service to demonstrate how enterprise AI assistants work, giving you hands-on experience with the core concepts behind tools like Agentforce Coworker.
Prerequisites
- Basic computer knowledge and internet access
- Python installed on your computer (any version 3.6 or higher)
- Free API key from a service like OpenAI or Hugging Face (we'll use OpenAI in this example)
- Text editor or IDE (like VS Code or PyCharm)
Step-by-Step Instructions
Step 1: Set Up Your Python Environment
First, we need to create a project folder and install the required Python packages. Open your command line or terminal and run these commands:
mkdir ai-assistant-project
cd ai-assistant-project
pip install openai python-dotenv
Why: These commands create a new project directory and install the necessary libraries. The openai library lets us connect to AI services, and python-dotenv helps us securely store our API keys.
Step 2: Get Your API Key
Visit https://platform.openai.com/api-keys to get your free API key from OpenAI. Once you have it, create a new file called .env in your project folder and add your key:
OPENAI_API_KEY=your_actual_api_key_here
Why: API keys are like passwords that let us access AI services. We store it in a separate file so it's not accidentally shared or committed to code repositories.
Step 3: Create Your Main AI Assistant File
Create a file named ai_assistant.py in your project folder. This will be our main program:
import openai
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Set up the OpenAI API client
openai.api_key = os.getenv('OPENAI_API_KEY')
# Simple conversation function
def chat_with_ai(user_message):
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful workplace assistant. Answer questions clearly and professionally."},
{"role": "user", "content": user_message}
],
max_tokens=150,
temperature=0.7
)
return response.choices[0].message.content.strip()
except Exception as e:
return f"Sorry, I encountered an error: {str(e)}"
# Main loop for conversation
if __name__ == "__main__":
print("AI Assistant is ready! Type 'quit' to exit.")
while True:
user_input = input("\nYou: ")
if user_input.lower() in ['quit', 'exit', 'bye']:
print("AI Assistant: Goodbye!")
break
response = chat_with_ai(user_input)
print(f"AI Assistant: {response}")
Why: This code sets up the connection to the AI service and creates a conversation loop. The ChatCompletion.create function sends messages to the AI and gets responses back.
Step 4: Test Your AI Assistant
Run your program by typing:
python ai_assistant.py
Try asking questions like:
- "What should I do if I'm late to work?"
- "How do I request time off?"
- "What are the company's email policies?"
Why: Testing helps you understand how the AI responds to different questions. You'll see how the AI understands workplace-related queries and provides helpful answers.
Step 5: Customize Your Assistant
Let's make your assistant more specific to workplace needs. Modify the system message in your code:
{"role": "system", "content": "You are a helpful workplace assistant for a staffing company like Adecco. Answer questions about company policies, employee benefits, work procedures, and workplace etiquette. Keep responses professional and concise."}
Why: The system message tells the AI what role it should play. By customizing it, we make the AI more relevant to the specific workplace context.
Step 6: Add More Features
Enhance your assistant by adding a function to handle specific workplace tasks:
def get_workplace_info(query):
# This function could connect to a database or API
# For now, we'll simulate responses
responses = {
"time off": "To request time off, please fill out the time-off form in the employee portal.",
"benefits": "Our company offers health insurance, retirement plans, and paid time off.",
"policies": "Please check the employee handbook for detailed company policies."
}
for key, response in responses.items():
if key in query.lower():
return response
return "I can help with workplace policies and procedures. Please ask specific questions."
Why: Adding this function allows your assistant to provide more accurate and relevant information for specific workplace topics, similar to how enterprise AI assistants work.
Step 7: Run and Improve
Run your enhanced assistant and test it with specific workplace questions. Notice how the AI can now provide more targeted responses:
- "How do I request time off?"
- "What benefits do you offer?"
- "What are the company policies?"
Why: This demonstrates how AI assistants can be tailored to specific company needs, just like the Agentforce Coworker being rolled out by Adecco Group.
Summary
In this tutorial, you've created a basic AI assistant similar to Salesforce's Agentforce Coworker. You learned how to:
- Set up a Python environment with AI libraries
- Connect to an AI service using API keys
- Build a conversation loop for interaction
- Customize AI responses for specific workplace contexts
This simple assistant demonstrates the core concepts behind enterprise AI tools like Agentforce Coworker, which help employees work more efficiently by providing instant access to information and guidance. While this is a basic version, real enterprise AI assistants use more sophisticated technologies and databases to provide even more accurate and helpful responses.