DEV Community

Cover image for ๐Ÿค– Set Up Your Own AI Agent in Minutes! Clone, Run, & Deploy ๐Ÿš€๐Ÿ› ๏ธโšก
Ramkumar M N
Ramkumar M N

Posted on

๐Ÿค– Set Up Your Own AI Agent in Minutes! Clone, Run, & Deploy ๐Ÿš€๐Ÿ› ๏ธโšก

โ€œ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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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()
Enter fullscreen mode Exit fullscreen mode

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()
Enter fullscreen mode Exit fullscreen mode

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()
Enter fullscreen mode Exit fullscreen mode

Running the Agents

Start SlaveAgent1

python slave-agent-1.py
Enter fullscreen mode Exit fullscreen mode

Start SlaveAgent2

python slave-agent-2.py
Enter fullscreen mode Exit fullscreen mode

Start MasterAgent

python master-agent.py
Enter fullscreen mode Exit fullscreen mode

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!
Enter fullscreen mode Exit fullscreen mode

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!
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Agent Addresses Saved in Files

cat SlaveAgent1_address.txt
agent1qdfrrkh8xrrpqudrz53qhmwy2mxpal57nm5l0hfw7pkw57wx9vag6uqssqz

cat SlaveAgent2_address.txt
agent1qwwuh0d5qnzglyauh7d9cd2jpelhgqp37lmvjzwdj9wsmueap4p6ce73a6y
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” 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
Image description

MasterAgent Message Payload log
Image description

Image description

SlaveAgent1 Message Payload log
Image description

SlaveAgent2 Message Payload log
Image description

๐Ÿ” 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  
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
anmolbaranwal profile image
Anmol Baranwal

Awesome! ๐Ÿ”ฅ I'm currently exploring CrewAI.

check this: deeplearning.ai/short-courses/mult...

Collapse
 
ramkumar-m-n profile image
Ramkumar M N

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