โGive a person a task, and theyโll complete it once. Teach an AI agent the task, and itโll execute it endlessly.โ
Introduction
AI agents can communicate and collaborate to perform tasks efficiently. In this article, we will explore how to build multiple AI agents using Fetch.ai uAgents and establish communication between them. You can use this framework to integrate it with existing AI-agents available in agentverse.ai marketplace
Getting Started
When I first started learning about AI agents, I had many questions in mind. The concept seemed intriguing, but I wanted to understand its real-world applications, efficiency, and why companies were rapidly adopting it. Through my research and hands-on experimentation, I realized the true potential of AI agents and their ability to revolutionize automation, decision-making, and collaboration. To help others gain the same clarity, I have compiled answers to some of the most common questions about AI agents. I hope this section will provide insights and help you understand their significance
What is an AI Agent?
An AI agent is a software entity that can perceive its environment, process data, and make autonomous decisions. Unlike traditional programs, AI agents operate independently or collaborate to automate tasks like customer support, data analysis, and logistics.
Who is Using AI Agents?
Tech giants like Google, Microsoft, and OpenAI use AI agents for automation. Finance companies rely on them for fraud detection and trading. Healthcare providers use them for diagnostics, and logistics companies like Amazon and FedEx optimize deliveries with AI-powered automation.
Why Are Companies Moving to AI Agents?
Traditional systems need manual intervention and centralized control, leading to inefficiencies. AI agents make real-time decisions, scale dynamically, and reduce reliance on single points of failure. Their ability to process and adapt to data makes them far more efficient.
How Do AI Agents Communicate?
AI agents exchange messages using structured protocols. In Fetch.aiโs uAgents framework, each agent has a unique address and communicates securely. They use an event-driven model, responding to messages and integrating with APIs, databases, and blockchain networks.
What Services Can AI Agents Provide?
AI agents handle information retrieval, task automation, data analysis, and fraud detection. They also enable decentralized marketplaces, allowing direct peer-to-peer transactions without intermediaries. Their flexibility improves efficiency across industries.
The Future of AI Agents
AI agents will drive automation, reduce costs, and enhance AI ecosystems. Their integration with blockchain will improve security and transparency in digital transactions, making them essential for the future of AI-driven applications.
Industries Benefiting from AI Agents
Finance uses AI agents for trading and fraud detection, while healthcare applies them to diagnostics and drug discovery. Retail and e-commerce use AI agents for recommendations and customer support, while logistics and smart cities benefit from AI-driven automation.
Why Fetch.ai for AI Agents?
Fetch.ai offers a decentralized infrastructure with secure, scalable AI agent interactions. The uAgents framework simplifies development, while blockchain integration ensures trust. The Agentverse Marketplace provides ready-to-use AI services, speeding up deployment.
Other AI Agent Platforms
Googleโs Dialogflow powers chatbots, OpenAIโs GPT agents handle automation, and IBM Watson Assistant supports enterprise AI. Microsoft Azure AI Agents and Rasa also provide virtual assistants for business applications.
AI Agents in Marketplaces
Marketplaces like Fetch.aiโs Agentverse.ai offer pre-built AI agents for integration. For example, the OpenAI Agent provides text generation and data analysis. Businesses can leverage these agents to enhance applications without complex AI development.
Letโs Learn How to Implement - Step by Step
We will create:
โข MasterAgent: Sends messages to Slave Agents.
โข SlaveAgent1 and SlaveAgent2: Receive messages from the MasterAgent.
The MasterAgent acts as the central coordinator, retrieving references to other agents, assigning tasks, consolidating results, and sending the final output back to the requesting client. It ensures smooth communication and workload distribution among agents.
Slave agents function as individual workers, executing tasks based on the MasterAgentโs instructions. In this example, we will create custom agents with specific logic. However, we can also leverage pre-built agents from marketplaces like the OpenAI Agent in Agentverse.ai and seamlessly integrate them into our applications.
Project Structure
first-ai-agent/
โโโ agents/
โ โโโ master-agent.py
โ โโโ slave-agent-1.py
โ โโโ slave-agent-2.py
โโโ venv/
โโโ __pycache__/
โโโ .gitignore
โโโ LICENSE
โโโ README.md
โโโ requirements.txt
โโโ setup.sh
Installing Dependencies
Ensure you have Python installed. Then, set up a virtual environment and install Fetch.ai uAgents.
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install uagents
Source Code
Slave Agent 1 (slave-agent-1.py
)
from uagents import Agent
slave1 = Agent(name="SlaveAgent1", port=8001)
@slave1.on_message()
def handle_message(ctx, sender, msg):
ctx.logger.info(f"[SlaveAgent1] Received message from {sender}: {msg}")
# Save agent address
with open("SlaveAgent1_address.txt", "w") as f:
f.write(slave1.address)
if __name__ == "__main__":
slave1.run()
Slave Agent 2 (slave-agent-2.py
)
from uagents import Agent
slave2 = Agent(name="SlaveAgent2", port=8002)
@slave2.on_message()
def handle_message(ctx, sender, msg):
ctx.logger.info(f"[SlaveAgent2] Received message from {sender}: {msg}")
# Save agent address
with open("SlaveAgent2_address.txt", "w") as f:
f.write(slave2.address)
if __name__ == "__main__":
slave2.run()
Master Agent (master-agent.py
)
from uagents import Agent
master = Agent(name="MasterAgent", port=8003)
# Read slave agent addresses
with open("SlaveAgent1_address.txt", "r") as f:
slave1_address = f.read().strip()
with open("SlaveAgent2_address.txt", "r") as f:
slave2_address = f.read().strip()
@master.on_event("start")
def send_messages(ctx):
ctx.logger.info(f"[MasterAgent] Sending message to SlaveAgent1 ({slave1_address})")
ctx.send(slave1_address, "Hello SlaveAgent1, this is MasterAgent!")
ctx.logger.info(f"[MasterAgent] Sending message to SlaveAgent2 ({slave2_address})")
ctx.send(slave2_address, "Hello SlaveAgent2, this is MasterAgent!")
if __name__ == "__main__":
master.run()
Running the Agents
Start SlaveAgent1
python slave-agent-1.py
Start SlaveAgent2
python slave-agent-2.py
Start MasterAgent
python master-agent.py
Logs & Execution
Slave Agent 1 Logs
[SlaveAgent1] ๐ Running on address: agent1qdfrrkh...
INFO: [SlaveAgent1]: Starting server on http://0.0.0.0:8001
INFO: [uagents.registration]: Registration on Almanac API successful
[SlaveAgent1] ๐ฉ Received message from MasterAgent: Hello SlaveAgent1, this is MasterAgent!
Slave Agent 2 Logs
[SlaveAgent2] ๐ Running on address: agent1qwwuh...
INFO: [SlaveAgent2]: Starting server on http://0.0.0.0:8002
INFO: [uagents.registration]: Registration on Almanac API successful
[SlaveAgent2] ๐ฉ Received message from MasterAgent: Hello SlaveAgent2, this is MasterAgent!
Master Agent Logs
[MasterAgent] ๐ Running on address: agent1qf8m6e...
INFO: [MasterAgent]: Sending message to SlaveAgent1 (agent1qdfrrkh...)
INFO: [MasterAgent]: Sending message to SlaveAgent2 (agent1qwwuh...)
INFO: [uagents.registration]: Registration on Almanac API successful
Agent Addresses Saved in Files
cat SlaveAgent1_address.txt
agent1qdfrrkh8xrrpqudrz53qhmwy2mxpal57nm5l0hfw7pkw57wx9vag6uqssqz
cat SlaveAgent2_address.txt
agent1qwwuh0d5qnzglyauh7d9cd2jpelhgqp37lmvjzwdj9wsmueap4p6ce73a6y
๐ Inspecting Agent Communication
To ensure that our agents are functioning correctly, we can use AgentVerse Local Agent Inspector to monitor message exchanges in real-time. Below is an overview of how our agents interact:
โ
SlaveAgent1: Received a message from MasterAgent
โ
SlaveAgent2: Received a message from MasterAgent
โ
MasterAgent: Successfully sent messages to SlaveAgent1 and SlaveAgent2
With the AgentVerse Local Agent Inspector, we can visually track these interactions and verify that messages are being transmitted as expected.
๐ AgentVerse Inspect Agent Communication
To ensure that our agents are functioning correctly, we can use AgentVerse Local Agent Inspector to monitor message exchanges in real-time. Below is an overview of how our agents interact:
โ
MasterAgent: Successfully sent messages to SlaveAgent1 and SlaveAgent2
โ
SlaveAgent1: Received a message from MasterAgent
โ
SlaveAgent2: Received a message from MasterAgent
With the AgentVerse Local Agent Inspector, we can visually track these interactions and verify that messages are being transmitted as expected.
๐ธ Screenshots:
fetch.ai AgentVerse Local Agent Inspector Dashboard
MasterAgent Message Payload log
SlaveAgent1 Message Payload log
SlaveAgent2 Message Payload log
๐ Inspecting Agents Locally
For local inspection, you can use the following endpoints:
http://127.0.0.1:8001/submit # SlaveAgent1
http://127.0.0.1:8002/submit # SlaveAgent2
http://127.0.0.1:8003/submit # MasterAgent
By visiting these URLs in your browser, you will see the agent running status, allowing you to verify that each agent is operational.
Conclusion
Using Fetch.ai's uAgents, we successfully created multiple agents that communicate with each other. These autonomous agents can be extended to perform complex tasks like data processing, transactions, or decision-making.
Next Steps
- Implement secure message encryption between agents.
- Extend the system for multi-agent marketplace collaboration.
- Integrate machine learning models for intelligent agent behavior.
๐ Vision: Building the Future, One Step at a Time
All our post are beginner-friendly and part of a bigger visionโnot just random topics. Each article is a small step toward a real-world, cutting-edge solution that integrates AI, ML, Blockchain, DevOps, and Full-Stack development. And yes, it will be open-source, Fork GitHub and use it as a micro-service in your own projects.
๐ Useful Resources
Category & Topic | Description | Read More |
---|---|---|
โก Boost Coding Speed with GitHub Copilot! | Discover how GitHub Copilot can help you write code 4x faster. | Explore Now |
๐ค Start Machine Learning in 10 Minutes! | Quickly set up Jupyter on AWS EC2 and start your ML journey. | Get Started |
๐ฉ๏ธ New to Cloud? Learn cloud computing in a fun and simple way! | Get started with cloud concepts in an engaging and easy-to-understand way. | Start Here |
๐ Stay Connected & Follow for More Updates!
- ๐ LinkedIn: Ramkumar M N
- ๐ป GitHub: @ramkumar-contactme
- โ๏ธ Dev.to: Ramkumar M N
- ๐ง Email
- ๐ HashNode: @ramkumarmn
Weโre looking for collaborators and expert insights to refine and expand these ideas. Letโs build something impactful together! ๐๐ก
If you found this article useful, give it a like! ๐
Would love to hear your thoughtsโdrop a comment ๐ฌ
Got ideas to enhance this project? Share them in the comments! ๐ก
Save this article in your reading-list to get further development updates ๐
I hope this is helpful, Letโs connect and build something amazing together! ๐๐ก
Top comments (2)
Awesome! ๐ฅ I'm currently exploring CrewAI.
check this: deeplearning.ai/short-courses/mult...
Hi Anmol,
Thank you for your comment. Also thanks for sharing the resources. I have registered for it, will checkout and utilise it.
Regards,
Ram