Day 2: Variables, Data Types, and Operators - Building AI Agent Memory
Video:
What We'll Build Today
Create Python variables that store different types of AI-relevant data
Build a simple "AI agent memory system" using Python data types
Practice operators that help AI systems make decisions and process information
Why This Matters: The Foundation of AI Understanding
Think of variables as your AI agent's memory slots. Just like you remember your friend's name (text), your age (number), and whether you like coffee (true/false), AI agents need to store and work with different types of information. Every AI system you'll ever build - from chatbots to image recognition - starts with the fundamental ability to store, retrieve, and manipulate data.
When ChatGPT processes your question, it's working with variables containing your text, numerical confidence scores, and boolean flags for different processing steps. Today's lesson teaches you how to create and manipulate these same building blocks.
Core Concepts: The Data Types That Power AI
1. Strings - The Language of AI Communication
Strings hold text data, which is the primary way humans communicate with AI systems. Every prompt you type, every response an AI generates, every piece of training data from the internet - it all starts as strings.
user_prompt = "What's the weather like today?"
ai_response = "I'd be happy to help you check the weather!"
model_name = "gpt-4"
Think of strings as the universal translator between human thoughts and machine processing. In AI applications, you'll constantly be cleaning, analyzing, and transforming text data stored in string variables.
2. Numbers - The Mathematical Brain of AI
AI systems are fundamentally mathematical, so numbers are everywhere. Integers count things (how many words in a sentence?), while floats measure confidence levels and probabilities.
# Integers for counting and indexing
word_count = 1500
training_epochs = 100
batch_size = 32
# Floats for AI calculations
confidence_score = 0.87
learning_rate = 0.001
model_accuracy = 94.2
Every time an AI makes a prediction, it's working with floating-point numbers representing probabilities. When you see "GPT-4 is 87% confident in this answer," that 0.87 started as a float variable.
3. Booleans - The Decision Gates of AI
Boolean variables (True/False) control the flow of AI decision-making. They're like switches that turn features on or off, or gates that let information pass through.
is_training_mode = True
user_authenticated = False
model_ready = True
use_gpu_acceleration = True
In production AI systems, booleans control everything from whether to use cached results to determining if a user's input needs additional safety filtering.
4. Lists - The Data Collections That Train AI
Lists store multiple pieces of related data - perfect for datasets, user interactions, or model predictions. Think of them as organized filing cabinets for your AI's information.
conversation_history = ["Hello!", "How are you?", "I'm doing well, thanks!"]
prediction_scores = [0.92, 0.87, 0.45, 0.12]
supported_languages = ["English", "Spanish", "French", "German"]
Every AI training dataset is essentially a massive list of examples. Your chatbot's conversation history? A list of strings. Image recognition confidence scores? A list of floats.
Implementation: Building Your First AI Data Handler
GitHub Link:
https://github.com/sysdr/aiml/tree/main/day2/day2_variables_datatypes
Let's create a simple "AI Agent Memory System" that demonstrates how these data types work together in real AI applications:
# AI Agent Memory System
class SimpleAIAgent:
def __init__(self, name):
# String for agent identity
self.name = name
# Lists for storing conversation data
self.conversation_history = []
self.confidence_scores = []
# Boolean for agent state
self.is_active = True
# Numbers for performance tracking
self.total_interactions = 0
self.average_confidence = 0.0
def process_input(self, user_input):
# Simulate AI processing
self.conversation_history.append(user_input)
# Generate a mock confidence score
import random
confidence = round(random.uniform(0.7, 0.99), 2)
self.confidence_scores.append(confidence)
# Update counters using operators
self.total_interactions += 1
self.average_confidence = sum(self.confidence_scores) / len(self.confidence_scores)
# Boolean logic for response generation
if confidence > 0.8:
response_quality = "high"
else:
response_quality = "moderate"
return f"Processed with {confidence} confidence ({response_quality} quality)"
def get_status(self):
return {
"name": self.name,
"active": self.is_active,
"interactions": self.total_interactions,
"avg_confidence": round(self.average_confidence, 2),
"recent_conversations": self.conversation_history[-3:] # Last 3 items
}
# Create and test your AI agent
my_agent = SimpleAIAgent("ChatHelper")
print(my_agent.process_input("Hello, how are you?"))
print(my_agent.process_input("What's the weather like?"))
print(my_agent.get_status())
This example shows how variables and operators work together to create a functioning AI system. Notice how we use comparison operators (>
, <
) for decision-making, arithmetic operators (+
, /
) for calculations, and list operations for data management.
Real-World Connection: From Code to Production
This exact pattern appears in production AI systems everywhere. When you use ChatGPT, similar code manages your conversation history (lists of strings), tracks model confidence (floats), determines response strategies (booleans), and counts tokens for billing (integers).
Companies like OpenAI use these fundamental data types scaled up to handle millions of users. Your learning today directly translates to understanding how real AI systems store user sessions, manage model states, and process the constant stream of data that powers modern AI applications.
Working Code Demo:
Next Steps: Adding Intelligence Tomorrow
Tomorrow, we'll learn control flow - the if/else statements and loops that let your AI agent make smart decisions based on the data we learned to store today. You'll see how combining today's variables with decision-making logic creates the foundation for truly intelligent behavior.
Ready to give your AI agent a brain? See you tomorrow!