π Mastering Agentic AI: Running Multiple AI Agents in Parallel
Why You Need Agentic AI
Imagine having a fleet of AI assistants working in parallel β each handling a specific task without blocking each other.
One AI reviews your code, another fetches emails, a third monitors system performance, and yet another fetches real-time market trends β all happening simultaneously!
This is the power of Agentic AI. π
In this article, weβll build a system where multiple AI agents execute simple but useful tasks in parallel and continuously produce visible outputs.
Letβs dive in. π₯
π‘ What is Agentic AI?
Agentic AI refers to AI-driven agents that operate autonomously, perceiving the environment, reasoning about information, and executing tasks without human intervention.
For example, in software development:
- A code review agent can scan PRs and suggest improvements.
- A performance monitoring agent can analyze CPU load.
- A news-fetching agent can retrieve real-time stock market trends.
Now, letβs create a simple, visible, and parallel AI system. π§
π Building Multiple AI Agents That Run in Parallel
Weβll create multiple AI agents that execute simple tasks independently and concurrently using Pythonβs multiprocessing
.
Each agent will:
- Print outputs every 10 seconds (ensuring real-time visibility).
- Run without blocking other agents.
- Work as a parallel AI system.
π Understanding the AI Agents in the Agentic AI System
This Agentic AI system consists of five independent AI agents, each running simultaneously to perform a unique task. Below is a detailed breakdown of the five agents:
1οΈβ£ Number Generator AI β Random Number Simulation
π§ Description:
The Number Generator AI generates a random integer between 1 and 100 every 10 seconds. This mimics real-world random data generation, commonly used in simulations and testing.
def number_generator_agent():
"""Generates a random number every 10 seconds."""
while True:
number = random.randint(1, 100)
print(f"π² [Number Generator AI] Generated Number: {number}")
time.sleep(10)
π Use Cases:
β
Statistical Simulations β Helps in probability and statistics experiments.
β
Gaming Applications β Generates random events or lucky draws.
β
AI Model Training β Simulates random datasets for machine learning.
2οΈβ£ Logger AI β Real-Time System Monitoring
π§ Description:
The Logger AI continuously logs system messages, helping in real-time monitoring.
def logger_agent():
"""Logs a random message every 10 seconds."""
messages = ["Processing logs...", "Analyzing patterns...", "Checking system health..."]
while True:
print(f"π [Logger AI] {random.choice(messages)}")
time.sleep(10)
π Use Cases:
β
System Monitoring β Tracks system health and activity.
β
Debugging & Troubleshooting β Identifies software issues in real-time.
β
Security Logging β Monitors unauthorized access attempts.
3οΈβ£ Timer AI β Countdown Simulation
π§ Description:
The Timer AI functions as a countdown timer, starting at 10 seconds and decrementing each second until resetting to 10.
def timer_agent():
"""Prints a countdown message every 10 seconds."""
counter = 10
while True:
print(f"β³ [Timer AI] Countdown: {counter} seconds remaining...")
counter -= 1
if counter == 0:
counter = 10
time.sleep(10)
π Use Cases:
β
Task Scheduling β Simulates event-based countdowns.
β
Pomodoro Productivity Timer β Can be used for time management tools.
β
Event Triggers β Used for notifications, reminders, or sports tracking.
4οΈβ£ Weather AI β Simulated Weather Forecasting
π§ Description:
The Weather AI randomly selects a weather condition from a list every 10 seconds, simulating real-time weather updates.
def weather_agent():
"""Simulates random weather conditions every 10 seconds."""
conditions = ["Sunny βοΈ", "Rainy π§οΈ", "Cloudy βοΈ", "Windy π¬οΈ", "Stormy βοΈ"]
while True:
print(f"π [Weather AI] Current Weather: {random.choice(conditions)}")
time.sleep(10)
π Use Cases:
β
Weather Forecasting Simulations β Generates weather-based datasets for AI models.
β
Gaming & Virtual Worlds β Simulates changing weather conditions.
β
IoT Climate Control Systems β Helps in smart home automation.
5οΈβ£ Quote Generator AI β Daily Motivation
π§ Description:
The Quote Generator AI selects a motivational quote from a predefined list and prints it every 10 seconds.
def quote_agent():
"""Displays an inspirational quote every 10 seconds."""
quotes = [
"π Keep pushing forward!",
"π‘ Every problem has a solution.",
"π― Focus on what matters.",
"π₯ Stay motivated!"
]
while True:
print(f"π [Quote AI] Inspiration: {random.choice(quotes)}")
time.sleep(10)
π Use Cases:
β
Daily Productivity Bots β Provides inspiration for professionals & students.
β
Mental Health & Well-being β Helps with positivity and focus.
β
AI-Powered Learning Assistants β Enhances e-learning platforms.
π Running All AI Agents in Parallel
π Running All Agents in Parallel in PyCharm Notebook
import multiprocessing
if __name__ == "__main__":
agents = [
multiprocessing.Process(target=logger_agent),
multiprocessing.Process(target=number_generator_agent),
multiprocessing.Process(target=timer_agent),
multiprocessing.Process(target=weather_agent),
multiprocessing.Process(target=quote_agent),
]
# Start all AI agents
for agent in agents:
agent.start()
# Keep running the processes
for agent in agents:
agent.join()
π Running All Agents in Parallel in Jupyter Notebook
### **π Running All Agents in Parallel in Jupyter Notebook**
agents = [
threading.Thread(target=clock_agent, daemon=True),
threading.Thread(target=counter_agent, daemon=True),
threading.Thread(target=random_number_agent, daemon=True),
threading.Thread(target=greeting_agent, daemon=True),
threading.Thread(target=math_agent, daemon=True),
]
# Start all agents
for agent in agents:
agent.start()
# Keep Jupyter Notebook running to see output
while True:
time.sleep(1) # Prevents notebook from stopping
π§ What This Code Does:
β
Uses multiprocessing
to run agents simultaneously.
β
Starts five independent AI agents.
β
Ensures they run in parallel without blocking each other.
Full Code: Running AI Agents Simultaneously
import multiprocessing
import time
import random
### **1οΈβ£ Agent: AI-Powered Logger**
def logger_agent():
"""Logs a random message every 10 seconds."""
messages = ["Processing logs...", "Analyzing patterns...", "Checking system health..."]
while True:
print(f"π [Logger AI] {random.choice(messages)}")
time.sleep(10)
### **2οΈβ£ Agent: AI Number Generator**
def number_generator_agent():
"""Generates a random number every 10 seconds."""
while True:
number = random.randint(1, 100)
print(f"π² [Number Generator AI] Generated Number: {number}")
time.sleep(10)
### **3οΈβ£ Agent: AI Timer Countdown**
def timer_agent():
"""Prints a countdown message every 10 seconds."""
counter = 10
while True:
print(f"β³ [Timer AI] Countdown: {counter} seconds remaining...")
counter -= 1
if counter == 0:
counter = 10
time.sleep(10)
### **4οΈβ£ Agent: AI Weather Simulator**
def weather_agent():
"""Simulates random weather conditions every 10 seconds."""
conditions = ["Sunny βοΈ", "Rainy π§οΈ", "Cloudy βοΈ", "Windy π¬οΈ", "Stormy βοΈ"]
while True:
print(f"π [Weather AI] Current Weather: {random.choice(conditions)}")
time.sleep(10)
### **5οΈβ£ Agent: AI Quote Generator**
def quote_agent():
"""Displays an inspirational quote every 10 seconds."""
quotes = [
"π Keep pushing forward!",
"π‘ Every problem has a solution.",
"π― Focus on what matters.",
"π₯ Stay motivated!"
]
while True:
print(f"π [Quote AI] Inspiration: {random.choice(quotes)}")
time.sleep(10)
### **π Running All Agents in Parallel**
if __name__ == "__main__":
agents = [
multiprocessing.Process(target=logger_agent),
multiprocessing.Process(target=number_generator_agent),
multiprocessing.Process(target=timer_agent),
multiprocessing.Process(target=weather_agent),
multiprocessing.Process(target=quote_agent),
]
# Start all AI agents
for agent in agents:
agent.start()
# Keep running the processes
for agent in agents:
agent.join()
π§ How This Code Works
β
Each AI agent runs a separate process (ensuring parallel execution).
β
They continuously print results every 10 seconds, so you always see visible output.
β
Uses multiprocessing
so that tasks donβt block each other.
π Example Real-Time Output
π [Logger AI] Checking system health...
π² [Number Generator AI] Generated Number: 47
β³ [Timer AI] Countdown: 10 seconds remaining...
π [Weather AI] Current Weather: Sunny βοΈ
π [Quote AI] Inspiration: π Keep pushing forward!
(10 seconds laterβ¦)
π [Logger AI] Processing logs...
π² [Number Generator AI] Generated Number: 93
β³ [Timer AI] Countdown: 9 seconds remaining...
π [Weather AI] Current Weather: Rainy π§οΈ
π [Quote AI] Inspiration: π― Focus on what matters.
π₯ Pro Tips for Scaling Agentic AI
β
Use AI-powered APIs: Enhance your agents with OpenAI (for chat assistants), Google APIs (for calendar management), or Twitter API (for real-time news).
β
Store Data: Save results in a database or log file for analysis.
β
Add UI Dashboards: Visualize agent outputs using Dash, Flask, or Streamlit.
β
Deploy in the Cloud: Run agents continuously on AWS Lambda, Google Cloud Functions, or Docker.
π― Why You Should Try This Today
If youβre still manually juggling tasks β code review, logging, scheduling, monitoring, and fetching data β itβs time to automate your life with Agentic AI.
With just a few lines of code, you can have an AI-powered team working alongside you 24/7.
Drop a comment π¬if you have any suggestions on how we can further improve image generation using AI!
If you enjoyed this article, donβt forget to leave claps π (max 50) and π hit follow to stay updated.
Disclaimer: All views expressed here are my own and do not reflect the opinions of any affiliated organization.