mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 17:18:29 +00:00
Add info-level logging for encryption start and complete indications
Co-authored-by: theCyberTech <84775494+theCyberTech@users.noreply.github.com>
This commit is contained in:
@@ -119,6 +119,8 @@ class AgentCommunicationEncryption:
|
||||
ValueError: If encryption fails
|
||||
"""
|
||||
try:
|
||||
logger.info(f"Starting encryption for {message_type} message to recipient {recipient_fingerprint.uuid_str[:8]}...")
|
||||
|
||||
# Convert message to JSON string if it's a dict
|
||||
if isinstance(message, dict):
|
||||
message_str = json.dumps(message)
|
||||
@@ -135,6 +137,7 @@ class AgentCommunicationEncryption:
|
||||
encrypted_bytes = fernet.encrypt(message_str.encode('utf-8'))
|
||||
encrypted_payload = encrypted_bytes.decode('utf-8')
|
||||
|
||||
logger.info(f"Successfully encrypted {message_type} message from {self.agent_fingerprint.uuid_str[:8]}... to {recipient_fingerprint.uuid_str[:8]}...")
|
||||
logger.debug(f"Encrypted message from {self.agent_fingerprint.uuid_str[:8]}... to {recipient_fingerprint.uuid_str[:8]}...")
|
||||
|
||||
return EncryptedMessage(
|
||||
@@ -162,6 +165,8 @@ class AgentCommunicationEncryption:
|
||||
ValueError: If decryption fails or message is not for this agent
|
||||
"""
|
||||
try:
|
||||
logger.info(f"Starting decryption of {encrypted_message.message_type} message from sender {encrypted_message.sender_fingerprint[:8]}...")
|
||||
|
||||
# Verify this message is intended for this agent
|
||||
if encrypted_message.recipient_fingerprint != self.agent_fingerprint.uuid_str:
|
||||
raise ValueError(f"Message not intended for this agent. Expected {self.agent_fingerprint.uuid_str[:8]}..., got {encrypted_message.recipient_fingerprint[:8]}...")
|
||||
@@ -178,9 +183,13 @@ class AgentCommunicationEncryption:
|
||||
|
||||
# Try to parse as JSON, fallback to string
|
||||
try:
|
||||
return json.loads(decrypted_str)
|
||||
decrypted_content = json.loads(decrypted_str)
|
||||
except json.JSONDecodeError:
|
||||
return decrypted_str
|
||||
decrypted_content = decrypted_str
|
||||
|
||||
logger.info(f"Successfully decrypted {encrypted_message.message_type} message from {encrypted_message.sender_fingerprint[:8]}... to {encrypted_message.recipient_fingerprint[:8]}...")
|
||||
|
||||
return decrypted_content
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to decrypt message: {e}")
|
||||
|
||||
@@ -83,12 +83,14 @@ class BaseAgentTool(BaseTool):
|
||||
encryption_handler = self._get_encryption_handler(sender_agent)
|
||||
if encryption_handler and hasattr(recipient_agent, 'security_config') and recipient_agent.security_config:
|
||||
try:
|
||||
logger.info(f"Starting encrypted communication from '{sender_agent.role}' to '{recipient_agent.role}'")
|
||||
# Encrypt the message for the recipient
|
||||
encrypted_msg = encryption_handler.encrypt_message(
|
||||
message_payload,
|
||||
recipient_agent.security_config.fingerprint,
|
||||
message_type="agent_communication"
|
||||
)
|
||||
logger.info(f"Encrypted communication established between '{sender_agent.role}' and '{recipient_agent.role}'")
|
||||
logger.debug(f"Encrypted communication from {sender_agent.role} to {recipient_agent.role}")
|
||||
return encrypted_msg
|
||||
except Exception as e:
|
||||
@@ -118,11 +120,13 @@ class BaseAgentTool(BaseTool):
|
||||
encryption_handler = self._get_encryption_handler(recipient_agent)
|
||||
if encryption_handler:
|
||||
try:
|
||||
logger.info(f"Starting decryption of received communication for '{recipient_agent.role}'")
|
||||
# Convert dict to EncryptedMessage if needed
|
||||
if isinstance(message, dict):
|
||||
message = EncryptedMessage(**message)
|
||||
|
||||
decrypted = encryption_handler.decrypt_message(message)
|
||||
logger.info(f"Successfully decrypted communication for '{recipient_agent.role}'")
|
||||
logger.debug(f"Decrypted communication for {recipient_agent.role}")
|
||||
return decrypted
|
||||
except Exception as e:
|
||||
@@ -253,6 +257,7 @@ class BaseAgentTool(BaseTool):
|
||||
|
||||
# Execute with processed communication context
|
||||
if isinstance(communication_payload, EncryptedMessage):
|
||||
logger.info(f"Executing encrypted communication task for agent '{self.sanitize_agent_name(target_agent.role)}'")
|
||||
logger.debug(f"Executing encrypted communication task for agent '{self.sanitize_agent_name(target_agent.role)}'")
|
||||
# For encrypted messages, pass the encrypted payload as additional context
|
||||
# The target agent will need to handle decryption during execution
|
||||
@@ -261,6 +266,7 @@ class BaseAgentTool(BaseTool):
|
||||
enhanced_context += f"\nADDITIONAL_CONTEXT: {context}"
|
||||
result = target_agent.execute_task(task_with_assigned_agent, enhanced_context)
|
||||
else:
|
||||
logger.info(f"Executing plain communication task for agent '{self.sanitize_agent_name(target_agent.role)}'")
|
||||
logger.debug(f"Executing plain communication task for agent '{self.sanitize_agent_name(target_agent.role)}'")
|
||||
result = target_agent.execute_task(task_with_assigned_agent, context)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user