0
0
Agentic AIml~5 mins

Agent communication protocols in Agentic AI

Choose your learning style9 modes available
Introduction
Agent communication protocols help different AI agents talk and work together smoothly, like friends sharing ideas to solve a problem.
When multiple AI agents need to share information to complete a task.
When coordinating robots to work together in a factory.
When chatbots need to pass messages to each other to answer complex questions.
When AI systems in a smart home communicate to manage devices efficiently.
When agents negotiate or make decisions together in a game or simulation.
Syntax
Agentic AI
protocol = {
    'message_type': ['inform', 'request', 'confirm', 'query'],
    'sender': 'agent_name',
    'receiver': 'agent_name',
    'content': 'information or command',
    'timestamp': 'time_sent'
}
Each message follows a clear structure to avoid confusion.
Common message types include 'inform' to share facts and 'request' to ask for actions.
Examples
AgentA tells AgentB that the door is open.
Agentic AI
message = {
    'message_type': 'inform',
    'sender': 'AgentA',
    'receiver': 'AgentB',
    'content': 'The door is open',
    'timestamp': '2024-06-01T10:00:00Z'
}
AgentB asks AgentA to close the door.
Agentic AI
message = {
    'message_type': 'request',
    'sender': 'AgentB',
    'receiver': 'AgentA',
    'content': 'Please close the door',
    'timestamp': '2024-06-01T10:01:00Z'
}
AgentA confirms to AgentB that the door is closed.
Agentic AI
message = {
    'message_type': 'confirm',
    'sender': 'AgentA',
    'receiver': 'AgentB',
    'content': 'Door is now closed',
    'timestamp': '2024-06-01T10:02:00Z'
}
Sample Model
This program shows two agents sending and receiving messages using a simple communication protocol. Each message has a type, sender, receiver, content, and timestamp.
Agentic AI
import time

class Agent:
    def __init__(self, name):
        self.name = name

    def send_message(self, receiver, message_type, content):
        message = {
            'message_type': message_type,
            'sender': self.name,
            'receiver': receiver.name,
            'content': content,
            'timestamp': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
        }
        print(f"{self.name} sends to {receiver.name}: {message}")
        receiver.receive_message(message)

    def receive_message(self, message):
        print(f"{self.name} received message: {message}")

# Create two agents
agent_a = Agent('AgentA')
agent_b = Agent('AgentB')

# AgentA informs AgentB
agent_a.send_message(agent_b, 'inform', 'The door is open')

# AgentB requests AgentA
agent_b.send_message(agent_a, 'request', 'Please close the door')

# AgentA confirms to AgentB
agent_a.send_message(agent_b, 'confirm', 'Door is now closed')
OutputSuccess
Important Notes
Timestamps help agents know when messages were sent.
Clear message types avoid misunderstandings between agents.
Protocols can be extended with more message types as needed.
Summary
Agent communication protocols let AI agents share messages clearly.
Messages have a type, sender, receiver, content, and time.
Using protocols helps agents work together like a team.