agentconnect.core.message module¶
Message handling for the AgentConnect framework.
This module provides the Message class for creating, signing, and verifying messages exchanged between agents in the system.
- class Message(id, sender_id, receiver_id, content, message_type, timestamp, metadata=<factory>, protocol_version=ProtocolVersion.V1_0, signature=None)¶
Bases:
object
Message class for agent communication.
This class represents messages exchanged between agents, with support for content, metadata, and cryptographic signatures for verification.
- Parameters:
id (str)
sender_id (str)
receiver_id (str)
content (str)
message_type (MessageType)
timestamp (datetime)
metadata (Dict)
protocol_version (ProtocolVersion)
signature (str | None)
- id¶
Unique identifier for the message
- sender_id¶
ID of the sending agent
- receiver_id¶
ID of the receiving agent
- content¶
Message content
- message_type¶
Type of message (text, command, response, etc.)
- timestamp¶
When the message was created
- metadata¶
Additional information about the message
- protocol_version¶
Version of the communication protocol
- signature¶
Cryptographic signature for verification
-
message_type:
MessageType
¶
-
protocol_version:
ProtocolVersion
= '1.0'¶
- classmethod create(sender_id, receiver_id, content, sender_identity, message_type=MessageType.TEXT, metadata=None)¶
Create a new signed message.
- Parameters:
sender_id (
str
) – ID of the sending agentreceiver_id (
str
) – ID of the receiving agentcontent (
str
) – Message contentsender_identity (
AgentIdentity
) – Identity of the sending agentmessage_type (
MessageType
) – Type of message being sentmetadata (
Optional
[Dict
]) – Additional information about the message
- Return type:
- Returns:
A signed Message object
- Raises:
ValueError – If the sender identity doesn’t have a private key for signing
- sign(identity)¶
Sign message with sender’s private key.
- Parameters:
identity (
AgentIdentity
) – The identity containing the private key for signing- Raises:
ValueError – If the identity doesn’t have a private key
- Return type:
- verify(sender_identity)¶
Verify message signature using sender’s public key.
- Parameters:
sender_identity (
AgentIdentity
) – The identity containing the public key for verification- Return type:
- Returns:
True if the signature is valid, False otherwise
- Raises:
SecurityError – If the sender identity is not verified